From: Matthias Schmidt Date: Sun, 27 Jul 2014 13:19:16 +0000 (+0200) Subject: Automatically delete notifications when deleting likes X-Git-Tag: 2.1.0_Alpha_1~522 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a7b665e8e383cf60e9a747e0505bd0f6fad2977c;p=GitHub%2FWoltLab%2FWCF.git Automatically delete notifications when deleting likes --- diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index 948fcfdbea..f4da8a9d88 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -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 diff --git a/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php b/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php index 63d5f65853..0688ab41e2 100644 --- a/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php @@ -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; diff --git a/wcfsetup/install/files/lib/system/like/LikeHandler.class.php b/wcfsetup/install/files/lib/system/like/LikeHandler.class.php index 5ca7a1f715..10a9277493 100644 --- a/wcfsetup/install/files/lib/system/like/LikeHandler.class.php +++ b/wcfsetup/install/files/lib/system/like/LikeHandler.class.php @@ -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 $objectIDs + * @param string $objectType + * @param array $objectIDs + * @param array $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);