Skip to content

Commit 4ef893b

Browse files
committed
Fix profile enrichment: detect handle-as-displayName and reduce debounce
The appview echoes the handle as displayName when a profile record hasn't synced yet, so isIncompleteProfile was never flagging these profiles. Changes: - Detect displayName === handle as incomplete (appview echoes handle) - Patch displayName even when set, if it's just the handle echoed back - Also enrich profiles that have only a description from PDS - Reduce debounce from 200ms to 50ms to minimize flash of incomplete data
1 parent aeab006 commit 4ef893b

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

src/state/queries/profile-enrichment.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,24 @@ type Enrichment = {
1313

1414
/**
1515
* A profile is "incomplete" when the appview has the account but hasn't
16-
* synced the profile record yet: the DID exists but there's no avatar
17-
* AND no displayName.
16+
* synced the profile record yet. Detection heuristics:
17+
* - No avatar at all, OR
18+
* - displayName is missing/empty, OR
19+
* - displayName equals the handle (appview echoes handle as displayName
20+
* when the profile record hasn't synced)
1821
*/
1922
function isIncompleteProfile(obj: any): boolean {
2023
if (!obj || typeof obj !== 'object') return false
2124
if (typeof obj.did !== 'string' || !obj.did.startsWith('did:')) return false
2225
if (!('handle' in obj)) return false
2326
if (obj.__enriched || obj.__fallbackMode) return false
24-
if (obj.avatar || obj.displayName) return false
25-
return true
27+
28+
const hasAvatar = !!obj.avatar
29+
const hasRealDisplayName = !!obj.displayName && obj.displayName !== obj.handle // appview echoes handle when unsynced
30+
31+
// Incomplete if missing avatar AND missing a real display name
32+
if (!hasAvatar && !hasRealDisplayName) return true
33+
return false
2634
}
2735

2836
/**
@@ -64,7 +72,8 @@ async function fetchProfileEnrichment(did: string): Promise<Enrichment | null> {
6472
)
6573
if (!record?.value) return null
6674
const v = record.value
67-
if (!v.displayName && !v.avatar) return null
75+
// Return enrichment if there's anything useful (displayName, avatar, or description)
76+
if (!v.displayName && !v.avatar && !v.description) return null
6877
return {
6978
displayName: v.displayName || '',
7079
description: v.description || '',
@@ -116,7 +125,12 @@ function deepEnrich(
116125
) {
117126
const e = enrichments.get(data.did)!
118127
const patch: any = {__enriched: true}
119-
if (e.displayName && !data.displayName) patch.displayName = e.displayName
128+
// Patch displayName if missing or if appview just echoed the handle
129+
if (
130+
e.displayName &&
131+
(!data.displayName || data.displayName === data.handle)
132+
)
133+
patch.displayName = e.displayName
120134
if (e.description && 'description' in data && !data.description)
121135
patch.description = e.description
122136
if (e.avatar && !data.avatar) patch.avatar = e.avatar
@@ -229,7 +243,7 @@ function scheduleEnrichment(queryClient: QueryClient): void {
229243
pendingDids = new Set()
230244
if (batch.size === 0) return
231245
processBatch(queryClient, batch)
232-
}, 200)
246+
}, 50)
233247
}
234248

235249
async function processBatch(

0 commit comments

Comments
 (0)