From: Matthias Schmidt Date: Sun, 27 Jan 2019 11:26:10 +0000 (+0100) Subject: Mark comment (response) notifications as read when loaded via AJAX X-Git-Tag: 5.2.0_Alpha_1~345 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=434fee8c5b4e34feb54ef51ee3dabc4c53bdfddf;p=GitHub%2FWoltLab%2FWCF.git Mark comment (response) notifications as read when loaded via AJAX Close #2835 --- diff --git a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php index a759a66f01..bff123c305 100644 --- a/wcfsetup/install/files/lib/data/comment/CommentAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/CommentAction.class.php @@ -198,6 +198,12 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli $commentList->getConditionBuilder()->add("comment.time < ?", [$this->parameters['data']['lastCommentTime']]); $commentList->readObjects(); + // mark notifications for loaded comments as read + CommentHandler::getInstance()->markNotificationsAsConfirmedForComments( + CommentHandler::getInstance()->getObjectType($this->parameters['data']['objectTypeID'])->objectType, + $commentList->getObjects() + ); + WCF::getTPL()->assign([ 'commentList' => $commentList, 'likeData' => MODULE_LIKE ? $commentList->getLikeData() : [] @@ -252,6 +258,21 @@ class CommentAction extends AbstractDatabaseObjectAction implements IMessageInli return ['template' => '']; } + // mark notifications for loaded comment/response as read + $objectType = CommentHandler::getInstance()->getObjectType($this->parameters['data']['objectTypeID'])->objectType; + if ($this->response === null) { + CommentHandler::getInstance()->markNotificationsAsConfirmedForComments( + $objectType, + [new StructuredComment($this->comment)] + ); + } + else { + CommentHandler::getInstance()->markNotificationsAsConfirmedForResponses( + $objectType, + [$this->response] + ); + } + $returnValues = $this->renderComment($this->comment, $this->response); return (is_array($returnValues)) ? $returnValues : ['template' => $returnValues]; } 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 0077a00ba3..0e63c61bc3 100644 --- a/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php +++ b/wcfsetup/install/files/lib/data/comment/response/CommentResponseAction.class.php @@ -207,6 +207,12 @@ class CommentResponseAction extends AbstractDatabaseObjectAction { $lastResponseTime = max($lastResponseTime, $response->time); } + // mark notifications for loaded responses as read + CommentHandler::getInstance()->markNotificationsAsConfirmedForResponses( + CommentHandler::getInstance()->getObjectType($this->comment->objectTypeID)->objectType, + $responseList->getObjects() + ); + WCF::getTPL()->assign([ 'commentCanModerate' => $commentCanModerate, 'likeData' => MODULE_LIKE ? $responseList->getLikeData() : [], diff --git a/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php b/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php index 7fd43c0b69..07f1313d59 100644 --- a/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php +++ b/wcfsetup/install/files/lib/system/comment/CommentHandler.class.php @@ -1,9 +1,10 @@ getObjectTypeID($objectType) === null) { throw new \InvalidArgumentException("Unknown comment object type '{$objectType}'."); } - if (count($commentList) === 0) { + if (count($comments) === 0) { return; } + $commentIDs = []; + foreach ($comments as $comment) { + $commentIDs[] = $comment->commentID; + } + // 1. comments // mark comment notifications as confirmed @@ -474,7 +480,7 @@ class CommentHandler extends SingletonFactory { $eventData['eventName'], $eventData['objectType'], [WCF::getUser()->userID], - $commentList->getObjectIDs() + $commentIDs ); } } @@ -496,7 +502,7 @@ class CommentHandler extends SingletonFactory { $notificationList = new UserNotificationList(); $notificationList->getConditionBuilder()->add('user_notification.eventID IN (?)', [array_keys($reactionCommentEvents)]); $notificationList->getConditionBuilder()->add('user_notification.userID = ?', [WCF::getUser()->userID]); - $notificationList->getConditionBuilder()->add('user_notification.baseObjectID IN (?)', [$commentList->getObjectIDs()]); + $notificationList->getConditionBuilder()->add('user_notification.baseObjectID IN (?)', [$commentIDs]); $notificationList->readObjects(); $objectIDs = []; @@ -523,7 +529,7 @@ class CommentHandler extends SingletonFactory { // 2. responses $responseIDs = []; - foreach ($commentList as $comment) { + foreach ($comments as $comment) { // as we do not know whether `Comment::getUnfilteredResponseIDs()` // or `Comment::getResponseIDs()` has been used, collect response // ids manually @@ -602,21 +608,26 @@ class CommentHandler extends SingletonFactory { * Marks all comment response-related notifications for objects of the given object type in * the given comment response list as confirmed for the active user. * - * @param string $objectType comment object type name - * @param StructuredCommentResponseList $responseList comment responses whose notifications will be marked as read + * @param string $objectType comment object type name + * @param CommentResponse[] $responses comment responses whose notifications will be marked as read * * @throws \InvalidArgumentException if invalid comment object type name is given * @since 5.2 */ - public function markNotificationsAsConfirmedForResponseList($objectType, StructuredCommentResponseList $responseList) { + public function markNotificationsAsConfirmedForResponses($objectType, array $responses) { if ($this->getObjectTypeID($objectType) === null) { throw new \InvalidArgumentException("Unknown comment object type '{$objectType}'."); } - if (count($responseList) === 0) { + if (count($responses) === 0) { return; } + $responseIDs = []; + foreach ($responses as $response) { + $responseIDs[] = $response->responseID; + } + $responseEvents = []; if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType.'.response.notification')) { foreach (UserNotificationHandler::getInstance()->getEvents($objectType . '.response.notification') as $event) { @@ -633,7 +644,7 @@ class CommentHandler extends SingletonFactory { $eventData['eventName'], $eventData['objectType'], [WCF::getUser()->userID], - $responseList->getObjectIDs() + $responseIDs ); } } @@ -655,7 +666,7 @@ class CommentHandler extends SingletonFactory { $notificationList = new UserNotificationList(); $notificationList->getConditionBuilder()->add('user_notification.eventID IN (?)', [array_keys($reactionResponseEvents)]); $notificationList->getConditionBuilder()->add('user_notification.userID = ?', [WCF::getUser()->userID]); - $notificationList->getConditionBuilder()->add('user_notification.baseObjectID IN (?)', [$responseList->getObjectIDs()]); + $notificationList->getConditionBuilder()->add('user_notification.baseObjectID IN (?)', [$responseIDs]); $notificationList->readObjects(); $objectIDs = [];