Chat system refactor

This commit is contained in:
2023-06-20 14:15:33 +01:00
parent 4365fac9b5
commit 234c1c092d
22 changed files with 397 additions and 263 deletions

View File

@ -2,9 +2,9 @@ import { NostrEvent } from "@snort/system";
import { FeedCache } from "@snort/shared";
import { db } from "Db";
class DMCache extends FeedCache<NostrEvent> {
export class ChatCache extends FeedCache<NostrEvent> {
constructor() {
super("DMCache", db.dms);
super("ChatCache", db.chats);
}
key(of: NostrEvent): string {
@ -23,13 +23,7 @@ class DMCache extends FeedCache<NostrEvent> {
return ret;
}
allDms(): Array<NostrEvent> {
takeSnapshot(): Array<NostrEvent> {
return [...this.cache.values()];
}
takeSnapshot(): Array<NostrEvent> {
return this.allDms();
}
}
export const DmCache = new DMCache();

View File

@ -1,16 +1,16 @@
import { UserProfileCache, UserRelaysCache, RelayMetricCache } from "@snort/system";
import { DmCache } from "./DMCache";
import { InteractionCache } from "./EventInteractionCache";
import { ChatCache } from "./ChatCache";
export const UserCache = new UserProfileCache();
export const UserRelays = new UserRelaysCache();
export const RelayMetrics = new RelayMetricCache();
export { DmCache };
export const Chats = new ChatCache();
export async function preload(follows?: Array<string>) {
const preloads = [
UserCache.preload(follows),
DmCache.preload(),
Chats.preload(),
InteractionCache.preload(),
UserRelays.preload(follows),
RelayMetrics.preload(),