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:
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import { useAuthStore } from '../stores/authStore';
|
import { useAuthStore } from '../stores/authStore';
|
||||||
import { useSpaceStore, getChannelOrigin, getMyUserIdForOrigin } from '../stores/spaceStore';
|
import { useSpaceStore, getChannelOrigin, getMyUserIdForOrigin, setMyUserIdForOrigin } from '../stores/spaceStore';
|
||||||
import { useChatStore } from '../stores/chatStore';
|
import { useChatStore } from '../stores/chatStore';
|
||||||
import { useVoiceStore } from '../stores/voiceStore';
|
import { useVoiceStore } from '../stores/voiceStore';
|
||||||
import { useSocialStore } from '../stores/socialStore';
|
import { useSocialStore } from '../stores/socialStore';
|
||||||
@@ -109,6 +109,11 @@ function handleEvent(origin: string, event: ServerEvent): void {
|
|||||||
|
|
||||||
populateFromReady(origin, event.spaces, event.folders, event.dmChannels);
|
populateFromReady(origin, event.spaces, event.folders, event.dmChannels);
|
||||||
|
|
||||||
|
// Cache authoritative identity for this origin (federation-safe)
|
||||||
|
if (!isHome) {
|
||||||
|
setMyUserIdForOrigin(origin, event.user.id);
|
||||||
|
}
|
||||||
|
|
||||||
// Mark remote instance as connected in instanceStore
|
// Mark remote instance as connected in instanceStore
|
||||||
if (!isHome) {
|
if (!isHome) {
|
||||||
import('../stores/instanceStore').then(({ useInstanceStore }) => {
|
import('../stores/instanceStore').then(({ useInstanceStore }) => {
|
||||||
|
|||||||
@@ -592,6 +592,14 @@ export function setUserIdForOriginResolver(resolver: (origin: string) => string
|
|||||||
_getUserIdForOrigin = resolver;
|
_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.
|
* Returns the local user's ID on a given instance origin.
|
||||||
* '' or falsy = home instance (returns authStore user ID).
|
* '' 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 {
|
export function getMyUserIdForOrigin(origin: string): string | undefined {
|
||||||
if (!origin) return useAuthStore.getState().user?.id;
|
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);
|
return _getUserIdForOrigin?.(origin);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user