fix: cache federated user identity from WS ready to fix server mute/deafen

getMyUserIdForOrigin relied on instanceStore resolver which could return
the home user ID during connection errors. Cache the authoritative user
ID directly from the WS ready payload, ensuring effective-state
computations use the correct federated identity.
This commit is contained in:
Jannis Braun
2026-03-09 23:01:19 +01:00
parent 907f8285cd
commit 11a69fe92a
2 changed files with 18 additions and 1 deletions
+12
View File
@@ -592,6 +592,14 @@ export function setUserIdForOriginResolver(resolver: (origin: string) => string
_getUserIdForOrigin = resolver;
}
// Direct identity cache populated from WS ready events.
// Bypasses the instanceStore resolver for reliable federation support.
const _myUserIdByOrigin = new Map<string, string>();
export function setMyUserIdForOrigin(origin: string, userId: string): void {
_myUserIdByOrigin.set(origin, userId);
}
/**
* Returns the local user's ID on a given instance origin.
* '' or falsy = home instance (returns authStore user ID).
@@ -599,5 +607,9 @@ export function setUserIdForOriginResolver(resolver: (origin: string) => string
*/
export function getMyUserIdForOrigin(origin: string): string | undefined {
if (!origin) return useAuthStore.getState().user?.id;
// Direct cache (populated from WS ready) takes priority — always correct
const cached = _myUserIdByOrigin.get(origin);
if (cached) return cached;
// Fallback to instanceStore resolver (may have placeholder user during connection)
return _getUserIdForOrigin?.(origin);
}