feat: 封存解散群聊后用户端隐藏 archived 会话

- 用户会话列表(ListConversations)过滤 status=active,死群不再堆在列表
- 未读统计(CountUnreadMessages)排除 archived 会话,消除消不掉的红点
- 数据完整保留,客服后台与历史记录查看不受影响,保留纠纷证据链

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
yml2213
2026-06-29 22:59:40 +08:00
co-authored by Claude Opus 4.8
parent be5d322c10
commit 4f4f71f251
2 changed files with 5 additions and 1 deletions
@@ -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).
@@ -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