feat: 实现关注系统 + 通知侧边栏分类 TAB + 点赞聚合通知
- 新增关注系统:UserFollow 模型、FollowService(toggle/status/列表隐私控制) - User 新增 FollowersCount/FollowingCount/FollowListPublic/NotifyPrefs 字段 - Space 页面增加四态关注按钮(关注/已关注/回关/已互粉)+ 粉丝/关注数链接 - 新增 /space/:uid/followers 和 /space/:uid/following 列表页 - 新增 NotifyFollow/NotifyLikeAggregated 通知类型 - ReactionService 点赞时写入 daily_like_summary,访问时生成聚合通知 - FollowService 关注时触发 NotifyFollow 通知 - 消息中心侧边栏升级为分类 TAB(全部/系统通知/@艾特/点赞/关注) - NotificationService 新增 ListByCategory 按分类分页查询
This commit is contained in:
@ -75,3 +75,47 @@ func (r *ReactionRepo) IncrPostDislikes(postID uint, delta int) error {
|
||||
Where("id = ?", postID).
|
||||
UpdateColumn("dislikes_count", gorm.Expr("dislikes_count + ?", delta)).Error
|
||||
}
|
||||
|
||||
// GetPostAuthorID 查询文章作者ID
|
||||
func (r *ReactionRepo) GetPostAuthorID(postID uint) (uint, error) {
|
||||
var post model.Post
|
||||
err := r.db.Select("user_id").First(&post, postID).Error
|
||||
return post.UserID, err
|
||||
}
|
||||
|
||||
// UpsertDailyLikeSummary 追加或创建每日点赞汇总
|
||||
func (r *ReactionRepo) UpsertDailyLikeSummary(authorUID uint, date string, likerUID string) error {
|
||||
var existing model.DailyLikeSummary
|
||||
err := r.db.Where("author_uid = ? AND date = ?", authorUID, date).First(&existing).Error
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return r.db.Create(&model.DailyLikeSummary{
|
||||
AuthorUID: authorUID,
|
||||
Date: date,
|
||||
LikerUIDs: likerUID,
|
||||
Notified: false,
|
||||
}).Error
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// 追加 likerUID
|
||||
newUids := existing.LikerUIDs
|
||||
if newUids == "" {
|
||||
newUids = likerUID
|
||||
} else {
|
||||
newUids = newUids + "," + likerUID
|
||||
}
|
||||
return r.db.Model(&existing).Update("liker_uids", newUids).Error
|
||||
}
|
||||
|
||||
// GetUnnotifiedSummaries 查询未通知的每日点赞汇总
|
||||
func (r *ReactionRepo) GetUnnotifiedSummaries(userID uint) ([]model.DailyLikeSummary, error) {
|
||||
var summaries []model.DailyLikeSummary
|
||||
err := r.db.Where("author_uid = ? AND notified = ?", userID, false).Find(&summaries).Error
|
||||
return summaries, err
|
||||
}
|
||||
|
||||
// MarkSummaryNotified 标记汇总已通知
|
||||
func (r *ReactionRepo) MarkSummaryNotified(id uint) error {
|
||||
return r.db.Model(&model.DailyLikeSummary{}).Where("id = ?", id).Update("notified", true).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user