fix: sync contacts
This commit is contained in:
@ -18,7 +18,7 @@ export class DiffSyncTags extends EventEmitter<SafeSyncEvents> {
|
|||||||
#changesEncrypted: Array<TagDiff> = [];
|
#changesEncrypted: Array<TagDiff> = [];
|
||||||
#decryptedContent?: string;
|
#decryptedContent?: string;
|
||||||
|
|
||||||
constructor(readonly link: NostrLink) {
|
constructor(readonly link: NostrLink, readonly contentEncrypted: boolean) {
|
||||||
super();
|
super();
|
||||||
this.#sync = new SafeSync(link);
|
this.#sync = new SafeSync(link);
|
||||||
this.#sync.on("change", () => {
|
this.#sync.on("change", () => {
|
||||||
@ -99,7 +99,7 @@ export class DiffSyncTags extends EventEmitter<SafeSyncEvents> {
|
|||||||
async sync(signer: EventSigner, system: SystemInterface) {
|
async sync(signer: EventSigner, system: SystemInterface) {
|
||||||
await this.#sync.sync(system);
|
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());
|
const decrypted = await signer.nip4Decrypt(this.#sync.value.content, await signer.getPubKey());
|
||||||
this.#decryptedContent = decrypted;
|
this.#decryptedContent = decrypted;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,8 @@ export class UserState<TAppData> extends EventEmitter<UserStateEvents> {
|
|||||||
new NostrLink(NostrPrefix.Event, "", EventKind.SetMetadata, pubkey),
|
new NostrLink(NostrPrefix.Event, "", EventKind.SetMetadata, pubkey),
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
this.#contacts = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.ContactList, pubkey));
|
this.#contacts = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.ContactList, pubkey), false);
|
||||||
this.#relays = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.Relays, pubkey));
|
this.#relays = new DiffSyncTags(new NostrLink(NostrPrefix.Event, "", EventKind.Relays, pubkey), false);
|
||||||
if (options?.appdataId && options.initAppdata) {
|
if (options?.appdataId && options.initAppdata) {
|
||||||
const link = new NostrLink(NostrPrefix.Address, options.appdataId, EventKind.AppData, pubkey);
|
const link = new NostrLink(NostrPrefix.Address, options.appdataId, EventKind.AppData, pubkey);
|
||||||
this.#appdata = new JsonEventSync<TAppData>(options.initAppdata, link, options.encryptAppdata ?? false);
|
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");
|
throw new Error("Not a standar list");
|
||||||
}
|
}
|
||||||
if (!this.#standardLists.has(kind)) {
|
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));
|
list.on("change", () => this.emit("change", UserStateChangeType.GenericList));
|
||||||
this.#standardLists.set(kind, list);
|
this.#standardLists.set(kind, list);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user