mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52:26 +00:00
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:
1 parent
de463a86f4
commit
5c1d1d340b
2 files changed
+77
-15
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user