mirror of
https://github.com/dergigi/boris.git
synced 2025-12-17 06:34:24 +01:00
fix: allow profile labels to update from fallback to resolved names
Previously, useProfileLabels would set fallback npub labels immediately for missing profiles, then skip updating them when profiles were fetched because the condition checked if the label already existed. Now we track which profiles were being fetched (pubkeysToFetch) and update their labels even if they already have fallback labels set, allowing profiles to resolve progressively from fallback npubs to actual names as they load.
This commit is contained in:
@@ -148,13 +148,16 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
|
|
||||||
// Fetch missing profiles asynchronously
|
// Fetch missing profiles asynchronously
|
||||||
if (pubkeysToFetch.length > 0 && relayPool && eventStore) {
|
if (pubkeysToFetch.length > 0 && relayPool && eventStore) {
|
||||||
|
const pubkeysToFetchSet = new Set(pubkeysToFetch)
|
||||||
fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch)
|
fetchProfiles(relayPool, eventStore as unknown as IEventStore, pubkeysToFetch)
|
||||||
.then((fetchedProfiles) => {
|
.then((fetchedProfiles) => {
|
||||||
const updatedLabels = new Map(labels)
|
const updatedLabels = new Map(labels)
|
||||||
const fetchedProfilesByPubkey = new Map(fetchedProfiles.map(p => [p.pubkey, p]))
|
const fetchedProfilesByPubkey = new Map(fetchedProfiles.map(p => [p.pubkey, p]))
|
||||||
|
|
||||||
profileData.forEach(({ encoded, pubkey }) => {
|
profileData.forEach(({ encoded, pubkey }) => {
|
||||||
if (!updatedLabels.has(encoded)) {
|
// Only update profiles that were in pubkeysToFetch (i.e., were being fetched)
|
||||||
|
// This allows us to replace fallback labels with resolved names
|
||||||
|
if (pubkeysToFetchSet.has(pubkey)) {
|
||||||
// First, try to use the profile from the returned array
|
// First, try to use the profile from the returned array
|
||||||
const fetchedProfile = fetchedProfilesByPubkey.get(pubkey)
|
const fetchedProfile = fetchedProfilesByPubkey.get(pubkey)
|
||||||
if (fetchedProfile) {
|
if (fetchedProfile) {
|
||||||
@@ -192,16 +195,10 @@ export function useProfileLabels(content: string, relayPool?: RelayPool | null):
|
|||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
const fallback = getNpubFallbackDisplay(pubkey)
|
||||||
updatedLabels.set(encoded, fallback)
|
updatedLabels.set(encoded, fallback)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// No profile found, use fallback
|
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
|
||||||
updatedLabels.set(encoded, fallback)
|
|
||||||
}
|
}
|
||||||
} else {
|
// If no profile found in eventStore, keep existing fallback
|
||||||
// No eventStore, use fallback
|
|
||||||
const fallback = getNpubFallbackDisplay(pubkey)
|
|
||||||
updatedLabels.set(encoded, fallback)
|
|
||||||
}
|
}
|
||||||
|
// If no eventStore, keep existing fallback
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user