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:
@@ -89,17 +89,21 @@ export default async function chatRoutes(app: FastifyInstance) {
|
||||
|
||||
const onlineSet = new Set(connections.keys());
|
||||
|
||||
// For private chats, resolve title/avatar/color from the other member
|
||||
const other = chat.type === 'private' ? members.find((m: any) => m.id !== userId) : null;
|
||||
|
||||
return {
|
||||
id: chat.id,
|
||||
type: chat.type,
|
||||
title: chat.title,
|
||||
title: chat.type === 'private' ? (other?.display_name || '') : chat.title,
|
||||
description: chat.description,
|
||||
avatarColor: chat.avatar_color,
|
||||
avatar: chat.avatar || null,
|
||||
avatarColor: chat.type === 'private' ? (other?.avatar_color || chat.avatar_color) : chat.avatar_color,
|
||||
avatar: chat.type === 'private' ? (other?.avatar || null) : (chat.avatar || null),
|
||||
isPublic: chat.is_public,
|
||||
myRole: member.role,
|
||||
canSendMessages: member.can_send_messages,
|
||||
canAddMembers: member.can_add_members,
|
||||
privateUserId: chat.type === 'private' ? (other?.id || null) : null,
|
||||
createdAt: chat.created_at,
|
||||
members: members.map(m => ({
|
||||
id: m.id, username: m.username, displayName: m.display_name,
|
||||
|
||||
@@ -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