Browse Source

fix: reattempt to get user profiles

as they often are not recieved the first time
master
DanConwayDev 2 years ago
parent
commit
290650a435
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 57
      src/lib/stores/users.ts

57
src/lib/stores/users.ts

@ -20,26 +20,43 @@ export const ensureUser = (hexpubkey: string): Writable<UserObject> => {
users[hexpubkey] = writable(base) users[hexpubkey] = writable(base)
getUserRelays(hexpubkey) getUserRelays(hexpubkey)
u.fetchProfile({ const getProfile = () => {
closeOnEose: true, u.fetchProfile({
groupable: true, closeOnEose: true,
// default 100 groupable: true,
groupableDelay: 200, // default 100
}).then( groupableDelay: 200,
(p) => { }).then(
users[hexpubkey].update((u) => ({ (p) => {
...u, users[hexpubkey].update((u) => ({
loading: false, ...u,
profile: p === null ? undefined : p, loading: false,
})) profile: p === null ? undefined : p,
}, }))
() => { },
users[hexpubkey].update((u) => ({ () => {
...u, users[hexpubkey].update((u) => ({
loading: false, ...u,
})) loading: false,
} }))
) }
)
}
let attempts = 1
const tryAgainin3s = () => {
setTimeout(
() => {
if (!get(users[hexpubkey]).profile) {
getProfile()
attempts++
if (attempts < 5) tryAgainin3s()
}
},
(attempts ^ 2) * 1000
)
}
getProfile()
tryAgainin3s()
} }
return users[hexpubkey] return users[hexpubkey]
} }

Loading…
Cancel
Save