Suppress notifications triggered by blocked users
authorAlexander Ebert <ebert@woltlab.com>
Wed, 1 Mar 2017 12:43:40 +0000 (13:43 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 1 Mar 2017 12:43:40 +0000 (13:43 +0100)
Closes #2201

wcfsetup/install/files/lib/system/user/notification/UserNotificationHandler.class.php

index 0a8a9aacf1bbc2b1b545d0aab445054aa244626a..f72f8089672919465ed065df15d9843659fcf1dd 100644 (file)
@@ -189,6 +189,34 @@ class UserNotificationHandler extends SingletonFactory {
                        return;
                }
                
+               // remove recipients that are blocking the current user
+               if ($userProfile->getUserID()) {
+                       // we use a live query here to avoid offloading this to the UserProfile
+                       // class, as we're potentially dealing with a lot of users and loading
+                       // their user storage data can get really expensive
+                       $conditions = new PreparedStatementConditionBuilder();
+                       $conditions->add("userID IN (?)", [$recipientIDs]);
+                       $conditions->add("ignoreUserID = ?", [$userProfile->getUserID()]);
+                       
+                       $sql = "SELECT  userID
+                               FROM    wcf" . WCF_N . "_user_ignore
+                               ".$conditions;
+                       $statement = WCF::getDB()->prepareStatement($sql);
+                       $statement->execute($conditions->getParameters());
+                       $userIDs = [];
+                       while ($userID = $statement->fetchColumn()) {
+                               $userIDs[] = $userID;
+                       }
+                       
+                       if (!empty($userIDs)) {
+                               $recipientIDs = array_diff($recipientIDs, $userIDs);
+                       }
+                       
+                       if (empty($recipientIDs)) {
+                               return;
+                       }
+               }
+               
                // get recipients
                $recipientList = new UserNotificationEventRecipientList();
                $recipientList->getConditionBuilder()->add('event_to_user.eventID = ?', [$event->eventID]);