feat(web): wire federation registry into connectToRemote, loginToRemote, and reconnectInstance flows

This commit is contained in:
Jannis Braun
2026-04-01 18:01:48 +02:00
parent d7e2f25c31
commit c22d568605
+44
View File
@@ -313,6 +313,21 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
return { instances: updated, isLoading: false }; 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 // Open WebSocket connection to the remote instance
connectInstance(origin, response.token); connectInstance(origin, response.token);
@@ -333,6 +348,7 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Sync instance list to all instances (fire-and-forget) // Sync instance list to all instances (fire-and-forget)
get().syncInstanceList().catch(() => {}); get().syncInstanceList().catch(() => {});
get().syncRegistry().catch(() => {});
} catch (err) { } catch (err) {
set({ isLoading: false, error: (err as Error).message }); set({ isLoading: false, error: (err as Error).message });
throw err; throw err;
@@ -368,6 +384,21 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
return { instances: updated, isLoading: false }; 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 // Open WebSocket connection to the remote instance
connectInstance(origin, response.token); connectInstance(origin, response.token);
@@ -378,6 +409,7 @@ export const useInstanceStore = create<InstanceState>((set, get) => ({
// Sync instance list to all instances (fire-and-forget) // Sync instance list to all instances (fire-and-forget)
get().syncInstanceList().catch(() => {}); get().syncInstanceList().catch(() => {});
get().syncRegistry().catch(() => {});
} catch (err) { } catch (err) {
set({ isLoading: false, error: (err as Error).message }); set({ isLoading: false, error: (err as Error).message });
throw err; throw err;
@@ -443,6 +475,18 @@ export const useInstanceStore = create<InstanceState>((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); connectInstance(origin, inst.token);
} catch (err) { } catch (err) {
if (isNetworkError(err)) { if (isNetworkError(err)) {