diff --git a/ts/session/apis/snode_api/swarmPolling.ts b/ts/session/apis/snode_api/swarmPolling.ts index a00cf5b24..47b7b2958 100644 --- a/ts/session/apis/snode_api/swarmPolling.ts +++ b/ts/session/apis/snode_api/swarmPolling.ts @@ -676,69 +676,58 @@ export class SwarmPolling { } public async pollOnceForOurDisplayName(abortSignal?: AbortSignal): Promise { - try { - if (abortSignal?.aborted) { - throw new NotFoundError('[pollOnceForOurDisplayName] aborted right away'); - } - - const pubkey = UserUtils.getOurPubKeyFromCache(); - const toPollFrom = await this.getNodesToPollFrom(pubkey.key); + if (abortSignal?.aborted) { + throw new NotFoundError('[pollOnceForOurDisplayName] aborted right away'); + } - if (abortSignal?.aborted) { - throw new NotFoundError( - '[pollOnceForOurDisplayName] aborted after selecting nodes to poll from' - ); - } + const pubkey = UserUtils.getOurPubKeyFromCache(); + const toPollFrom = await this.getNodesToPollFrom(pubkey.key); - const resultsFromUserProfile = await SnodeAPIRetrieve.retrieveNextMessages( - toPollFrom, - [''], - pubkey.key, - [SnodeNamespaces.UserProfile], - pubkey.key, - null + if (abortSignal?.aborted) { + throw new NotFoundError( + '[pollOnceForOurDisplayName] aborted after selecting nodes to poll from' ); + } - // check if we just fetched the details from the config namespaces. - // If yes, merge them together and exclude them from the rest of the messages. - if (!resultsFromUserProfile?.length) { - throw new NotFoundError('[pollOnceForOurDisplayName] resultsFromUserProfile is empty'); - } + const resultsFromUserProfile = await SnodeAPIRetrieve.retrieveNextMessages( + toPollFrom, + [''], + pubkey.key, + [SnodeNamespaces.UserProfile], + pubkey.key, + null + ); - if (abortSignal?.aborted) { - throw new NotFoundError( - '[pollOnceForOurDisplayName] aborted after retrieving user profile config messages' - ); - } + // check if we just fetched the details from the config namespaces. + // If yes, merge them together and exclude them from the rest of the messages. + if (!resultsFromUserProfile?.length) { + throw new NotFoundError('[pollOnceForOurDisplayName] resultsFromUserProfile is empty'); + } - const userConfigMessages = resultsFromUserProfile - .filter(m => SnodeNamespace.isUserConfigNamespace(m.namespace)) - .map(r => r.messages.messages); + if (abortSignal?.aborted) { + throw new NotFoundError( + '[pollOnceForOurDisplayName] aborted after retrieving user profile config messages' + ); + } - const userConfigMessagesMerged = flatten(compact(userConfigMessages)); - if (!userConfigMessagesMerged.length) { - throw new NotFoundError( - '[pollOnceForOurDisplayName] after merging there are no user config messages' - ); - } - const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true); + const userConfigMessages = resultsFromUserProfile + .filter(m => SnodeNamespace.isUserConfigNamespace(m.namespace)) + .map(r => r.messages.messages); - if (isEmpty(displayName)) { - throw new NotFoundError( - '[pollOnceForOurDisplayName] Got a config message from network but without a displayName...' - ); - } + const userConfigMessagesMerged = flatten(compact(userConfigMessages)); + if (!userConfigMessagesMerged.length) { + throw new NotFoundError( + '[pollOnceForOurDisplayName] after merging there are no user config messages' + ); + } + const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true); - return displayName; - } catch (e) { - if (e.message === ERROR_CODE_NO_CONNECT) { - if (window.inboxStore?.getState().onionPaths.isOnline) { - window.inboxStore?.dispatch(updateIsOnline(false)); - } - } else if (!window.inboxStore?.getState().onionPaths.isOnline) { - window.inboxStore?.dispatch(updateIsOnline(true)); - } - throw e; + if (isEmpty(displayName)) { + throw new NotFoundError( + '[pollOnceForOurDisplayName] Got a config message from network but without a displayName...' + ); } + + return displayName; } }