✨ Prevent blocked user see friend visible level posts
This commit is contained in:
parent
486bb69977
commit
9207a4f164
@ -41,6 +41,34 @@ func ListAccountFriends(user models.Account) ([]models.Account, error) {
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func ListAccountBlockedUsers(user models.Account) ([]models.Account, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
|
||||
defer cancel()
|
||||
|
||||
pc, err := gap.H.GetServiceGrpcConn(hyper.ServiceTypeAuthProvider)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to listing account blocked users: %v", err)
|
||||
}
|
||||
result, err := proto.NewAuthClient(pc).ListUserBlocklist(ctx, &proto.ListUserRelativeRequest{
|
||||
UserId: uint64(user.ID),
|
||||
IsRelated: true,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to listing account blocked users: %v", err)
|
||||
}
|
||||
|
||||
out := lo.Map(result.Data, func(item *proto.SimpleUserInfo, index int) uint {
|
||||
return uint(item.Id)
|
||||
})
|
||||
|
||||
var accounts []models.Account
|
||||
if err = database.C.Where("id IN ?", out).Find(&accounts).Error; err != nil {
|
||||
return nil, fmt.Errorf("failed to linking listed blocked users: %v", err)
|
||||
}
|
||||
|
||||
return accounts, nil
|
||||
}
|
||||
|
||||
func ModifyPosterVoteCount(user models.Account, isUpvote bool, delta int) error {
|
||||
if isUpvote {
|
||||
user.TotalUpvote += delta
|
||||
|
@ -32,12 +32,17 @@ func FilterPostWithUserContext(tx *gorm.DB, user *models.Account) *gorm.DB {
|
||||
friendAllowList := lo.Map(friends, func(item models.Account, index int) uint {
|
||||
return item.ID
|
||||
})
|
||||
blocked, _ := ListAccountBlockedUsers(*user)
|
||||
blockedDisallowList := lo.Map(blocked, func(item models.Account, index int) uint {
|
||||
return item.ID
|
||||
})
|
||||
|
||||
tx = tx.Where(
|
||||
"(visibility != ? OR (visibility != ? AND author_id IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR author_id = ?)",
|
||||
"(visibility != ? OR (visibility != ? AND author_id IN ? AND author_id NOT IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR author_id = ?)",
|
||||
NoneVisibility,
|
||||
FriendsVisibility,
|
||||
friendAllowList,
|
||||
blockedDisallowList,
|
||||
SelectedVisibility,
|
||||
datatypes.JSONQuery("visible_users").HasKey(strconv.Itoa(int(user.ID))),
|
||||
FilteredVisibility,
|
||||
|
Loading…
Reference in New Issue
Block a user