feat(web): refetch DM list after re-attach so reconciled conversation replaces the split (reattach-dm-reconcile spec §3.4)

This commit is contained in:
Jannis Braun
2026-07-03 12:44:00 +02:00
parent 011a9be92a
commit 21c8731f3a
5 changed files with 134 additions and 1 deletions
@@ -56,6 +56,15 @@ vi.mock('../../../stores/transferStore', () => ({
),
}));
// spaceStore is imported for the post-reattach DM refetch (reloadDmsForOrigin);
// stub it so this isolated render doesn't load the real store's audio import chain.
vi.mock('../../../stores/spaceStore', () => ({
useSpaceStore: Object.assign(
(selector: (s: unknown) => unknown) => selector({}),
{ getState: () => ({ reloadDmsForOrigin: vi.fn().mockResolvedValue(undefined) }), setState: vi.fn(), subscribe: vi.fn() },
),
}));
// api.uploads.url is referenced during render for avatar/banner sources;
// api.users.reattach is the peer call the fallback action fires on confirm.
vi.mock('../../../api/client', () => ({
@@ -2,6 +2,7 @@ import { useState, useEffect, useRef, useMemo } from 'react';
import { useAuthStore } from '../../../stores/authStore';
import { useUIStore } from '../../../stores/uiStore';
import { useInstanceStore } from '../../../stores/instanceStore';
import { useSpaceStore } from '../../../stores/spaceStore';
import { Avatar } from '../../ui/Avatar';
import { ImageCropModal } from '../../ui/ImageCropModal';
import { DeleteAccountModal } from '../DeleteAccountModal';
@@ -110,6 +111,10 @@ export function AccountPanel() {
const { token } = await homeConnection.api.auth.attachProof(window.location.hostname);
const res = await api.users.reattach({ token });
useAuthStore.getState().setUser(res.user);
// Re-attach reconciled this (home) account's 1-on-1 DM federatedIds on the
// server; refetch the home DM list so the split conversation collapses
// without a reload.
try { await useSpaceStore.getState().reloadDmsForOrigin(''); } catch { /* non-fatal */ }
addToast(`Account re-linked with ${homeConnection.username}`, 'success', 3000);
} catch (err) {
setReattachError(err instanceof Error ? err.message : 'Re-attach failed');