feat(phase2c): 群聊与已读回执功能完整实现
Phase 2c 全部 14 个 Task 完成,包含: 后端(Go): - MinIO 文件存储服务集成(Docker + Go SDK + 通用上传 API) - Group 模块完整实现(DAO + Service + Controller + Router + Wire) - 18 个群管理 REST API + 11 个 WS 群事件推送 - 群创建/解散/邀请/踢人/退出/转让群主/设管理员/禁言/全体禁言/群公告/群昵称/免打扰/搜索 - IM Service 扩展(群消息发送/撤回 + @提醒 + 管理员无时限撤回) - 已读回执后端(单聊会话级 last_read_msg_id + 群聊消息级 im_message_reads) - 管理端群组管理(列表/详情/解散) - 数据库迁移(3 张新表 + 2 张表字段扩展) 前端(uni-app): - 群聊 Store + API 封装 + 11 个 WS 事件监听 - 已读回执 UI(单聊已读/未读标记 + 群聊 X人已读 + 已读详情页) - 7 个群聊页面(对话/创建/设置/成员/邀请/审批/搜索) - 会话列表改造(全部/单聊/群聊 Tab + @标记 + 免打扰标识) 管理端(Vue 3 + Element Plus): - 群组列表页(搜索/分页/详情弹窗/解散群聊) - 侧边栏群组管理入口 文档同步:进度/架构/设计/API/规范文档全部更新 Made-with: Cursor
This commit is contained in:
@@ -86,13 +86,14 @@ func (d *ConversationDAO) GetUserConversations(ctx context.Context, userID int64
|
||||
err := d.db.WithContext(ctx).
|
||||
Raw(`SELECT c.id, c.type, c.last_message_id, c.last_msg_content, c.last_msg_time, c.last_msg_sender_id,
|
||||
cm.is_pinned, cm.unread_count, cm.clear_before_msg_id,
|
||||
peer.user_id AS peer_user_id
|
||||
cm.is_do_not_disturb, cm.at_me_count,
|
||||
COALESCE(peer.user_id, 0) AS peer_user_id
|
||||
FROM im_conversations c
|
||||
JOIN im_conversation_members cm ON cm.conversation_id = c.id AND cm.user_id = ?
|
||||
LEFT JOIN im_conversation_members peer ON peer.conversation_id = c.id AND peer.user_id != ?
|
||||
LEFT JOIN im_conversation_members peer ON peer.conversation_id = c.id AND peer.user_id != ? AND c.type = ?
|
||||
WHERE cm.is_deleted = false
|
||||
ORDER BY cm.is_pinned DESC, c.last_msg_time DESC NULLS LAST`,
|
||||
userID, userID).
|
||||
userID, userID, constants.ConversationTypePrivate).
|
||||
Scan(&results).Error
|
||||
|
||||
if err != nil {
|
||||
@@ -112,6 +113,8 @@ type ConversationWithMember struct {
|
||||
IsPinned bool `json:"is_pinned"`
|
||||
UnreadCount int `json:"unread_count"`
|
||||
ClearBeforeMsgID int64 `json:"clear_before_msg_id"`
|
||||
IsDoNotDisturb bool `json:"is_do_not_disturb"`
|
||||
AtMeCount int `json:"at_me_count"`
|
||||
PeerUserID int64 `json:"peer_user_id"`
|
||||
}
|
||||
|
||||
@@ -216,6 +219,44 @@ func (d *ConversationDAO) IncrementUnread(ctx context.Context, conversationID, u
|
||||
UpdateColumn("unread_count", gorm.Expr("unread_count + 1")).Error
|
||||
}
|
||||
|
||||
// IncrementAtMeCount 将指定成员的 @提醒计数 +1
|
||||
func (d *ConversationDAO) IncrementAtMeCount(ctx context.Context, conversationID, userID int64) error {
|
||||
return d.db.WithContext(ctx).
|
||||
Model(&model.ConversationMember{}).
|
||||
Where("conversation_id = ? AND user_id = ?", conversationID, userID).
|
||||
UpdateColumn("at_me_count", gorm.Expr("at_me_count + 1")).Error
|
||||
}
|
||||
|
||||
// ClearAtMeCount 清零指定成员的 @提醒计数
|
||||
func (d *ConversationDAO) ClearAtMeCount(ctx context.Context, conversationID, userID int64) error {
|
||||
return d.db.WithContext(ctx).
|
||||
Model(&model.ConversationMember{}).
|
||||
Where("conversation_id = ? AND user_id = ?", conversationID, userID).
|
||||
Update("at_me_count", 0).Error
|
||||
}
|
||||
|
||||
// GetMemberDNDMap 批量获取会话成员的免打扰状态(返回 userID → isDoNotDisturb 的映射)
|
||||
func (d *ConversationDAO) GetMemberDNDMap(ctx context.Context, conversationID int64) (map[int64]bool, error) {
|
||||
type memberDND struct {
|
||||
UserID int64 `json:"user_id"`
|
||||
IsDoNotDisturb bool `json:"is_do_not_disturb"`
|
||||
}
|
||||
var members []memberDND
|
||||
err := d.db.WithContext(ctx).
|
||||
Model(&model.ConversationMember{}).
|
||||
Select("user_id, is_do_not_disturb").
|
||||
Where("conversation_id = ?", conversationID).
|
||||
Scan(&members).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
result := make(map[int64]bool, len(members))
|
||||
for _, m := range members {
|
||||
result[m.UserID] = m.IsDoNotDisturb
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ClearUnread 清零指定成员的未读消息数
|
||||
func (d *ConversationDAO) ClearUnread(ctx context.Context, conversationID, userID int64, lastMsgID int64) error {
|
||||
return d.db.WithContext(ctx).
|
||||
|
||||
Reference in New Issue
Block a user