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>
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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),
|
||||
);
|
||||
Reference in New Issue
Block a user