From 3caf48c6db1472eec585da986687704bbe4ac488 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 18 Feb 2025 17:24:15 +1100 Subject: [PATCH] fix: do not show group expired banner without a good reason --- ts/session/apis/snode_api/swarmPolling.ts | 37 +++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index 4830d4260..3bc33be2f 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -703,19 +703,31 @@ export class SwarmPolling { ); return []; } - const noConfigBeforeFetch = namespacesAndLastHashes.some( - m => !m.lastHash && SnodeNamespace.isGroupConfigNamespace(m.namespace) - ); - const noConfigAfterFetch = namespacesAndLastHashesAfterFetch.some( - m => !m.lastHash && SnodeNamespace.isGroupConfigNamespace(m.namespace) - ); + const noConfigBeforeFetch = namespacesAndLastHashes + .filter(m => SnodeNamespace.isGroupConfigNamespace(m.namespace)) + .every(m => !m.lastHash); + + const noConfigAfterFetch = results + .filter(m => SnodeNamespace.isGroupConfigNamespace(m.namespace)) + .every(m => !m.messages.messages?.length); + const convo = ConvoHub.use().get(pubkey); + + if (PubKey.is03Pubkey(pubkey) && convo) { + if (noConfigBeforeFetch && noConfigAfterFetch) { + window.log.warn(`no configs before and after fetch of group: ${ed25519Str(pubkey)}`); + if (!convo.getIsExpired03Group()) { + convo.set({ isExpired03Group: true }); + await convo.commit(); + } + } else if (convo.getIsExpired03Group()) { + window.log.info( + `configs received for group marked as expired: ${ed25519Str(pubkey)}... Marking it unexpired` + ); - if (PubKey.is03Pubkey(pubkey) && noConfigBeforeFetch && noConfigAfterFetch) { - window.log.warn(`no configs before and after fetch of group: ${ed25519Str(pubkey)}`); - const convo = ConvoHub.use().get(pubkey); - if (convo && !convo.get('isExpired03Group')) { - convo.set({ isExpired03Group: true }); + // Group was marked as "expired", but apparently iot is not (we have hashes saved/just fetched). + // Maybe an admin came back online?, anyway mark the group as not expired. + convo.set({ isExpired03Group: false }); await convo.commit(); } } @@ -912,9 +924,8 @@ export class SwarmPolling { this.lastHashes[nodeEdKey][pubkey] = {}; } this.lastHashes[nodeEdKey][pubkey][namespace] = lastHash || ''; - return this.lastHashes[nodeEdKey][pubkey][namespace]; } - // return the cached value + // return the cached value/the one set on the line above return this.lastHashes[nodeEdKey][pubkey][namespace]; }