feat: add background retry scheduler for federation password sync

Replace the give-up-after-3-retries path with a persistent background
scheduler: 10 retries every 30s (5 min), then 12 retries every 5 min
(1 hr). Active timers are keyed by origin so rapid password changes
cancel and replace the previous loop. All timers are cleared on logout
via clearPasswordSyncTimers() called from instanceStore.reset().
This commit is contained in:
Jannis Braun
2026-03-23 00:52:40 +01:00
parent 678e1bf358
commit 95cb9d4df2
2 changed files with 93 additions and 2 deletions
+6
View File
@@ -5,6 +5,10 @@ import { useAuthStore } from './authStore';
import { setApiForOriginResolver, setUserIdForOriginResolver, setOriginFromHostnameResolver, useSpaceStore } from './spaceStore';
import { connectInstance, disconnectInstance, disconnectAllRemote } from '../hooks/useWebSocket';
import { syncProfileToRemote } from '../utils/profileSync';
// Circular dependency: federationOps imports useInstanceStore, instanceStore imports this.
// Safe because both modules access each other lazily (at call time, not import time).
// clearPasswordSyncTimers itself does not reference useInstanceStore.
import { clearPasswordSyncTimers } from '../utils/federationOps';
// ─── Types ───────────────────────────────────────────────────────────────────
@@ -696,6 +700,8 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Tear down all remote WebSocket connections
disconnectAllRemote();
clearPasswordSyncTimers();
set({ instances: [], isLoading: false, error: null, _autoConnectDone: false, pendingSyncOrigins: [] });
// Token cache preserved — scoped per user, survives logout for seamless reconnect
},