fix: federation DM identity resolution — cross-instance isSelf() failure

Add a cross-instance self-ID registry to identity.ts so isSelf() can
recognize the current user's Snowflake IDs from all connected instances.
Previously, federated DMs showed the user themselves as the other party
because remote-instance IDs didn't match the home user ID.

- Register user IDs from every WS ready event (home + remote)
- Clear the registry on session reset (login/logout/register/delete)
- Fix isSelf() username comparison to parse both sides as federated
- Replace naive ID check in MessageList WelcomeHeader with isSelf()
This commit is contained in:
Jannis Braun
2026-03-12 18:53:38 +01:00
parent 83699d7e91
commit 8af155d08f
4 changed files with 26 additions and 2 deletions
+18 -1
View File
@@ -11,6 +11,20 @@ export function parseFederatedUsername(username: string): { baseName: string; do
return { baseName: username.slice(0, atIndex), domain: username.slice(atIndex + 1) };
}
// ─── Cross-instance self-ID registry ─────────────────────────────────────────
// Tracks all Snowflake IDs that belong to the current user across connected
// instances (home + remotes). Populated from WS `ready` events.
const _knownSelfIds = new Set<string>();
export function registerSelfId(id: string): void {
_knownSelfIds.add(id);
}
export function clearSelfIds(): void {
_knownSelfIds.clear();
}
/**
* Stateless check: is `user` a replicated alias of `homeUser`?
* Uses the immutable (username, homeInstance) composite key —
@@ -23,12 +37,15 @@ export function isSelf(
if (!homeUser) return false;
// Same instance, same ID — trivial case
if (user.id === homeUser.id) return true;
// Cross-instance: check all known user IDs from connected instances
if (_knownSelfIds.has(user.id)) return true;
// Replicated user: homeInstance matches our origin
if (!user.homeInstance) return false;
if (user.homeInstance !== window.location.host) return false;
// Username: "youruser" or "youruser@nova.ddns.net" → base must match
const { baseName } = parseFederatedUsername(user.username);
return baseName === homeUser.username;
const { baseName: homeBase } = parseFederatedUsername(homeUser.username);
return baseName === homeBase;
}
/**