feat: sync user profile to remote instances on federation connect and profile update
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user