♻️ Refactored user context visibility filter
This commit is contained in:
parent
d2ffde8469
commit
8d1db481de
@ -32,17 +32,38 @@ func FilterPostWithUserContext(tx *gorm.DB, user *authm.Account) *gorm.DB {
|
|||||||
NoneVisibility = models.PostVisibilityNone
|
NoneVisibility = models.PostVisibilityNone
|
||||||
)
|
)
|
||||||
|
|
||||||
friends, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipFriend), true)
|
userFriends, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipFriend), true)
|
||||||
allowlist := lo.Map(friends, func(item *proto.UserInfo, index int) uint {
|
userBlocked, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipBlocked), true)
|
||||||
|
userFriendList := lo.Map(userFriends, func(item *proto.UserInfo, index int) uint {
|
||||||
return uint(item.GetId())
|
return uint(item.GetId())
|
||||||
})
|
})
|
||||||
blocked, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipBlocked), true)
|
userBlockList := lo.Map(userBlocked, func(item *proto.UserInfo, index int) uint {
|
||||||
blocklist := lo.Map(blocked, func(item *proto.UserInfo, index int) uint {
|
|
||||||
return uint(item.GetId())
|
return uint(item.GetId())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Query the publishers according to the user's relationship
|
||||||
|
var publishers []models.Publisher
|
||||||
|
database.C.Where(
|
||||||
|
"id IN ? AND type = ?",
|
||||||
|
append(userFriendList, userBlockList...),
|
||||||
|
models.PublisherTypePersonal,
|
||||||
|
).Find(&publishers)
|
||||||
|
|
||||||
|
allowlist := lo.Filter(publishers, func(item models.Publisher, index int) bool {
|
||||||
|
if item.AccountID == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return lo.Contains(userFriendList, *item.AccountID)
|
||||||
|
})
|
||||||
|
blocklist := lo.Filter(publishers, func(item models.Publisher, index int) bool {
|
||||||
|
if item.AccountID == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return lo.Contains(userBlockList, *item.AccountID)
|
||||||
|
})
|
||||||
|
|
||||||
tx = tx.Where(
|
tx = tx.Where(
|
||||||
"(visibility != ? OR (visibility != ? AND publisher_id IN ? AND publisher_id NOT IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR publisher_id = ?)",
|
"(visibility != ? OR (visibility = ? AND publisher_id IN ? AND publisher_id NOT IN ?) OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR publisher_id = ?)",
|
||||||
NoneVisibility,
|
NoneVisibility,
|
||||||
FriendsVisibility,
|
FriendsVisibility,
|
||||||
allowlist,
|
allowlist,
|
||||||
|
Loading…
Reference in New Issue
Block a user