From c22d56860536ad1e406dbb6c978da967076db6ee Mon Sep 17 00:00:00 2001 From: Jannis Braun <151788261+TheZwiss@users.noreply.github.com> Date: Wed, 1 Apr 2026 18:01:48 +0200 Subject: [PATCH] feat(web): wire federation registry into connectToRemote, loginToRemote, and reconnectInstance flows --- packages/web/src/stores/instanceStore.ts | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/packages/web/src/stores/instanceStore.ts b/packages/web/src/stores/instanceStore.ts index 9b78ef60..ae95a621 100644 --- a/packages/web/src/stores/instanceStore.ts +++ b/packages/web/src/stores/instanceStore.ts @@ -313,6 +313,21 @@ export const useInstanceStore = create((set, get) => ({ return { instances: updated, isLoading: false }; }); + // Upsert registry entry for the new connection + const registry = upsertRegistryEntry(get().registry, origin, { + origin, + label: instance.label, + username: instance.username, + remoteUserId: instance.user.id, + status: 'connected', + addedAt: get().registry.get(origin)?.addedAt ?? Date.now(), + lastConnectedAt: Date.now(), + disconnectedAt: null, + errorMessage: null, + }); + const registryUpdatedAt = Date.now(); + set({ registry, registryUpdatedAt }); + // Open WebSocket connection to the remote instance connectInstance(origin, response.token); @@ -333,6 +348,7 @@ export const useInstanceStore = create((set, get) => ({ // Sync instance list to all instances (fire-and-forget) get().syncInstanceList().catch(() => {}); + get().syncRegistry().catch(() => {}); } catch (err) { set({ isLoading: false, error: (err as Error).message }); throw err; @@ -368,6 +384,21 @@ export const useInstanceStore = create((set, get) => ({ return { instances: updated, isLoading: false }; }); + // Upsert registry entry for the login connection + const registry = upsertRegistryEntry(get().registry, origin, { + origin, + label: instance.label, + username: instance.username, + remoteUserId: instance.user.id, + status: 'connected', + addedAt: get().registry.get(origin)?.addedAt ?? Date.now(), + lastConnectedAt: Date.now(), + disconnectedAt: null, + errorMessage: null, + }); + const registryUpdatedAt = Date.now(); + set({ registry, registryUpdatedAt }); + // Open WebSocket connection to the remote instance connectInstance(origin, response.token); @@ -378,6 +409,7 @@ export const useInstanceStore = create((set, get) => ({ // Sync instance list to all instances (fire-and-forget) get().syncInstanceList().catch(() => {}); + get().syncRegistry().catch(() => {}); } catch (err) { set({ isLoading: false, error: (err as Error).message }); throw err; @@ -443,6 +475,18 @@ export const useInstanceStore = create((set, get) => ({ ), })); + // Update registry entry on successful reconnect + const registry = upsertRegistryEntry(get().registry, origin, { + origin, + status: 'connected', + lastConnectedAt: Date.now(), + disconnectedAt: null, + errorMessage: null, + }); + const registryUpdatedAt = Date.now(); + set({ registry, registryUpdatedAt }); + get().syncRegistry().catch(() => {}); + connectInstance(origin, inst.token); } catch (err) { if (isNetworkError(err)) {