Add keyword search, draft

This commit is contained in:
artur
2023-01-24 15:33:18 +03:00
committed by Kieran
parent 200dc6b352
commit 3f45a3db06
12 changed files with 38740 additions and 7004 deletions

View File

@ -1,7 +1,7 @@
import { HexKey, TaggedRawEvent } from "Nostr";
import { ProfileCacheExpire } from "Const";
import { mapEventToProfile, MetadataCache, } from "State/Users";
import { getDb } from "State/Users/Db";
import { ProfileCacheExpire, SearchRelays } from "Const";
import { mapEventToProfile, MetadataCache } from "Db/User";
import Connection, { RelaySettings } from "Nostr/Connection";
import Event from "Nostr/Event";
import EventKind from "Nostr/EventKind";
@ -48,7 +48,8 @@ export class NostrSystem {
let c = new Connection(address, options);
this.Sockets.set(address, c);
for (let [_, s] of this.Subscriptions) {
c.AddSubscription(s);
if (!s.Keywords || SearchRelays.has(address))
c.AddSubscription(s);
}
} else {
// update settings if already connected
@ -71,15 +72,17 @@ export class NostrSystem {
}
AddSubscription(sub: Subscriptions) {
for (let [_, s] of this.Sockets) {
s.AddSubscription(sub);
for (let [a, s] of this.Sockets) {
if (!sub.Keywords || SearchRelays.has(a))
s.AddSubscription(sub);
}
this.Subscriptions.set(sub.Id, sub);
}
RemoveSubscription(subId: string) {
for (let [_, s] of this.Sockets) {
s.RemoveSubscription(subId);
for (let [a, s] of this.Sockets) {
if (!this.Subscriptions.get(subId)?.Keywords || SearchRelays.has(a))
s.RemoveSubscription(subId);
}
this.Subscriptions.delete(subId);
}
@ -192,9 +195,9 @@ export class NostrSystem {
let profile = mapEventToProfile(e);
if (profile) {
let existing = await db.find(profile.pubkey);
if((existing?.created ?? 0) < profile.created) {
if ((existing?.created ?? 0) < profile.created) {
await db.put(profile);
} else if(existing) {
} else if (existing) {
await db.update(profile.pubkey, { loaded: new Date().getTime() });
}
}