🐛 Fixed post visibility
This commit is contained in:
parent
ed77a443b8
commit
14f4da6c91
@ -36,13 +36,14 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
AllVisibility = models.PostVisibilityAll
|
||||||
FriendsVisibility = models.PostVisibilityFriends
|
FriendsVisibility = models.PostVisibilityFriends
|
||||||
SelectedVisibility = models.PostVisibilitySelected
|
SelectedVisibility = models.PostVisibilitySelected
|
||||||
FilteredVisibility = models.PostVisibilityFiltered
|
FilteredVisibility = models.PostVisibilityFiltered
|
||||||
)
|
)
|
||||||
|
|
||||||
type userContextState struct {
|
type userContextState struct {
|
||||||
Self uint `json:"self"`
|
Self []uint `json:"self"`
|
||||||
Allowlist []uint `json:"allow"`
|
Allowlist []uint `json:"allow"`
|
||||||
InvisibleList []uint `json:"invisible"`
|
InvisibleList []uint `json:"invisible"`
|
||||||
FollowList []uint `json:"follow"`
|
FollowList []uint `json:"follow"`
|
||||||
@ -53,8 +54,7 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
marshal := marshaler.New(cacheManager)
|
marshal := marshaler.New(cacheManager)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var allowlist, invisibleList, followList, realmList []uint
|
var self, allowlist, invisibleList, followList, realmList []uint
|
||||||
var self uint
|
|
||||||
|
|
||||||
statusCacheKey := fmt.Sprintf("post-user-context-query#%d", user.ID)
|
statusCacheKey := fmt.Sprintf("post-user-context-query#%d", user.ID)
|
||||||
statusCache, err := marshal.Get(ctx, statusCacheKey, new(userContextState))
|
statusCache, err := marshal.Get(ctx, statusCacheKey, new(userContextState))
|
||||||
@ -67,12 +67,16 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
self = state.Self
|
self = state.Self
|
||||||
} else {
|
} else {
|
||||||
// Get itself
|
// Get itself
|
||||||
var publisher models.Publisher
|
{
|
||||||
if err := database.C.Where("account_id = ?", user.ID).First(&publisher).Error; err != nil {
|
var publishers []models.Publisher
|
||||||
|
if err := database.C.Where("account_id = ?", user.ID).Find(&publishers).Error; err != nil {
|
||||||
return tx
|
return tx
|
||||||
}
|
}
|
||||||
allowlist = append(allowlist, publisher.ID)
|
self = lo.Map(publishers, func(item models.Publisher, index int) uint {
|
||||||
self = publisher.ID
|
return item.ID
|
||||||
|
})
|
||||||
|
allowlist = append(allowlist, self...)
|
||||||
|
}
|
||||||
|
|
||||||
// Getting the relationships
|
// Getting the relationships
|
||||||
userFriends, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipFriend), true)
|
userFriends, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipFriend), true)
|
||||||
@ -165,10 +169,11 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
}
|
}
|
||||||
|
|
||||||
tx = tx.Where(
|
tx = tx.Where(
|
||||||
"publisher_id = ? OR "+
|
"(publisher_id IN ? OR visibility = ? "+
|
||||||
"(visibility = ? AND publisher_id IN ?) OR "+
|
"(visibility = ? AND publisher_id IN ?) OR "+
|
||||||
"(visibility = ? AND ?) OR "+
|
"(visibility = ? AND ?) OR "+
|
||||||
"(visibility = ? AND NOT ?)",
|
"(visibility = ? AND NOT ?))",
|
||||||
|
AllVisibility,
|
||||||
self,
|
self,
|
||||||
FriendsVisibility,
|
FriendsVisibility,
|
||||||
allowlist,
|
allowlist,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user