diff --git a/src/app/(dashboard)/chats/page.tsx b/src/app/(dashboard)/chats/page.tsx index d27a467..96d67a2 100644 --- a/src/app/(dashboard)/chats/page.tsx +++ b/src/app/(dashboard)/chats/page.tsx @@ -510,10 +510,13 @@ const formatPreviewContent = (content: string) => { ? { ...conv, lastMessage: getDisplayContent(content), lastMessageTime: "Just now" } : conv ) - const idx = updated.findIndex((c) => c.id === activeChat) - if (idx > 0) { - const [item] = updated.splice(idx, 1) - updated.unshift(item) + const conv = updated.find((c) => c.id === activeChat) + if (conv && !conv.pinned) { + const idx = updated.findIndex((c) => c.id === activeChat) + if (idx > 0) { + const [item] = updated.splice(idx, 1) + updated.unshift(item) + } } return updated }) @@ -842,7 +845,7 @@ const formatPreviewContent = (content: string) => { setUnreadMap((prev) => { const m = new Map(prev); m.set(conv.id, 0); return m }) setConversations((prev) => { const idx = prev.findIndex((c) => c.id === conv.id) - if (idx > 0) { + if (idx > 0 && !conv.pinned) { const u = [...prev] const [item] = u.splice(idx, 1) u.unshift(item) diff --git a/src/app/api/conversations/route.ts b/src/app/api/conversations/route.ts index cd3ba0f..2561244 100644 --- a/src/app/api/conversations/route.ts +++ b/src/app/api/conversations/route.ts @@ -29,7 +29,7 @@ export async function GET() { WHERE c.id IN ( SELECT conversation_id FROM conversation_participants WHERE user_id = $1 ) - ORDER BY cp_me.pinned_at DESC NULLS LAST, c.updated_at DESC + ORDER BY cp_me.pinned_at DESC NULLS LAST, CASE WHEN cp_me.pinned_at IS NULL THEN c.updated_at END DESC LIMIT 50`, [user.id], )