fix: prevent duplicate DMs at creation time, clean up corrupted read states
Replace the unreliable client-side DM dedup loop in populateFromReady with a creation-time guard (findExistingDmForUser) that checks all instances before opening a new DM. Guards added to FriendsPage, NewDmModal, and UserProfilePopout. Also fixes: corrupted read_states from temp_ optimistic message IDs (server migration + client-side validation), federation-aware closeDm/addDmMember API routing, isSelf-based DM member filtering in sidebar/header, and WS event error isolation.
This commit is contained in:
@@ -2,7 +2,7 @@ import React, { useState, useRef, useEffect } from 'react';
|
||||
import { Modal } from '../ui/Modal';
|
||||
import { Avatar } from '../ui/Avatar';
|
||||
import { useUIStore } from '../../stores/uiStore';
|
||||
import { useServerStore } from '../../stores/serverStore';
|
||||
import { useServerStore, getApiForOrigin } from '../../stores/serverStore';
|
||||
import { api } from '../../api/client';
|
||||
import type { User } from '@backspace/shared';
|
||||
|
||||
@@ -16,6 +16,7 @@ export function AddDmMemberModal() {
|
||||
const modalData = useUIStore((s) => s.modalData);
|
||||
const closeModal = useUIStore((s) => s.closeModal);
|
||||
const dmChannels = useServerStore((s) => s.dmChannels);
|
||||
const channelOriginMap = useServerStore((s) => s.channelOriginMap);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const searchTimer = useRef<ReturnType<typeof setTimeout>>();
|
||||
|
||||
@@ -67,7 +68,9 @@ export function AddDmMemberModal() {
|
||||
setError('');
|
||||
setIsAdding(true);
|
||||
try {
|
||||
await api.dm.addMember(dmChannelId, { userId: user.id });
|
||||
const origin = channelOriginMap.get(dmChannelId) || '';
|
||||
const targetApi = getApiForOrigin(origin);
|
||||
await targetApi.dm.addMember(dmChannelId, { userId: user.id });
|
||||
closeModal();
|
||||
} catch (err) {
|
||||
setError((err as Error).message || 'Failed to add member');
|
||||
|
||||
@@ -59,6 +59,13 @@ export function NewDmModal() {
|
||||
const handleSelectUser = async (user: User) => {
|
||||
setError('');
|
||||
try {
|
||||
const existing = useServerStore.getState().findExistingDmForUser(user);
|
||||
if (existing) {
|
||||
closeModal();
|
||||
useUIStore.getState().setShowDms(true);
|
||||
navigate(`/channels/@me/${existing.dm.id}`);
|
||||
return;
|
||||
}
|
||||
const channel = await api.dm.create({ userId: user.id });
|
||||
addDmChannel(channel);
|
||||
closeModal();
|
||||
|
||||
Reference in New Issue
Block a user