(feat): add cache package
All checks were successful
/ build-web (push) Successful in 7m26s
/ build-desktop (linux) (push) Successful in 11m29s
/ build-mobile (push) Successful in 19m15s
/ release (push) Successful in 3m3s

(feat): improve local storage security
(feat): move settings to dedicated settings package
This commit is contained in:
Alois 2026-07-11 22:08:01 +02:00
commit 790a1db788
54 changed files with 1984 additions and 947 deletions

30
packages/cache/src/helpers.ts vendored Normal file
View file

@ -0,0 +1,30 @@
import type { CachedMessage, ConversationWindow } from "./schemas";
export function trimMessages(
messages: readonly CachedMessage[],
limit: number,
): CachedMessage[] {
return [...messages]
.sort((a, b) => b.SendTime - a.SendTime)
.slice(0, limit)
.sort((a, b) => a.SendTime - b.SendTime);
}
export function replaceConversation(
windows: readonly ConversationWindow[],
replacement: ConversationWindow,
): ConversationWindow[] {
return [
replacement,
...windows.filter((item) => item.UserId !== replacement.UserId),
];
}
export function selectConversationWindows(
windows: readonly ConversationWindow[],
limit: number,
): ConversationWindow[] {
return [...windows]
.sort((a, b) => b.LastMessageAt - a.LastMessageAt || a.UserId - b.UserId)
.slice(0, limit);
}