From 8aa627ef43525c0b5d81a26aa8acd33677bb09c8 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 10 Aug 2024 17:18:55 +0800 Subject: [PATCH] :bug: Fix visibility filter --- pkg/internal/services/posts.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pkg/internal/services/posts.go b/pkg/internal/services/posts.go index dd2ea0b..01dbd2c 100644 --- a/pkg/internal/services/posts.go +++ b/pkg/internal/services/posts.go @@ -27,10 +27,16 @@ func FilterPostWithUserContext(tx *gorm.DB, user *models.Account) *gorm.DB { ) // TODO Blocked by dealer, need support get friend list - tx = tx.Where("visibility != ? OR visibility != ?", FriendsVisibility, NoneVisibility). - Or("visibility = ? AND ?", SelectedVisibility, datatypes.JSONQuery("visible_users").HasKey(strconv.Itoa(int(user.ID)))). - Or("visibility = ? AND NOT ?", SelectedVisibility, datatypes.JSONQuery("invisible_users").HasKey(strconv.Itoa(int(user.ID)))). - Or("author_id = ?", user.ID) + tx = tx.Where( + "(visibility != ? OR visibility != ? OR (visibility = ? AND ?) OR (visibility = ? AND NOT ?) OR author_id = ?)", + FriendsVisibility, + NoneVisibility, + SelectedVisibility, + datatypes.JSONQuery("visible_users").HasKey(strconv.Itoa(int(user.ID))), + SelectedVisibility, + datatypes.JSONQuery("invisible_users").HasKey(strconv.Itoa(int(user.ID))), + user.ID, + ) return tx }