Files
cinny/src/app/state/searchCacheEnabled.ts
T
jaredandClaude Opus 4.8 7da960ac8c feat(search): opt-in persistent index for encrypted-room search (P4-8)
Raw-IndexedDB cache (lotus-search-cache: messages keyed [roomId,eventId] +
per-room coverage) merged into local search with in-memory-wins dedupe. OPT-IN
(default off) via a standalone atom — stores decrypted text at rest, so it ships
with a privacy note, a Clear button, and an unconditional wipe on logout
(initMatrix). All IDB errors degrade to cache-miss. +8 tests (1 IDB skip in node).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-01 21:19:02 -04:00

25 lines
1002 B
TypeScript

import {
atomWithLocalStorage,
getLocalStorageItem,
setLocalStorageItem,
} from './utils/atomWithLocalStorage';
const SEARCH_CACHE_ENABLED = 'searchCacheEnabled';
/**
* P4-8 — persistent encrypted-search cache opt-in flag (default `false`).
*
* Standalone, `localStorage`-backed boolean atom kept separate from
* `state/settings.ts` on purpose. When `true`, encrypted-room search persists a
* decrypted plaintext index to IndexedDB (`lotus-search-cache`) so coverage
* survives reloads. Because this writes decrypted plaintext at rest it must be
* explicitly opted into; the cache is clearable from the search UI and wiped on
* logout. Toggling this atom off stops all reads/writes but does NOT wipe
* existing data — that is the explicit "Clear cached index" button / logout.
*/
export const searchCacheEnabledAtom = atomWithLocalStorage<boolean>(
SEARCH_CACHE_ENABLED,
(key) => getLocalStorageItem<boolean>(key, false),
(key, value) => setLocalStorageItem(key, value),
);