🐛 Fix visibility issue cause by searching
This commit is contained in:
parent
e35171ab81
commit
87b6bee1f3
@ -39,10 +39,10 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
FriendsVisibility = models.PostVisibilityFriends
|
FriendsVisibility = models.PostVisibilityFriends
|
||||||
SelectedVisibility = models.PostVisibilitySelected
|
SelectedVisibility = models.PostVisibilitySelected
|
||||||
FilteredVisibility = models.PostVisibilityFiltered
|
FilteredVisibility = models.PostVisibilityFiltered
|
||||||
NoneVisibility = models.PostVisibilityNone
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type userContextState struct {
|
type userContextState struct {
|
||||||
|
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"`
|
||||||
@ -54,6 +54,7 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
var allowlist, invisibleList, followList, realmList []uint
|
var 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))
|
||||||
@ -63,7 +64,16 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
invisibleList = state.InvisibleList
|
invisibleList = state.InvisibleList
|
||||||
followList = state.FollowList
|
followList = state.FollowList
|
||||||
realmList = state.RealmList
|
realmList = state.RealmList
|
||||||
|
self = state.Self
|
||||||
} else {
|
} else {
|
||||||
|
// Get itself
|
||||||
|
var publisher models.Publisher
|
||||||
|
if err := database.C.Where("id = ?", user.ID).First(&publisher).Error; err != nil {
|
||||||
|
return tx
|
||||||
|
}
|
||||||
|
allowlist = append(allowlist, publisher.ID)
|
||||||
|
self = publisher.ID
|
||||||
|
|
||||||
// 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)
|
||||||
userGotBlocked, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipBlocked), true)
|
userGotBlocked, _ := authkit.ListRelative(gap.Nx, user.ID, int32(authm.RelationshipBlocked), true)
|
||||||
@ -147,6 +157,7 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
InvisibleList: invisibleList,
|
InvisibleList: invisibleList,
|
||||||
RealmList: realmList,
|
RealmList: realmList,
|
||||||
FollowList: followList,
|
FollowList: followList,
|
||||||
|
Self: self,
|
||||||
},
|
},
|
||||||
store.WithExpiration(2*time.Minute),
|
store.WithExpiration(2*time.Minute),
|
||||||
store.WithTags([]string{"post-user-context-query", fmt.Sprintf("user#%d", user.ID)}),
|
store.WithTags([]string{"post-user-context-query", fmt.Sprintf("user#%d", user.ID)}),
|
||||||
@ -158,7 +169,7 @@ func FilterPostWithUserContext(c *fiber.Ctx, tx *gorm.DB, user *authm.Account) *
|
|||||||
"(visibility = ? AND publisher_id IN ?) OR "+
|
"(visibility = ? AND publisher_id IN ?) OR "+
|
||||||
"(visibility = ? AND ?) OR "+
|
"(visibility = ? AND ?) OR "+
|
||||||
"(visibility = ? AND NOT ?)",
|
"(visibility = ? AND NOT ?)",
|
||||||
user.ID,
|
self,
|
||||||
FriendsVisibility,
|
FriendsVisibility,
|
||||||
allowlist,
|
allowlist,
|
||||||
SelectedVisibility,
|
SelectedVisibility,
|
||||||
@ -253,9 +264,15 @@ func FilterPostWithFuzzySearch(tx *gorm.DB, probe string) *gorm.DB {
|
|||||||
|
|
||||||
probe = "%" + probe + "%"
|
probe = "%" + probe + "%"
|
||||||
return tx.
|
return tx.
|
||||||
Where("? AND body->>'content' ILIKE ?", gorm.Expr("body ? 'content'"), probe).
|
Where(
|
||||||
Or("? AND body->>'title' ILIKE ?", gorm.Expr("body ? 'title'"), probe).
|
"(? AND body->>'content' ILIKE ? OR ? AND body->>'title' ILIKE ? OR ? AND body->>'description' ILIKE ?)",
|
||||||
Or("? AND body->>'description' ILIKE ?", gorm.Expr("body ? 'description'"), probe)
|
gorm.Expr("body ? 'content'"),
|
||||||
|
probe,
|
||||||
|
gorm.Expr("body ? 'title'"),
|
||||||
|
probe,
|
||||||
|
gorm.Expr("body ? 'description'"),
|
||||||
|
probe,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func PreloadGeneral(tx *gorm.DB) *gorm.DB {
|
func PreloadGeneral(tx *gorm.DB) *gorm.DB {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user