fix(dm): populate store before navigating to new group DM

addDmChannel must be called before navigate() so the route effect
finds the channel in the store immediately. Without this, the chat
view renders empty until the WS dm_channel_created event arrives.
Also show an error instead of silently returning when otherMember
cannot be determined.
This commit is contained in:
Jannis Braun
2026-03-26 22:36:21 +01:00
parent be20f23500
commit bf8fc589f9
@@ -18,6 +18,7 @@ export function AddDmMemberModal() {
const modalData = useUIStore((s) => s.modalData); const modalData = useUIStore((s) => s.modalData);
const closeModal = useUIStore((s) => s.closeModal); const closeModal = useUIStore((s) => s.closeModal);
const dmChannels = useSpaceStore((s) => s.dmChannels); const dmChannels = useSpaceStore((s) => s.dmChannels);
const addDmChannel = useSpaceStore((s) => s.addDmChannel);
const navigate = useNavigate(); const navigate = useNavigate();
const myUserId = useAuthStore((s) => s.user?.id); const myUserId = useAuthStore((s) => s.user?.id);
const inputRef = useRef<HTMLInputElement>(null); const inputRef = useRef<HTMLInputElement>(null);
@@ -74,8 +75,12 @@ export function AddDmMemberModal() {
if (!dmChannel.ownerId) { if (!dmChannel.ownerId) {
// 1-on-1 DM → create a new group DM with all 3 users // 1-on-1 DM → create a new group DM with all 3 users
const otherMember = dmChannel.members.find(m => m.id !== myUserId); const otherMember = dmChannel.members.find(m => m.id !== myUserId);
if (!otherMember) return; if (!otherMember) {
setError('Could not determine the other member of this conversation.');
return;
}
const newChannel = await api.dm.createGroup({ userIds: [otherMember.id, user.id] }); const newChannel = await api.dm.createGroup({ userIds: [otherMember.id, user.id] });
addDmChannel(newChannel);
closeModal(); closeModal();
navigate(`/channels/@me/${newChannel.id}`); navigate(`/channels/@me/${newChannel.id}`);
} else { } else {