fix: sync contacts
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
kieran 2024-04-29 11:39:26 +01:00
parent a17c98ad25
commit b199d1a366
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 5 additions and 5 deletions

View File

@ -18,7 +18,7 @@ export class DiffSyncTags extends EventEmitter<SafeSyncEvents> {
#changesEncrypted: Array<TagDiff> = [];
#decryptedContent?: string;
constructor(readonly link: NostrLink) {
constructor(readonly link: NostrLink, readonly contentEncrypted: boolean) {
super();
this.#sync = new SafeSync(link);
this.#sync.on("change", () => {
@ -99,7 +99,7 @@ export class DiffSyncTags extends EventEmitter<SafeSyncEvents> {
async sync(signer: EventSigner, system: SystemInterface) {
await this.#sync.sync(system);
if (this.#sync.value?.content) {
if (this.#sync.value?.content && this.contentEncrypted) {
const decrypted = await signer.nip4Decrypt(this.#sync.value.content, await signer.getPubKey());
this.#decryptedContent = decrypted;
}

View File

@ -78,8 +78,8 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
new NostrLink(NostrPrefix.Event, "", EventKind.SetMetadata, pubkey),
false,
);
this.#contacts = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.ContactList, pubkey));
this.#relays = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.Relays, pubkey));
this.#contacts = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.ContactList, pubkey), false);
this.#relays = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.Relays, pubkey), false);
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);
@ -415,7 +415,7 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
throw new Error("Not a standar list");
}
if (!this.#standardLists.has(kind)) {
const list = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", kind, this.pubkey));
const list = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", kind, this.pubkey), true);
list.on("change", () => this.emit("change", UserStateChangeType.GenericList));
this.#standardLists.set(kind, list);
}