fix(social): deduplicate federated search results by canonical identity
Replicated profiles on remote instances have different local IDs but share the same homeUserId as the native profile. Use homeUserId ?? id as the dedup key so the same person only appears once. Home instance is queried first, so the native profile (with clean username) wins.
This commit is contained in:
@@ -261,9 +261,12 @@ export const useSocialStore = create<SocialState>((set, get) => ({
|
|||||||
if (result.status !== 'fulfilled') return;
|
if (result.status !== 'fulfilled') return;
|
||||||
const origin = searches[i]!.origin;
|
const origin = searches[i]!.origin;
|
||||||
for (const user of result.value) {
|
for (const user of result.value) {
|
||||||
const dedupeKey = `${origin ?? ''}:${user.id}`;
|
// Deduplicate by canonical identity: replicated profiles share
|
||||||
if (seen.has(dedupeKey)) continue;
|
// the same homeUserId as the native profile's id, so collapse them.
|
||||||
seen.add(dedupeKey);
|
// Prefer the first seen (home instance is queried first → native wins).
|
||||||
|
const canonicalId = user.homeUserId ?? user.id;
|
||||||
|
if (seen.has(canonicalId)) continue;
|
||||||
|
seen.add(canonicalId);
|
||||||
if (origin) normalizeUserAssets(user, origin);
|
if (origin) normalizeUserAssets(user, origin);
|
||||||
allUsers.push({ ...user, _instanceOrigin: origin });
|
allUsers.push({ ...user, _instanceOrigin: origin });
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user