fix(nostr): harden nip-07 adapter and fix hashtag sync issues

- Wrapped NIP-07 adapter extension calls in `retryNip07Call` to handle transient failures and timeouts robustly.
- Updated `HashtagPreferencesService` to autosave changes to relays immediately on modification.
- Added race condition protection in `HashtagPreferencesService.load` to prevent overwriting optimistic local updates with stale relay data.

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-01-26 20:40:28 +00:00
1 parent de463a86f4
commit 5c1d1d340b
2 files changed
+77 -15

No files matched your search

+17 -3
View File
@@ -341,6 +341,9 @@ class HashtagPreferencesService {
if (!hadInterest || removedFromDisinterests) {
this.emitChange("interest-added", { tag: normalized });
this.publish().catch((err) =>
userLogger.warn(`${LOG_PREFIX} Auto-save failed`, err),
);
return true;
}
@@ -355,6 +358,9 @@ class HashtagPreferencesService {
this.interests.delete(normalized);
this.emitChange("interest-removed", { tag: normalized });
this.publish().catch((err) =>
userLogger.warn(`${LOG_PREFIX} Auto-save failed`, err),
);
return true;
}
@@ -370,6 +376,9 @@ class HashtagPreferencesService {
if (!hadDisinterest || removedFromInterests) {
this.emitChange("disinterest-added", { tag: normalized });
this.publish().catch((err) =>
userLogger.warn(`${LOG_PREFIX} Auto-save failed`, err),
);
return true;
}
@@ -384,6 +393,9 @@ class HashtagPreferencesService {
this.disinterests.delete(normalized);
this.emitChange("disinterest-removed", { tag: normalized });
this.publish().catch((err) =>
userLogger.warn(`${LOG_PREFIX} Auto-save failed`, err),
);
return true;
}
@@ -567,9 +579,11 @@ class HashtagPreferencesService {
const currentCreatedAt = Number(this.eventCreatedAt) || 0;
const latestCreatedAt = Number(latest.created_at) || 0;
if (wasLoadedForUser && currentCreatedAt > latestCreatedAt) {
userLogger.warn(
`${LOG_PREFIX} Ignoring stale preferences event (remote: ${latestCreatedAt}, local: ${currentCreatedAt}).`,
// Protection against overwriting optimistic updates:
// If the local version is newer (because user just edited), ignore the remote fetch.
if (wasLoadedForUser && currentCreatedAt >= latestCreatedAt) {
devLogger.log(
`${LOG_PREFIX} Ignoring stale/concurrent preferences event (remote: ${latestCreatedAt}, local: ${currentCreatedAt}).`,
);
return;
}