feat(e2ee): undecryptable placeholder says why and offers the fix (#159)
CI / Build & Quality Checks (push) Canceled after 0s
CI / Trigger Desktop Build (push) Canceled after 0s
CI / Secret scan (gitleaks) (push) Canceled after 0s
CI / Docker image build & smoke test (push) Canceled after 0s
CI / Playwright smoke (e2e) (push) Canceled after 0s

'Unable to decrypt message' now carries one sentence per matrix-js-sdk
DecryptionFailureCode (describeDecryptionFailure, unit-tested against every
code so no raw code can leak into the copy) and, where something fixes it,
one button: no key backup → 'Set up key backup'; backup exists but this
session can't open it / key withheld for an unverified session → 'Unlock key
backup' / 'Verify this session' (both open Settings → Devices via a new
settingsRequestAtom that SettingsTab consumes); backup working or unknown
session (rust-crypto re-requests keys itself) → 'Retry', which re-runs
decryptEventIfNeeded. Sender-side problems are plain text. The raw code sits
in the placeholder's tooltip for support.

Verified headless on a fresh session in the encrypted seed room: each event
shows 'Sent before you signed in here, and no key backup exists…' with
tooltip HISTORICAL_MESSAGE_NO_KEY_BACKUP; the button opens Settings → Devices.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PPmy3tPq869XDW4njjVaKA
This commit is contained in:
2026-09-19 13:23:25 -04:00
co-authored by Claude Opus 5
parent 6f25035341
commit 0e2671891f
8 changed files with 214 additions and 10 deletions
@@ -1,7 +1,11 @@
import React, { CSSProperties, ReactNode, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Box, Button, config, Icon, Icons, Text, color, toRem } from 'folds';
import { IContent } from 'matrix-js-sdk';
import { IContent, MatrixEvent } from 'matrix-js-sdk';
import { useSetAtom } from 'jotai';
import { useMatrixClient } from '../../hooks/useMatrixClient';
import { settingsRequestAtom } from '../../state/settingsRequest';
import { describeDecryptionFailure } from '../../utils/decryptionReason';
import { JUMBO_EMOJI_REG, URL_REG } from '../../utils/regex';
import { trimReplyFromBody } from '../../utils/room';
import { MessageTextBody } from './layout';
@@ -120,11 +124,59 @@ function CollapsibleBody({ eventId, children }: CollapsibleBodyProps) {
);
}
export function MBadEncrypted() {
type MBadEncryptedProps = {
mEvent?: MatrixEvent;
};
/**
* [Gitea #159] The undecryptable placeholder says WHY and offers the one
* action that fixes it (set up key backup / verify this session / retry).
* The raw SDK code stays in the tooltip for support.
*/
export function MBadEncrypted({ mEvent }: MBadEncryptedProps) {
const mx = useMatrixClient();
const requestSettings = useSetAtom(settingsRequestAtom);
const [retrying, setRetrying] = useState(false);
const code = mEvent?.decryptionFailureReason ?? null;
const reason = describeDecryptionFailure(code);
const handleAction = async () => {
if (reason.action === 'setup-backup' || reason.action === 'verify-session') {
requestSettings('devices');
return;
}
if (reason.action === 'retry' && mEvent) {
setRetrying(true);
try {
await mx.decryptEventIfNeeded(mEvent, { forceRedecryptIfUntrusted: true });
} catch {
// still undecryptable — the placeholder re-renders with the current reason
} finally {
setRetrying(false);
}
}
};
return (
<Text>
<MessageBadEncryptedContent />
</Text>
<Box direction="Column" gap="100" alignItems="Start">
<Text>
<MessageBadEncryptedContent title={code ?? undefined} />
</Text>
<Text size="T200" priority="300">
{reason.text}
</Text>
{reason.action !== 'none' && (
<Button
size="300"
variant="Secondary"
fill="Soft"
radii="300"
onClick={handleAction}
disabled={retrying}
>
<Text size="B300">{retrying ? 'Retrying…' : reason.actionLabel}</Text>
</Button>
)}
</Box>
);
}