Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
508a123150 | ||
|
|
fe61352d88 | ||
|
|
0bec28b651 | ||
|
|
75089ecd3f | ||
|
|
70f1d640ed | ||
|
|
85a2abc46a | ||
|
|
5130dfc9c8 |
@@ -1,4 +1,4 @@
|
|||||||
import React, { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react';
|
import React, { CSSProperties, ReactNode, useEffect, useId, useRef, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { Box, Button, config, Icon, Icons, Text, color, toRem } from 'folds';
|
import { Box, Button, config, Icon, Icons, Text, color, toRem } from 'folds';
|
||||||
import { IContent, MatrixEvent } from 'matrix-js-sdk';
|
import { IContent, MatrixEvent } from 'matrix-js-sdk';
|
||||||
@@ -41,7 +41,10 @@ import { formatAccuracy } from '../../utils/geoShare';
|
|||||||
import { Attachment, AttachmentBox, AttachmentContent, AttachmentHeader } from './attachment';
|
import { Attachment, AttachmentBox, AttachmentContent, AttachmentHeader } from './attachment';
|
||||||
import { FileHeader, FileDownloadButton } from './FileHeader';
|
import { FileHeader, FileDownloadButton } from './FileHeader';
|
||||||
|
|
||||||
const COLLAPSE_MAX_HEIGHT = 320; // px ≈ 20 lines
|
// ≈ 20 lines; in rem so a larger font setting doesn't show fewer lines (Gitea #343).
|
||||||
|
const COLLAPSE_MAX_HEIGHT_REM = 20;
|
||||||
|
const collapseMaxHeightPx = (): number =>
|
||||||
|
COLLAPSE_MAX_HEIGHT_REM * (parseFloat(getComputedStyle(document.documentElement).fontSize) || 16);
|
||||||
|
|
||||||
type CollapsibleBodyProps = {
|
type CollapsibleBodyProps = {
|
||||||
eventId?: string;
|
eventId?: string;
|
||||||
@@ -79,7 +82,7 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
|
|||||||
const el = bodyRef.current;
|
const el = bodyRef.current;
|
||||||
if (!el) return undefined;
|
if (!el) return undefined;
|
||||||
const observer = new ResizeObserver(() => {
|
const observer = new ResizeObserver(() => {
|
||||||
setNeedsCollapse(el.scrollHeight > COLLAPSE_MAX_HEIGHT);
|
setNeedsCollapse(el.scrollHeight > collapseMaxHeightPx());
|
||||||
});
|
});
|
||||||
observer.observe(el);
|
observer.observe(el);
|
||||||
return () => observer.disconnect();
|
return () => observer.disconnect();
|
||||||
@@ -89,16 +92,36 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
|
|||||||
// (Gitea #85); useReducedMotion subscribes to the change event instead.
|
// (Gitea #85); useReducedMotion subscribes to the change event instead.
|
||||||
const prefersReducedMotion = useReducedMotion();
|
const prefersReducedMotion = useReducedMotion();
|
||||||
|
|
||||||
|
const bodyId = useId();
|
||||||
|
const isClipped = needsCollapse && collapsed;
|
||||||
|
// [Gitea #343] The clipped part stays in the DOM, so Tab can reach a link in
|
||||||
|
// it; the browser would then scroll the overflow:hidden box itself (top cut
|
||||||
|
// off, and it stayed that way). Expand instead when focus lands inside.
|
||||||
|
const handleFocus = () => {
|
||||||
|
if (isClipped) setCollapsed(false);
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
if (isClipped && bodyRef.current) bodyRef.current.scrollTop = 0;
|
||||||
|
}, [isClipped]);
|
||||||
|
|
||||||
|
// Fade the content itself rather than painting a fixed-colour gradient over
|
||||||
|
// it, so it blends on any background (bubbles, highlights, chat backgrounds).
|
||||||
|
const fadeMask = 'linear-gradient(#000 calc(100% - 3rem), transparent)';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div
|
||||||
ref={bodyRef}
|
ref={bodyRef}
|
||||||
|
id={bodyId}
|
||||||
|
onFocus={handleFocus}
|
||||||
style={{
|
style={{
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
...(needsCollapse && collapsed
|
...(isClipped
|
||||||
? {
|
? {
|
||||||
maxHeight: `${COLLAPSE_MAX_HEIGHT}px`,
|
maxHeight: `${COLLAPSE_MAX_HEIGHT_REM}rem`,
|
||||||
overflow: 'hidden',
|
overflow: 'hidden',
|
||||||
|
maskImage: fadeMask,
|
||||||
|
WebkitMaskImage: fadeMask,
|
||||||
transition: prefersReducedMotion ? undefined : 'max-height 0.2s ease',
|
transition: prefersReducedMotion ? undefined : 'max-height 0.2s ease',
|
||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
@@ -107,23 +130,12 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{needsCollapse && collapsed && (
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
position: 'absolute',
|
|
||||||
bottom: 0,
|
|
||||||
left: 0,
|
|
||||||
right: 0,
|
|
||||||
height: '3rem',
|
|
||||||
background: `linear-gradient(transparent, ${color.Surface.Container})`,
|
|
||||||
pointerEvents: 'none',
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
{needsCollapse && (
|
{needsCollapse && (
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
|
aria-expanded={!collapsed}
|
||||||
|
aria-controls={bodyId}
|
||||||
onClick={() => setCollapsed((c) => !c)}
|
onClick={() => setCollapsed((c) => !c)}
|
||||||
style={{
|
style={{
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
@@ -134,7 +146,8 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Text as="span" size="T200" style={{ color: color.Primary.Main }}>
|
<Text as="span" size="T200" style={{ color: color.Primary.Main }}>
|
||||||
{collapsed ? 'Read more ↓' : 'Show less ↑'}
|
{collapsed ? 'Read more' : 'Show less'}
|
||||||
|
<span aria-hidden="true">{collapsed ? ' ↓' : ' ↑'}</span>
|
||||||
</Text>
|
</Text>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -83,3 +83,14 @@ test('clearPlaintextCaches wipes drafts (#41) and the status message (#204) but
|
|||||||
assert.ok(!removed.includes('cinny_session'), 'session key not this module’s concern');
|
assert.ok(!removed.includes('cinny_session'), 'session key not this module’s concern');
|
||||||
assert.ok(store.has('cinny_session'));
|
assert.ok(store.has('cinny_session'));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('clearPlaintextCaches removes the call-volume list and the settings-sync stamp (#347)', () => {
|
||||||
|
store.clear();
|
||||||
|
store.set('lotus-per-user-volume', '{"@bob:server":0.3}');
|
||||||
|
store.set('settings-sync-meta:@me:server', '{"lastSyncedAt":1}');
|
||||||
|
store.set('settings', '{}');
|
||||||
|
clearPlaintextCaches('@me:server');
|
||||||
|
assert.equal(store.has('lotus-per-user-volume'), false);
|
||||||
|
assert.equal(store.has('settings-sync-meta:@me:server'), false);
|
||||||
|
assert.equal(store.has('settings'), true, 'device preferences are kept');
|
||||||
|
});
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ const clearMsgDrafts = (): void => {
|
|||||||
* - `cinny_recent_gifs_v1` / `cinny_recent_stickers_v1` — media the user sent
|
* - `cinny_recent_gifs_v1` / `cinny_recent_stickers_v1` — media the user sent
|
||||||
* - `navToActivePath<userId>` — per-space last-visited room paths (needs userId)
|
* - `navToActivePath<userId>` — per-space last-visited room paths (needs userId)
|
||||||
* - `lotus_outbox_v1` — decrypted content of messages not yet sent ([Gitea #112])
|
* - `lotus_outbox_v1` — decrypted content of messages not yet sent ([Gitea #112])
|
||||||
|
* - `lotus-per-user-volume`, `settings-sync-meta:<userId>` — whom you adjusted in
|
||||||
|
* calls, and a key naming the account ([Gitea #347])
|
||||||
* - `draft-msg-*` — unsent composer drafts (decrypted message text, unscoped by
|
* - `draft-msg-*` — unsent composer drafts (decrypted message text, unscoped by
|
||||||
* user — see [Gitea #41]; previously deliberately preserved across logout
|
* user — see [Gitea #41]; previously deliberately preserved across logout
|
||||||
* (N98), which let the next account on this device see/send a prior user's
|
* (N98), which let the next account on this device see/send a prior user's
|
||||||
@@ -92,6 +94,24 @@ const clearStatusMessage = (): void => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* [Gitea #347] Per-person residue that isn't message text but still says whom
|
||||||
|
* the previous user dealt with: Element Call's per-user volume memory (same
|
||||||
|
* origin on the web — element-call `lotusVolumeMemory.ts`) and the settings-sync
|
||||||
|
* stamp, whose key names the account.
|
||||||
|
*/
|
||||||
|
export const CALL_VOLUME_KEY = 'lotus-per-user-volume';
|
||||||
|
const clearCallVolumesAndSyncMeta = (userId?: string): void => {
|
||||||
|
const keys = [CALL_VOLUME_KEY, ...(userId ? [`settings-sync-meta:${userId}`] : [])];
|
||||||
|
keys.forEach((key) => {
|
||||||
|
try {
|
||||||
|
localStorage.removeItem(key);
|
||||||
|
} catch {
|
||||||
|
// best-effort
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export const clearPlaintextCaches = (userId?: string): void => {
|
export const clearPlaintextCaches = (userId?: string): void => {
|
||||||
clearTranslationCache();
|
clearTranslationCache();
|
||||||
clearScheduledMessages();
|
clearScheduledMessages();
|
||||||
@@ -103,5 +123,6 @@ export const clearPlaintextCaches = (userId?: string): void => {
|
|||||||
clearOutbox();
|
clearOutbox();
|
||||||
clearCallSession();
|
clearCallSession();
|
||||||
clearStatusMessage();
|
clearStatusMessage();
|
||||||
|
clearCallVolumesAndSyncMeta(userId);
|
||||||
if (userId) clearNavToActivePathStore(userId);
|
if (userId) clearNavToActivePathStore(userId);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,3 +104,9 @@ describe('buildSyncedContent', () => {
|
|||||||
assert.deepEqual(c.settings, pickSyncable(base));
|
assert.deepEqual(c.settings, pickSyncable(base));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('device-local keys', () => {
|
||||||
|
it('keeps enterForNewline on each device (#348)', () => {
|
||||||
|
assert.equal(DEVICE_LOCAL_KEYS.has('enterForNewline'), true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ export const DEVICE_LOCAL_KEYS: ReadonlySet<keyof Settings> = new Set<keyof Sett
|
|||||||
'ringtoneVolume',
|
'ringtoneVolume',
|
||||||
'soundboardVolume',
|
'soundboardVolume',
|
||||||
'cameraOnJoin',
|
'cameraOnJoin',
|
||||||
|
// [Gitea #348] Enter = new line suits a phone keyboard, Enter = send a desktop one;
|
||||||
|
// syncing it switched the desktop to Ctrl+Enter when set on the phone.
|
||||||
|
'enterForNewline',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
/** The subset of `settings` that is synced (deep-copied so callers can't alias). */
|
/** The subset of `settings` that is synced (deep-copied so callers can't alias). */
|
||||||
|
|||||||
Reference in New Issue
Block a user