Files
snort/packages/app/src/Cache/ChatCache.ts
2023-06-20 14:15:33 +01:00

30 lines
646 B
TypeScript

import { NostrEvent } from "@snort/system";
import { FeedCache } from "@snort/shared";
import { db } from "Db";
export class ChatCache extends FeedCache<NostrEvent> {
constructor() {
super("ChatCache", db.chats);
}
key(of: NostrEvent): string {
return of.id;
}
override async preload(): Promise<void> {
await super.preload();
// load all dms to memory
await this.buffer([...this.onTable]);
}
newest(): number {
let ret = 0;
this.cache.forEach(v => (ret = v.created_at > ret ? v.created_at : ret));
return ret;
}
takeSnapshot(): Array<NostrEvent> {
return [...this.cache.values()];
}
}