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
76 lines
3.2 KiB
TypeScript
76 lines
3.2 KiB
TypeScript
import { DecryptionFailureCode } from 'matrix-js-sdk/lib/crypto-api';
|
|
|
|
/**
|
|
* [Gitea #159] What to tell the user about an undecryptable message, and the
|
|
* one thing that fixes it (if anything does). Raw codes never reach the UI
|
|
* text — they go in the tooltip for support.
|
|
*/
|
|
export type DecryptionAction = 'setup-backup' | 'retry' | 'verify-session' | 'none';
|
|
|
|
export type DecryptionReason = {
|
|
text: string;
|
|
action: DecryptionAction;
|
|
actionLabel?: string;
|
|
};
|
|
|
|
export const describeDecryptionFailure = (
|
|
code: DecryptionFailureCode | string | null | undefined,
|
|
): DecryptionReason => {
|
|
switch (code) {
|
|
case DecryptionFailureCode.HISTORICAL_MESSAGE_NO_KEY_BACKUP:
|
|
// No backup exists on the server at all: this key is gone for this
|
|
// session (another signed-in device may still share it), and the fix is
|
|
// for the future.
|
|
return {
|
|
text: 'Sent before you signed in here, and no key backup exists — set one up so your next session can read history.',
|
|
action: 'setup-backup',
|
|
actionLabel: 'Set up key backup',
|
|
};
|
|
case DecryptionFailureCode.HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED:
|
|
// A backup exists but this session can't open it (needs the recovery key
|
|
// / verification).
|
|
return {
|
|
text: "Sent before you signed in here. Your key backup exists but this session can't open it yet.",
|
|
action: 'verify-session',
|
|
actionLabel: 'Unlock key backup',
|
|
};
|
|
case DecryptionFailureCode.HISTORICAL_MESSAGE_WORKING_BACKUP:
|
|
return {
|
|
text: 'Waiting for the key from your backup…',
|
|
action: 'retry',
|
|
actionLabel: 'Retry',
|
|
};
|
|
case DecryptionFailureCode.HISTORICAL_MESSAGE_USER_NOT_JOINED:
|
|
return { text: 'Sent before you joined this room.', action: 'none' };
|
|
case DecryptionFailureCode.MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE:
|
|
return {
|
|
text: "The sender's device won't share keys with unverified sessions.",
|
|
action: 'verify-session',
|
|
actionLabel: 'Verify this session',
|
|
};
|
|
case DecryptionFailureCode.MEGOLM_KEY_WITHHELD:
|
|
return { text: 'The sender chose not to share the key for this message.', action: 'none' };
|
|
case DecryptionFailureCode.MEGOLM_UNKNOWN_INBOUND_SESSION_ID:
|
|
case DecryptionFailureCode.OLM_UNKNOWN_MESSAGE_INDEX:
|
|
// rust-crypto re-requests the key from our other devices by itself
|
|
// (there is no public re-request API any more); a retry re-runs the
|
|
// decryption in case it has arrived since.
|
|
return {
|
|
text: "This session doesn't have the key yet — it is being requested from your other devices.",
|
|
action: 'retry',
|
|
actionLabel: 'Retry',
|
|
};
|
|
case DecryptionFailureCode.SENDER_IDENTITY_PREVIOUSLY_VERIFIED:
|
|
return {
|
|
text: "The sender's identity changed since you verified them — re-verify to read this.",
|
|
action: 'none',
|
|
};
|
|
case DecryptionFailureCode.UNSIGNED_SENDER_DEVICE:
|
|
return { text: "Sent from a device the sender hasn't verified.", action: 'none' };
|
|
case DecryptionFailureCode.UNKNOWN_SENDER_DEVICE:
|
|
return { text: "Sent from a device we don't know about.", action: 'none' };
|
|
default:
|
|
return { text: 'Unable to decrypt this message.', action: 'none' };
|
|
}
|
|
};
|