Files
EchoChat/backend/go-service/app/dto/notify_dto.go
bujinyuan f1853f125d feat: Phase 2e-1 统一通知中心 + 我的 TabBar 聚合未读红点
后端(notify 模块)
- 新增 notify 模块:DAO/Service/Pusher 接口/Controller/Router/CleanupTask
- 数据库 DDL:notify_notifications 表 + 3 索引(user+created/user+is_read/user+category)
- 11 种 type 枚举(好友/群聊 9 种 + meeting_* 2 种预留)+ 4 种 category
- 跨模块集成:contact 3 处 Pusher(friend_request/accepted/rejected)
- 跨模块集成:group 6 处 Pusher(invite/join_request/approved/rejected/kicked/role_changed)
- WS handler 断线补偿:连接建立即推送 notify.unread.total
- 5 REST API(4 用户 + 1 管理员广播)+ 2 WS 事件(notify.new / notify.unread.total)
- 30 天已读通知定时清理(未读永久保留)
- Provider/Wire 依赖注入(NotifyPusher、NotifyConnectHook、UserInfoResolver 接口)

前端
- 新增 notify 模块:API/Pinia Store(5 分类分页缓存 + 未读数 + WS 事件)/NotifyItem/通知中心主页
- profile 入口:铃铛 badge + 菜单项 badge + 数字显示
- App.vue/login 初始化 notifyStore WS 监听;logout 调用 notifyStore.reset() 清缓存
- 清理 contact.js/group.js 中散落 toast 与冗余 notify.friend.request/group.join.request 处理
- CustomTabBar 新增 hasDot() 聚合指示器:我的 Tab 显示纯红点(无数字),
  当前聚合 notifyStore.unreadTotal,未来可扩展「资料待完善/安全提醒/新版本」等

文档
- 新增 Phase 2e 整体路线图 docs/plans/2026-04-20-phase2e-design.md
- 新增 Phase 2e-1 专用设计 docs/plans/2026-04-20-phase2e-1-design.md(§6.4 TabBar 聚合红点)
- 新增 Phase 2e-1 实施计划 docs/plans/2026-04-20-phase2e-1-implementation.plan.md
- 新增 E2E 验证报告 test-report-phase2e-1-notification.md(含 Playwright MCP 2 个现场 Bug 修复记录)
- 更新 docs/progress/CURRENT_STATUS.md、docs/api/README.md、docs/api/frontend/notify.md
- 更新 .cursor/rules/project-context.mdc、docs/plans/2026-02-27-echochat-system-design.md

其他
- .gitignore 排除 .playwright-mcp/ MCP 临时快照

架构决策
- 单端 WS 连接:沿用现有 ws.Hub,多端已读同步推迟到 Phase 2f/二期
- 跨模块依赖:contact/group → notify 严格单向(接口注入模式)
- 降级策略:Pusher 先入库后推送;WS 失败不回滚入库;入库失败仅 Warn 不影响业务

Playwright MCP 回归(4 类场景全通)
- 实时推送(admin 广播 → 1s 内前端自动插入 + 角标 +1)
- Deep-link 跳转(好友申请通知 → contact/request 页)
- 批量清零(全部已读按钮)
- TabBar 聚合红点(有未读亮/全部已读灭)与 notifyStore.unreadTotal 三层同步

Made-with: Cursor
2026-04-21 10:21:01 +08:00

68 lines
3.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package dto
// ====== 通知基础 DTO ======
// NotificationDTO 通知传输对象
// 前端列表渲染使用,字段顺序与 notify_notifications 一一对应
type NotificationDTO struct {
ID int64 `json:"id"` // 通知 ID
Type string `json:"type"` // 通知类型常量
Category string `json:"category"` // 前端分类friend / group / meeting / system由 type 计算得出
Title string `json:"title"` // 标题
Content string `json:"content"` // 副文案
Extra *string `json:"extra,omitempty"` // 扩展数据 JSON 字符串(前端按需解析)
ActorID *int64 `json:"actor_id,omitempty"` // 触发用户 ID
ActorName string `json:"actor_name,omitempty"` // 触发用户昵称(后端按需补全)
ActorAvatar string `json:"actor_avatar,omitempty"` // 触发用户头像
TargetType string `json:"target_type"` // 业务对象类型
TargetID *int64 `json:"target_id,omitempty"` // 业务对象 ID
IsRead bool `json:"is_read"` // 是否已读
ReadAt string `json:"read_at,omitempty"` // 已读时间(未读为空)
CreatedAt string `json:"created_at"` // 创建时间
}
// ====== REST API 请求/响应 DTO ======
// GetNotificationsRequest 通知列表查询参数
// GET /api/v1/notifications
type GetNotificationsRequest struct {
Category string `form:"category"` // 分类过滤all/friend/group/meeting/system空视为 all
IsRead *bool `form:"is_read"` // 已读状态过滤nil=全部true=已读false=未读
BeforeID int64 `form:"before_id"` // 游标分页:小于此 ID 的记录
Limit int `form:"limit"` // 页大小(默认 20最大 100
}
// NotificationListResponse 通知列表响应
type NotificationListResponse struct {
List []NotificationDTO `json:"list"` // 通知列表(按 created_at DESC 返回)
HasMore bool `json:"has_more"` // 是否还有更多数据
}
// UnreadCountResponse 未读数响应
type UnreadCountResponse struct {
Total int `json:"total"` // 未读总数
ByCategory map[string]int `json:"by_category"` // 按分类未读数friend/group/meeting/system
}
// MarkReadResponse 标记已读响应
type MarkReadResponse struct {
Affected int `json:"affected"` // 实际被标记为已读的记录数
}
// ====== 管理端广播 DTO ======
// BroadcastNotificationRequest 管理员发起系统广播请求
// POST /api/v1/admin/notifications/broadcast
type BroadcastNotificationRequest struct {
Title string `json:"title" binding:"required,max=100"` // 广播标题
Content string `json:"content" binding:"required,max=500"` // 广播正文
TargetType string `json:"target_type"` // 业务对象类型,通常为 system
TargetID *int64 `json:"target_id"` // 业务对象 ID可选
Extra *string `json:"extra"` // 扩展 JSON
}
// BroadcastNotificationResponse 广播结果响应
type BroadcastNotificationResponse struct {
Affected int `json:"affected"` // 成功入库的用户数
}