fix: open private chat from sidebar search
- openOrCreatePrivate: load chat by ID directly (skip stale list lookup) - GET /api/chats/🆔 resolve title/avatar/privateUserId for private chats (was returning null title, causing chat area to behave unexpectedly) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -88,13 +88,21 @@ export default function MainLayout() {
|
||||
|
||||
async function openOrCreatePrivate(userId: string) {
|
||||
try {
|
||||
const { data } = await api.post(`/api/chats/private/${userId}`);
|
||||
const { data: allChats } = await api.get('/api/chats');
|
||||
setChats(allChats);
|
||||
const chat = allChats.find((c: any) => c.id === data.id);
|
||||
if (chat) openChat(chat);
|
||||
const { data: chatData } = await api.post(`/api/chats/private/${userId}`);
|
||||
setSearch('');
|
||||
} catch {}
|
||||
// Load full chat detail directly by ID — don't rely on list lookup
|
||||
const { data: fullChatData } = await api.get(`/api/chats/${chatData.id}`);
|
||||
// Also refresh the sidebar chat list
|
||||
api.get('/api/chats').then(r => setChats(r.data)).catch(() => {});
|
||||
// Build chat object to open
|
||||
const chatToOpen = { ...fullChatData, id: chatData.id };
|
||||
setActiveChat(chatToOpen);
|
||||
setFullChat(chatToOpen);
|
||||
setMobileChatOpen(true);
|
||||
setShowInfo(false);
|
||||
} catch (e) {
|
||||
console.error('openOrCreatePrivate:', e);
|
||||
}
|
||||
}
|
||||
|
||||
const filtered = chats.filter(c =>
|
||||
|
||||
Reference in New Issue
Block a user