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:
@ -60,3 +60,48 @@ func (r *NotificationRepo) MarkAllRead(userID uint) error {
|
||||
Where("user_id = ? AND is_read = false", userID).
|
||||
Update("is_read", true).Error
|
||||
}
|
||||
|
||||
// ListByUserAndType 按类型分页查询用户消息
|
||||
func (r *NotificationRepo) ListByUserAndType(userID uint, notifyType string, offset, limit int) ([]model.Notification, error) {
|
||||
var list []model.Notification
|
||||
err := r.db.Where("user_id = ? AND notify_type = ?", userID, notifyType).
|
||||
Order("created_at DESC").
|
||||
Offset(offset).Limit(limit).
|
||||
Find(&list).Error
|
||||
return list, err
|
||||
}
|
||||
|
||||
// CountByUserAndType 按类型统计用户消息数
|
||||
func (r *NotificationRepo) CountByUserAndType(userID uint, notifyType string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.Model(&model.Notification{}).Where("user_id = ? AND notify_type = ?", userID, notifyType).Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
// CountUnreadByType 按类型统计用户未读消息数
|
||||
func (r *NotificationRepo) CountUnreadByType(userID uint, notifyType string) (int64, error) {
|
||||
var count int64
|
||||
err := r.db.Model(&model.Notification{}).
|
||||
Where("user_id = ? AND is_read = false AND notify_type = ?", userID, notifyType).
|
||||
Count(&count).Error
|
||||
return count, err
|
||||
}
|
||||
|
||||
// GetUnnotifiedDailyLikeSummaries 获取未通知的每日点赞汇总
|
||||
func (r *NotificationRepo) GetUnnotifiedDailyLikeSummaries(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
|
||||
}
|
||||
|
||||
// MarkDailyLikeSummaryNotified 标记汇总已通知
|
||||
func (r *NotificationRepo) MarkDailyLikeSummaryNotified(id uint) error {
|
||||
return r.db.Model(&model.DailyLikeSummary{}).Where("id = ?", id).Update("notified", true).Error
|
||||
}
|
||||
|
||||
// GetUsernameByID 根据用户ID获取用户名
|
||||
func (r *NotificationRepo) GetUsernameByID(userID uint) (string, error) {
|
||||
var user model.User
|
||||
err := r.db.Select("username").First(&user, userID).Error
|
||||
return user.Username, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user