commit 6045630f3318e95b44ff199f0e45b640badf570e
parent a9d5019ad44faa3089507fe49dd2238c298b79ac
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 24 May 2023 23:41:28 -0700
cleanup
Diffstat:
1 file changed, 25 insertions(+), 15 deletions(-)
diff --git a/pkg/web/handlers/handlers.go b/pkg/web/handlers/handlers.go
@@ -4994,6 +4994,30 @@ func manualPreload(db *database.DkfDB, msg *database.ChatMessage) {
}
}
+// Return true if the message passes all the user's filter.
+// false if the message does not and should be discarded.
+func applyUserFilters(db *database.DkfDB, authUser *database.User, msg *database.ChatMessage,
+ pmOnlyQuery database.PmDisplayMode, displayHellbanned, mentionsOnlyQuery bool) bool {
+ if (pmOnlyQuery == database.PmOnly && msg.ToUser == nil) ||
+ (pmOnlyQuery == database.PmNone && msg.ToUser != nil) ||
+ !authUser.DisplayModerators && msg.Moderators ||
+ !displayHellbanned && msg.IsHellbanned {
+ return false
+ }
+
+ if !authUser.DisplayIgnored {
+ ignoredUsers, _ := db.GetIgnoredUsersUsernames(authUser.ID)
+ if utils.InArr(msg.User.Username, ignoredUsers) {
+ return false
+ }
+ }
+
+ if mentionsOnlyQuery && !strings.Contains(msg.Message, "@"+authUser.Username) {
+ return false
+ }
+ return true
+}
+
func ChatStreamMessagesHandler(c echo.Context) error {
db := c.Get("database").(*database.DkfDB)
authUser := c.Get("authUser").(*database.User)
@@ -5114,21 +5138,7 @@ Loop:
manualPreload(db, msg)
- if (pmOnlyQuery == database.PmOnly && msg.ToUser == nil) ||
- (pmOnlyQuery == database.PmNone && msg.ToUser != nil) ||
- !authUser.DisplayModerators && msg.Moderators ||
- !displayHellbanned && msg.IsHellbanned {
- continue
- }
-
- if !authUser.DisplayIgnored {
- ignoredUsers, _ := db.GetIgnoredUsersUsernames(authUser.ID)
- if utils.InArr(msg.User.Username, ignoredUsers) {
- continue
- }
- }
-
- if mentionsOnlyQuery && !strings.Contains(msg.Message, "@"+authUser.Username) {
+ if !applyUserFilters(db, authUser, msg, pmOnlyQuery, displayHellbanned, mentionsOnlyQuery) {
continue
}