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