fix: remove unneeded catch block for checking if we are online

the inboxStore isnt set yet and we arent displaying the connected path light
pull/3056/head
William Grant 2 years ago
parent 5a131c5785
commit 7f031681f8

@ -676,69 +676,58 @@ export class SwarmPolling {
} }
public async pollOnceForOurDisplayName(abortSignal?: AbortSignal): Promise<string> { public async pollOnceForOurDisplayName(abortSignal?: AbortSignal): Promise<string> {
try { if (abortSignal?.aborted) {
if (abortSignal?.aborted) { throw new NotFoundError('[pollOnceForOurDisplayName] aborted right away');
throw new NotFoundError('[pollOnceForOurDisplayName] aborted right away'); }
}
const pubkey = UserUtils.getOurPubKeyFromCache();
const toPollFrom = await this.getNodesToPollFrom(pubkey.key);
if (abortSignal?.aborted) { const pubkey = UserUtils.getOurPubKeyFromCache();
throw new NotFoundError( const toPollFrom = await this.getNodesToPollFrom(pubkey.key);
'[pollOnceForOurDisplayName] aborted after selecting nodes to poll from'
);
}
const resultsFromUserProfile = await SnodeAPIRetrieve.retrieveNextMessages( if (abortSignal?.aborted) {
toPollFrom, throw new NotFoundError(
[''], '[pollOnceForOurDisplayName] aborted after selecting nodes to poll from'
pubkey.key,
[SnodeNamespaces.UserProfile],
pubkey.key,
null
); );
}
// check if we just fetched the details from the config namespaces. const resultsFromUserProfile = await SnodeAPIRetrieve.retrieveNextMessages(
// If yes, merge them together and exclude them from the rest of the messages. toPollFrom,
if (!resultsFromUserProfile?.length) { [''],
throw new NotFoundError('[pollOnceForOurDisplayName] resultsFromUserProfile is empty'); pubkey.key,
} [SnodeNamespaces.UserProfile],
pubkey.key,
null
);
if (abortSignal?.aborted) { // check if we just fetched the details from the config namespaces.
throw new NotFoundError( // If yes, merge them together and exclude them from the rest of the messages.
'[pollOnceForOurDisplayName] aborted after retrieving user profile config messages' if (!resultsFromUserProfile?.length) {
); throw new NotFoundError('[pollOnceForOurDisplayName] resultsFromUserProfile is empty');
} }
const userConfigMessages = resultsFromUserProfile if (abortSignal?.aborted) {
.filter(m => SnodeNamespace.isUserConfigNamespace(m.namespace)) throw new NotFoundError(
.map(r => r.messages.messages); '[pollOnceForOurDisplayName] aborted after retrieving user profile config messages'
);
}
const userConfigMessagesMerged = flatten(compact(userConfigMessages)); const userConfigMessages = resultsFromUserProfile
if (!userConfigMessagesMerged.length) { .filter(m => SnodeNamespace.isUserConfigNamespace(m.namespace))
throw new NotFoundError( .map(r => r.messages.messages);
'[pollOnceForOurDisplayName] after merging there are no user config messages'
);
}
const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true);
if (isEmpty(displayName)) { const userConfigMessagesMerged = flatten(compact(userConfigMessages));
throw new NotFoundError( if (!userConfigMessagesMerged.length) {
'[pollOnceForOurDisplayName] Got a config message from network but without a displayName...' throw new NotFoundError(
); '[pollOnceForOurDisplayName] after merging there are no user config messages'
} );
}
const displayName = await this.handleSharedConfigMessages(userConfigMessagesMerged, true);
return displayName; if (isEmpty(displayName)) {
} catch (e) { throw new NotFoundError(
if (e.message === ERROR_CODE_NO_CONNECT) { '[pollOnceForOurDisplayName] Got a config message from network but without a displayName...'
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;
} }
return displayName;
} }
} }

Loading…
Cancel
Save