feat(posts): filter posts by blocked users
All checks were successful
Build Backend / build (push) Successful in 2m49s
Build Backend / build-docker (push) Successful in 1m19s

Add functionality to filter out posts from blocked users in post listing endpoints. Includes a new `IsBlockedBatch` method for efficient batch checking of blocked relationships and `is_blocked` field in API responses when viewing a blocked user's posts.
This commit is contained in:
lafay
2026-04-25 11:25:43 +08:00
parent 323f872aa9
commit e0f34653a2
5 changed files with 82 additions and 2 deletions

View File

@@ -482,6 +482,7 @@ func (s *pushServiceImpl) pushSystemNotificationViaWebSocket(ctx context.Context
"type": string(notification.Type),
"title": notification.Title,
"content": notification.Content,
"is_read": notification.IsRead,
"extra": map[string]any{},
"created_at": notification.CreatedAt.Format("2006-01-02T15:04:05Z07:00"),
}

View File

@@ -53,6 +53,7 @@ type UserService interface {
UnblockUser(ctx context.Context, blockerID, blockedID string) error
GetBlockedUsers(ctx context.Context, blockerID string, page, pageSize int) ([]*model.User, int64, error)
IsBlocked(ctx context.Context, blockerID, blockedID string) (bool, error)
IsBlockedBatch(ctx context.Context, blockerID string, blockedIDs []string) (map[string]bool, error)
// 隐私设置
GetPrivacySettings(ctx context.Context, userID string) (*model.PrivacySettings, error)
@@ -583,6 +584,11 @@ func (s *userServiceImpl) IsBlocked(ctx context.Context, blockerID, blockedID st
return s.userRepo.IsBlocked(blockerID, blockedID)
}
// IsBlockedBatch 批量检查拉黑关系
func (s *userServiceImpl) IsBlockedBatch(ctx context.Context, blockerID string, blockedIDs []string) (map[string]bool, error) {
return s.userRepo.IsBlockedBatch(blockerID, blockedIDs)
}
// GetFollowingList 获取关注列表(字符串参数版本)
func (s *userServiceImpl) GetFollowingList(ctx context.Context, userID, page, pageSize string) ([]*model.User, error) {
// 转换字符串参数为整数