feat: 实时消息与管理端运营能力

新增群聊/私信与公共 WebSocket 总线,站长用户内容档案,并将通知与待审角标改为推送驱动;同步精简管理仪表盘并修复主题换肤 DOM 冲突。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-09-15 22:58:16 +08:00
parent 29db9ae9b5
commit 42c395a864
55 changed files with 7607 additions and 346 deletions

View File

@@ -169,27 +169,32 @@ type Checkin struct {
// 通知类型
const (
NotificationTypeComment = "comment" // 评论了你的帖子
NotificationTypeReply = "reply" // 回复了你的评论
NotificationTypeLike = "like" // 点赞了你的帖子
NotificationTypeApproved = "approved" // 内容审核通过
NotificationTypeRejected = "rejected" // 内容审核未通过
NotificationTypeComment = "comment" // 评论了你的帖子
NotificationTypeReply = "reply" // 回复了你的评论
NotificationTypeLike = "like" // 点赞了你的帖子
NotificationTypeApproved = "approved" // 内容审核通过
NotificationTypeRejected = "rejected" // 内容审核未通过
NotificationTypeMention = "mention" // 群聊中 @ 了你(PostID=0,用 RoomID/MessageID)
NotificationTypePendingReview = "pending_review" // 有新内容待审核(发给可审者)
)
// Notification 站内通知
type Notification struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `gorm:"index;not null" json:"user_id"` // 接收通知的用户
ActorID uint `gorm:"not null" json:"actor_id"` // 触发通知的用户
Type string `gorm:"size:16;not null;index" json:"type"` // comment | like
PostID uint `gorm:"index;not null" json:"post_id"` // 关联帖子
CommentID uint `gorm:"index" json:"comment_id"` // 关联评论(点赞时为 0)
Content string `gorm:"size:256" json:"content"` // 内容预览
UserID uint `gorm:"index;not null" json:"user_id"` // 接收通知的用户
ActorID uint `gorm:"not null" json:"actor_id"` // 触发通知的用户
Type string `gorm:"size:16;not null;index" json:"type"` // comment | like | mention ...
PostID uint `gorm:"index;not null;default:0" json:"post_id"` // 关联帖子(mention 类为 0)
CommentID uint `gorm:"index" json:"comment_id"` // 关联评论(点赞时为 0)
RoomID uint `gorm:"index;not null;default:0" json:"room_id"` // 关联群聊(mention)
MessageID uint `gorm:"not null;default:0" json:"message_id"` // 关联群聊消息(mention)
Content string `gorm:"size:256" json:"content"` // 内容预览
IsRead bool `gorm:"default:false;index" json:"is_read"`
CreatedAt time.Time `json:"created_at"`
Actor User `gorm:"foreignKey:ActorID" json:"actor,omitempty"`
Post Post `gorm:"foreignKey:PostID" json:"post,omitempty"`
Actor User `gorm:"foreignKey:ActorID" json:"actor,omitempty"`
Post Post `gorm:"foreignKey:PostID" json:"post,omitempty"`
Room *ChatRoom `gorm:"foreignKey:RoomID;constraint:-" json:"room,omitempty"`
}
// Announcement 站点公告(后台文章管理:支持草稿、标签与标签预设色)
@@ -252,3 +257,66 @@ type LoginLog struct {
Success bool `gorm:"index;not null;default:false" json:"success"`
CreatedAt time.Time `gorm:"index" json:"created_at"`
}
// 群聊成员角色
const (
ChatRoleOwner = "owner" // 群主(建群者,每群唯一):改名/解散/踢人/禁言
ChatRoleMember = "member" // 普通成员
)
// ChatRoom 会话房间:群聊或一对一私聊(RoomType);IsDefault 为全站大厅
type ChatRoom struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"size:64;not null;default:''" json:"name"`
Description string `gorm:"size:256;not null;default:''" json:"description"`
OwnerID uint `gorm:"index;not null" json:"owner_id"`
RoomType string `gorm:"size:16;not null;default:group;index" json:"room_type"` // group | direct
DirectKey string `gorm:"size:64;not null;default:'';index" json:"-"` // 私聊双方 ID 排序键 "min:max"
IsPrivate bool `gorm:"not null;default:false;index" json:"is_private"`
IsDefault bool `gorm:"not null;default:false;index" json:"is_default"`
MemberCount int `gorm:"not null;default:0" json:"member_count"`
LastMessageID uint `gorm:"index;not null;default:0" json:"last_message_id"` // 最后一条消息(列表排序/未读基准)
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Owner User `gorm:"foreignKey:OwnerID" json:"owner,omitempty"`
LastMessage *ChatMessage `gorm:"foreignKey:LastMessageID;constraint:-" json:"last_message,omitempty"`
}
const (
ChatRoomTypeGroup = "group"
ChatRoomTypeDirect = "direct"
)
// ChatRoomMember 群成员(房间+用户联合唯一;LastReadMessageID 为未读对账水位)
type ChatRoomMember struct {
ID uint `gorm:"primaryKey" json:"id"`
RoomID uint `gorm:"uniqueIndex:idx_chat_member;index;not null" json:"room_id"`
UserID uint `gorm:"uniqueIndex:idx_chat_member;not null" json:"user_id"`
Role string `gorm:"size:16;not null;default:member" json:"role"`
LastReadMessageID uint `gorm:"not null;default:0" json:"last_read_message_id"`
Muted bool `gorm:"not null;default:false" json:"muted"` // 被群主禁言
PinnedAt *time.Time `json:"pinned_at,omitempty"` // 该用户个人置顶时间;大厅强制置顶不依赖此字段
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
User User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}
// ChatMessage 群聊消息(先落库再经 WS 广播,WS 不承担可靠投递;撤回保留行供审计)
type ChatMessage struct {
ID uint `gorm:"primaryKey" json:"id"`
RoomID uint `gorm:"index:idx_chat_room_created,priority:1;not null" json:"room_id"`
SenderID uint `gorm:"index;not null" json:"sender_id"`
Content string `gorm:"type:varchar(2000);not null" json:"content"`
ReplyToID uint `gorm:"not null;default:0;index" json:"reply_to_id"` // 引用的消息 ID,0 表示无引用
ReplySnap string `gorm:"size:512;not null;default:''" json:"reply_snap"` // 引用快照「昵称: 摘要」,原文撤回后仍可展示
MentionIDs string `gorm:"size:512;not null;default:''" json:"-"` // 被@用户 ID 逗号分隔(落通知用)
RecalledAt *time.Time `json:"recalled_at,omitempty"`
RecalledBy uint `gorm:"not null;default:0" json:"recalled_by"`
CreatedAt time.Time `gorm:"index:idx_chat_room_created,priority:2" json:"created_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Sender User `gorm:"foreignKey:SenderID" json:"sender,omitempty"`
}