feat: sync user profile to remote instances on federation connect and profile update

This commit is contained in:
Jannis Braun
2026-03-11 01:33:18 +01:00
parent 3790386a5f
commit a5fcb78434
3 changed files with 181 additions and 1 deletions
+6 -1
View File
@@ -6,6 +6,7 @@ import { useSpaceStore } from './spaceStore';
import { useSocialStore } from './socialStore';
import { useVoiceStore } from './voiceStore';
import { useInstanceStore } from './instanceStore';
import { syncProfileUpdateToRemotes } from '../utils/profileSync';
interface AuthState {
token: string | null;
@@ -16,7 +17,7 @@ interface AuthState {
register: (username: string, password: string, displayName?: string) => Promise<void>;
logout: () => void;
loadUser: () => Promise<void>;
updateProfile: (data: { displayName?: string; avatar?: string; banner?: string; accentColor?: string; bio?: string; customStatus?: string; status?: UserStatus }) => Promise<void>;
updateProfile: (data: { displayName?: string; avatar?: string; banner?: string; accentColor?: string; avatarColor?: string; bio?: string; customStatus?: string; status?: UserStatus }) => Promise<void>;
setUser: (user: User) => void;
clearError: () => void;
}
@@ -84,6 +85,10 @@ export const useAuthStore = create<AuthState>((set, get) => ({
try {
const user = await api.users.update(data);
set({ user });
// Push profile changes to all connected remote instances
syncProfileUpdateToRemotes(data).catch((err) => {
console.warn('[ProfileSync] Failed to sync to remotes:', err);
});
} catch (err) {
set({ error: err instanceof Error ? err.message : 'Update failed' });
throw err;
+16
View File
@@ -4,6 +4,7 @@ import { BackspaceApiClient, createApiClient, api } from '../api/client';
import { useAuthStore } from './authStore';
import { setApiForOriginResolver, setUserIdForOriginResolver, setOriginFromHostnameResolver, useSpaceStore } from './spaceStore';
import { connectInstance, disconnectInstance, disconnectAllRemote } from '../hooks/useWebSocket';
import { syncProfileToRemote } from '../utils/profileSync';
// ─── Types ───────────────────────────────────────────────────────────────────
@@ -241,6 +242,11 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Open WebSocket connection to the remote instance
connectInstance(origin, response.token);
// Sync full home profile to new remote (fire-and-forget)
syncProfileToRemote(instance).catch((err) => {
console.warn(`[ProfileSync] Initial sync to ${origin} failed:`, err);
});
// Sync instance list to all instances (fire-and-forget)
get().syncInstanceList().catch(() => {});
} catch (err) {
@@ -281,6 +287,11 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Open WebSocket connection to the remote instance
connectInstance(origin, response.token);
// Sync full home profile to remote (fire-and-forget)
syncProfileToRemote(instance).catch((err) => {
console.warn(`[ProfileSync] Login sync to ${origin} failed:`, err);
});
// Sync instance list to all instances (fire-and-forget)
get().syncInstanceList().catch(() => {});
} catch (err) {
@@ -527,6 +538,11 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Open WebSocket connection now that we've verified the token
connectInstance(origin, cachedEntry.token);
// Sync home profile to reconnected remote (fire-and-forget)
syncProfileToRemote(connectedInstance).catch((err) => {
console.warn(`[ProfileSync] Reconnect sync to ${origin} failed:`, err);
});
} catch (err) {
if (isNetworkError(err)) {
// Instance unreachable (NAT hairpinning, DNS, server down) — token may still be valid