Add exceptions for spam checking
authorMarcel Werk <burntime@woltlab.com>
Tue, 27 Aug 2024 10:03:58 +0000 (12:03 +0200)
committerMarcel Werk <burntime@woltlab.com>
Tue, 27 Aug 2024 10:03:58 +0000 (12:03 +0200)
The spam check repeatedly matched even for trusted users because their IP address was listed in the SFS database.

wcfsetup/install/files/lib/system/event/listener/MessageSpamCheckingSfsListener.class.php

index 3b51d828e6faf0e475a6b6a71b9109695bbeed06..14605cc618afeec7abb163c2f58533d2c1a1307b 100644 (file)
@@ -22,13 +22,13 @@ final class MessageSpamCheckingSfsListener
             return;
         }
 
+        // Skip spam check for team members and trusted users.
         if ($event->user !== null) {
-            // Skip spam check for admins and moderators
-            $userProfile = UserProfileRuntimeCache::getInstance()->getObject($event->user->userID);
-            if (
-                $userProfile->getPermission('admin.general.canUseAcp')
-                || $userProfile->getPermission('mod.general.canUseModeration')
-            ) {
+            if ($this->isTeamMember($event->user->userID)) {
+                return;
+            }
+
+            if ($this->isTrustedUser($event->user->userID)) {
                 return;
             }
         }
@@ -41,4 +41,30 @@ final class MessageSpamCheckingSfsListener
             $event->preventDefault();
         }
     }
+
+    private function isTeamMember(int $userID): bool
+    {
+        $userProfile = UserProfileRuntimeCache::getInstance()->getObject($userID);
+        if (
+            $userProfile->getPermission('admin.general.canUseAcp')
+            || $userProfile->getPermission('mod.general.canUseModeration')
+        ) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private function isTrustedUser(int $userID): bool
+    {
+        $userProfile = UserProfileRuntimeCache::getInstance()->getObject($userID);
+        if (
+            $userProfile->activityPoints >= 100 ||
+            $userProfile->registrationDate < \TIME_NOW - 86_400 * 180
+        ) {
+            return true;
+        }
+
+        return false;
+    }
 }