Automatically delete notifications when deleting likes
authorMatthias Schmidt <gravatronics@live.com>
Sun, 27 Jul 2014 13:19:16 +0000 (15:19 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 27 Jul 2014 13:19:16 +0000 (15:19 +0200)
wcfsetup/install/files/lib/data/comment/CommentAction.class.php
wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php
wcfsetup/install/files/lib/system/like/LikeHandler.class.php

index 948fcfdbea93630f2745550ac56e96b33216c26a..f4da8a9d88275472ec96dfeaea9a852b34909855 100644 (file)
@@ -111,6 +111,7 @@ class CommentAction extends AbstractDatabaseObjectAction {
                
                if (!empty($groupCommentIDs)) {
                        $likeObjectIDs = array();
+                       $notificationObjectTypes = array();
                        foreach ($groupCommentIDs as $objectTypeID => $objectIDs) {
                                // remove activity events
                                $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
@@ -125,10 +126,14 @@ class CommentAction extends AbstractDatabaseObjectAction {
                                if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.notification')) {
                                        UserNotificationHandler::getInstance()->deleteNotifications('comment', $objectType->objectType.'.notification', array(), $objectIDs);
                                }
+                               
+                               if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.like.notification')) {
+                                       $notificationObjectTypes[] = $objectType->objectType.'.like.notification';
+                               }
                        }
                        
                        // remove likes
-                       LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $likeObjectIDs);
+                       LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $likeObjectIDs, $notificationObjectTypes);
                }
                
                // delete responses
index 63d5f65853b04f2a886a2fd894191ce926c64a18..0688ab41e2d5cfc49d9fe8151f911677d45befad 100644 (file)
@@ -108,6 +108,7 @@ class CommentResponseAction extends AbstractDatabaseObjectAction {
                }
                
                $likeObjectIDs = array();
+               $notificationObjectTypes = array();
                foreach ($responseIDs as $objectTypeID => $objectIDs) {
                        // remove activity events
                        $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
@@ -122,11 +123,15 @@ class CommentResponseAction extends AbstractDatabaseObjectAction {
                        }
                        
                        $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs);
+                       
+                       if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType.'.response.like.notification')) {
+                               $notificationObjectTypes[] = $objectType->objectType.'.response.like.notification';
+                       }
                }
                
                // remove likes
                if (!empty($likeObjectIDs)) {
-                       LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $likeObjectIDs);
+                       LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $likeObjectIDs, $notificationObjectTypes);
                }
                
                return $count;
index 5ca7a1f715429a2e2a718d66e448f7190caf1202..10a92774934b238a5a5fc1169ed4744b2281fd38 100644 (file)
@@ -15,6 +15,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\database\DatabaseException;
 use wcf\system\user\activity\event\UserActivityEventHandler;
 use wcf\system\user\activity\point\UserActivityPointHandler;
+use wcf\system\user\notification\UserNotificationHandler;
 use wcf\system\SingletonFactory;
 use wcf\system\WCF;
 
@@ -417,10 +418,11 @@ class LikeHandler extends SingletonFactory {
        /**
         * Removes all likes for given objects.
         * 
-        * @param       string          $objectType
-        * @param       array<integer>  $objectIDs
+        * @param       string                  $objectType
+        * @param       array<integer>          $objectIDs
+        * @param       array<string>           $notificationObjectTypes
         */
-       public function removeLikes($objectType, array $objectIDs) {
+       public function removeLikes($objectType, array $objectIDs, array $notificationObjectTypes = array()) {
                $objectTypeObj = $this->getObjectType($objectType);
                
                // get like objects
@@ -458,6 +460,16 @@ class LikeHandler extends SingletonFactory {
                                $likeData[$like->likeID] = $like->userID;
                        }
                        
+                       // delete like notifications
+                       if (!empty($notificationObjectTypes)) {
+                               foreach ($notificationObjectTypes as $notificationObjectType) {
+                                       UserNotificationHandler::getInstance()->removeNotifications($notificationObjectType, $likeList->getObjectIDs());
+                               }
+                       }
+                       else if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType.'.notification')) {
+                               UserNotificationHandler::getInstance()->removeNotifications($objectType.'.notification', $likeList->getObjectIDs());
+                       }
+                       
                        // revoke activity points
                        UserActivityPointHandler::getInstance()->removeEvents('com.woltlab.wcf.like.activityPointEvent.receivedLikes', $likeData);