feat: @提及支持改名后链接跟随UID + 显示名自动更新
- comment_mentions新增original_username列,创建时记录原始@用户名
- Mentions map改为{original_username: {uid, name}}结构,name为当前显示名
- 用户改名后:旧@文本仍能匹配original_username,链接跟随uid不变,显示名自动更新
- 前端renderMentions适配新结构
This commit is contained in:
@ -25,16 +25,23 @@ type Comment struct {
|
||||
ReplyToName string `gorm:"-:migration;<-:false" json:"reply_to_name,omitempty"`
|
||||
// RepliesCount 回复数(非DB字段,查询填充)
|
||||
RepliesCount int `gorm:"-:migration;<-:false" json:"replies_count,omitempty"`
|
||||
// Mentions 有效@提及映射 username -> uid(非DB字段,批量查询填充)
|
||||
// 前端据此判断 @username 是否为有效提及并生成链接
|
||||
Mentions map[string]uint `gorm:"-" json:"mentions,omitempty"`
|
||||
// Mentions 有效@提及映射 original_username -> {uid, 当前显示名}(非DB字段,批量查询填充)
|
||||
// key=创建时的原始@用户名,value={uid,当前显示名},用户改名后链接仍有效且显示新名
|
||||
Mentions map[string]MentionInfo `gorm:"-" json:"mentions,omitempty"`
|
||||
}
|
||||
|
||||
// CommentMention @提及映射(绑定UID,不是username,支持改名后自动更新显示名)
|
||||
// CommentMention @提及映射(绑定UID + 原始用户名,支持改名后自动更新显示名)
|
||||
type CommentMention struct {
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CommentID uint `gorm:"uniqueIndex:idx_comment_uid,priority:1;not null" json:"comment_id"`
|
||||
UID uint `gorm:"uniqueIndex:idx_comment_uid,priority:2;not null" json:"uid"`
|
||||
ID uint `gorm:"primarykey" json:"id"`
|
||||
CommentID uint `gorm:"uniqueIndex:idx_comment_uid,priority:1;not null" json:"comment_id"`
|
||||
UID uint `gorm:"uniqueIndex:idx_comment_uid,priority:2;not null" json:"uid"`
|
||||
OriginalUsername string `gorm:"type:varchar(64);not null;default:''" json:"original_username"`
|
||||
}
|
||||
|
||||
// MentionInfo @提及显示信息(前端渲染用)
|
||||
type MentionInfo struct {
|
||||
UID uint `json:"uid"`
|
||||
Name string `json:"name"` // 当前显示名
|
||||
}
|
||||
|
||||
// UserSearchResult @搜索用户结果
|
||||
|
||||
Reference in New Issue
Block a user