mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 04:42:57 +00:00
Merge pull request #1229 from PR0M3TH3AN/fix-hashtag-preferences-reset-7347622943668285159
fix: prevent hashtag preferences reset on empty or stale relay responses
This commit is contained in:
1 file changed
+13
-3
@@ -430,9 +430,9 @@ class HashtagPreferencesService {
|
||||
if (!events.length) {
|
||||
// If we failed to fetch (network error) but already have data for this user,
|
||||
// preserve the existing state instead of wiping it.
|
||||
if (fetchError && wasLoadedForUser) {
|
||||
if (wasLoadedForUser) {
|
||||
userLogger.warn(
|
||||
`${LOG_PREFIX} Keeping existing preferences after fetch error.`,
|
||||
`${LOG_PREFIX} Keeping existing preferences despite empty relay response.`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -470,7 +470,7 @@ class HashtagPreferencesService {
|
||||
}, null);
|
||||
|
||||
if (!latest) {
|
||||
if (fetchError && wasLoadedForUser) {
|
||||
if (wasLoadedForUser) {
|
||||
return;
|
||||
}
|
||||
this.reset();
|
||||
@@ -478,6 +478,16 @@ class HashtagPreferencesService {
|
||||
return;
|
||||
}
|
||||
|
||||
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}).`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const decryptResult = await this.decryptEvent(latest, normalized);
|
||||
if (!decryptResult.ok) {
|
||||
userLogger.warn(
|
||||
|
||||
Reference in new issue
Block a user