Skip to content

Commit 7da2599

Browse files
authored
Merge pull request #1603 from session-foundation/fix/fetch-displayname-form-whole-swarm
fix: fetch display name from whole swarm on seed recovery
2 parents fcc23ff + 1d2be31 commit 7da2599

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

ts/session/apis/snode_api/swarmPolling.ts

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
isEmpty,
1313
last,
1414
omit,
15-
sample,
1615
sampleSize,
1716
toNumber,
1817
uniqBy,
@@ -990,9 +989,8 @@ export class SwarmPolling {
990989
const pubkey = UserUtils.getOurPubKeyFromCache();
991990

992991
const swarmSnodes = await SnodePool.getSwarmFor(pubkey.key);
993-
const toPollFrom = sample(swarmSnodes);
994992

995-
if (!toPollFrom) {
993+
if (!swarmSnodes.length) {
996994
throw new Error(
997995
`[pollOnceForOurDisplayName] no snode in swarm for ${ed25519Str(pubkey.key)}`
998996
);
@@ -1004,23 +1002,35 @@ export class SwarmPolling {
10041002
);
10051003
}
10061004

1007-
// Note: always print something so we know if the polling is hanging
1008-
window.log.info(
1009-
`[onboarding] about to pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} `
1010-
);
1005+
const allResultsFromUserProfile = await Promise.allSettled(
1006+
swarmSnodes.map(async toPollFrom => {
1007+
// Note: always print something so we know if the polling is hanging
1008+
window.log.info(
1009+
`[onboarding] about to pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} `
1010+
);
1011+
const retrieved = await SnodeAPIRetrieve.retrieveNextMessagesNoRetries(
1012+
toPollFrom,
1013+
pubkey.key,
1014+
[{ lastHash: '', namespace: SnodeNamespaces.UserProfile }],
1015+
pubkey.key,
1016+
null,
1017+
false
1018+
);
10111019

1012-
const resultsFromUserProfile = await SnodeAPIRetrieve.retrieveNextMessagesNoRetries(
1013-
toPollFrom,
1014-
pubkey.key,
1015-
[{ lastHash: '', namespace: SnodeNamespaces.UserProfile }],
1016-
pubkey.key,
1017-
null,
1018-
false
1020+
// Note: always print something so we know if the polling is hanging
1021+
window.log.info(
1022+
`[onboarding] pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} returned: ${retrieved?.length}`
1023+
);
1024+
return retrieved;
1025+
})
10191026
);
10201027

1021-
// Note: always print something so we know if the polling is hanging
1022-
window.log.info(
1023-
`[onboarding] pollOnceForOurDisplayName of ${ed25519Str(pubkey.key)} from snode: ${ed25519Str(toPollFrom.pubkey_ed25519)} namespaces: ${[SnodeNamespaces.UserProfile]} returned: ${resultsFromUserProfile?.length}`
1028+
const resultsFromUserProfile = flatten(
1029+
compact(
1030+
allResultsFromUserProfile
1031+
.filter(promise => promise.status === 'fulfilled')
1032+
.map(promise => promise.value)
1033+
)
10241034
);
10251035

10261036
// check if we just fetched the details from the config namespaces.

0 commit comments

Comments
 (0)