feat: client tags

This commit is contained in:
2025-04-30 11:14:02 +01:00
parent f028de7c04
commit e6ca368134
10 changed files with 61 additions and 33 deletions

View File

@ -150,7 +150,11 @@ export class NostrLink implements ToNostrEventTag {
const ifSetCheck = <T>(a: T | undefined, b: T) => {
return !Boolean(a) || a === b;
};
return (EventExt.isReplaceable(ev.kind) || ifSetCheck(this.id, ev.id)) && ifSetCheck(this.author, ev.pubkey) && ifSetCheck(this.kind, ev.kind);
return (
(EventExt.isReplaceable(ev.kind) || ifSetCheck(this.id, ev.id)) &&
ifSetCheck(this.author, ev.pubkey) &&
ifSetCheck(this.kind, ev.kind)
);
}
return false;

View File

@ -74,13 +74,19 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
this.#stateObj = stateObj;
this.#standardLists = pubkey ? new Map() : undefined;
this.#profile = pubkey ? new JsonEventSync<UserMetadata | undefined>(
undefined,
new NostrLink(NostrPrefix.Event, pubkey, EventKind.SetMetadata, pubkey),
false,
) : undefined;
this.#contacts = pubkey ? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.ContactList, pubkey), false) : undefined;
this.#relays = pubkey ? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.Relays, pubkey), false) : undefined;
this.#profile = pubkey
? new JsonEventSync<UserMetadata | undefined>(
undefined,
new NostrLink(NostrPrefix.Event, pubkey, EventKind.SetMetadata, pubkey),
false,
)
: undefined;
this.#contacts = pubkey
? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.ContactList, pubkey), false)
: undefined;
this.#relays = pubkey
? new DiffSyncTags(new NostrLink(NostrPrefix.Event, pubkey, EventKind.Relays, pubkey), false)
: undefined;
if (options?.appdataId && options.initAppdata) {
const link = new NostrLink(NostrPrefix.Address, options.appdataId, EventKind.AppData, pubkey);
this.#appdata = new JsonEventSync<TAppData>(options.initAppdata, link, options.encryptAppdata ?? false);