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:
Ai
2026-05-22 12:32:06 +03:00
parent 5d3be2a628
commit 2a4b7d5abc
2 changed files with 21 additions and 9 deletions

View File

@@ -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,