From 4f4f71f251e4a5207667211fd75d17043900fff7 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Mon, 29 Jun 2026 22:59:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B0=81=E5=AD=98=E8=A7=A3=E6=95=A3?= =?UTF-8?q?=E7=BE=A4=E8=81=8A=E5=90=8E=E7=94=A8=E6=88=B7=E7=AB=AF=E9=9A=90?= =?UTF-8?q?=E8=97=8F=20archived=20=E4=BC=9A=E8=AF=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 用户会话列表(ListConversations)过滤 status=active,死群不再堆在列表 - 未读统计(CountUnreadMessages)排除 archived 会话,消除消不掉的红点 - 数据完整保留,客服后台与历史记录查看不受影响,保留纠纷证据链 Co-Authored-By: Claude Opus 4.8 (1M context) --- backend/internal/modules/chat/conversation.go | 4 +++- backend/internal/modules/chat/participant.go | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/internal/modules/chat/conversation.go b/backend/internal/modules/chat/conversation.go index c94e485..7d09ab2 100644 --- a/backend/internal/modules/chat/conversation.go +++ b/backend/internal/modules/chat/conversation.go @@ -15,7 +15,8 @@ func (r *Repository) ListConversations(ctx context.Context, principal Principal, var total int64 countDB := db.Table("chat_conversations AS c"). Joins("JOIN chat_participants AS cp ON cp.conversation_id = c.id"). - Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID) + Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID). + Where("c.status = ?", "active") if err := countDB.Count(&total).Error; err != nil { return nil, err } @@ -23,6 +24,7 @@ func (r *Repository) ListConversations(ctx context.Context, principal Principal, var rows []conversationRow offset := (page - 1) * pageSize err := r.conversationQuery(ctx, principal). + Where("c.status = ?", "active"). Order("COALESCE(c.last_message_at, c.created_at) DESC, c.id DESC"). Offset(offset). Limit(pageSize). diff --git a/backend/internal/modules/chat/participant.go b/backend/internal/modules/chat/participant.go index 544258d..f7a4d4f 100644 --- a/backend/internal/modules/chat/participant.go +++ b/backend/internal/modules/chat/participant.go @@ -54,7 +54,9 @@ func (r *Repository) CountUnreadMessages(ctx context.Context, principal Principa var total int64 err := r.db.WithContext(ctx).Table("chat_messages AS cm"). Joins("JOIN chat_participants AS cp ON cp.conversation_id = cm.conversation_id"). + Joins("JOIN chat_conversations AS c ON c.id = cm.conversation_id"). Where("cp.participant_type = ? AND cp.participant_id = ?", principal.Type, principal.ID). + Where("c.status = ?", "active"). Where("NOT (cm.sender_type = ? AND cm.sender_id = ?)", principal.Type, principal.ID). Where("(cp.last_read_at IS NULL OR cm.created_at > cp.last_read_at)"). Count(&total).Error