From 30394f983d88da24dd758e4552985c6e927b6537 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Tue, 25 Apr 2023 16:06:04 +0200 Subject: [PATCH] Add default implementation for user notifications about comments --- .../AbstractModerationQueueHandler.class.php | 14 ++++ .../queue/IModerationQueueHandler.class.php | 9 +++ ...ractCommentUserNotificationEvent.class.php | 72 +++++++++++++++++++ ...icleCommentUserNotificationEvent.class.php | 36 ++++------ ...ueueCommentUserNotificationEvent.class.php | 41 ++++++----- ...PageCommentUserNotificationEvent.class.php | 35 +++------ ...fileCommentUserNotificationEvent.class.php | 36 ++++------ wcfsetup/install/lang/de.xml | 15 +--- wcfsetup/install/lang/en.xml | 15 +--- 9 files changed, 161 insertions(+), 112 deletions(-) create mode 100644 wcfsetup/install/files/lib/system/user/notification/event/AbstractCommentUserNotificationEvent.class.php diff --git a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php index 351ee14e47..9953f1a244 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/AbstractModerationQueueHandler.class.php @@ -140,4 +140,18 @@ abstract class AbstractModerationQueueHandler implements IModerationQueueHandler return 'wcf.moderation.notification'; } + + /** + * @inheritDoc + */ + public function getCommentNotificationTypeNameLanguageItem(): string + { + if ($this instanceof IModerationQueueActivationHandler) { + return 'wcf.moderation.activation'; + } elseif ($this instanceof IModerationQueueReportHandler) { + return 'wcf.moderation.report'; + } + + return 'wcf.moderation.moderation'; + } } diff --git a/wcfsetup/install/files/lib/system/moderation/queue/IModerationQueueHandler.class.php b/wcfsetup/install/files/lib/system/moderation/queue/IModerationQueueHandler.class.php index 2881255be6..70f83ae238 100644 --- a/wcfsetup/install/files/lib/system/moderation/queue/IModerationQueueHandler.class.php +++ b/wcfsetup/install/files/lib/system/moderation/queue/IModerationQueueHandler.class.php @@ -94,4 +94,13 @@ interface IModerationQueueHandler * @since 3.0 */ public function getCommentNotificationLanguageItemPrefix(); + + /** + * Returns the language item for the type name for notifications for comments + * and comment responses on moderation queues of this type. + * + * @return string + * @since 6.0 + */ + public function getCommentNotificationTypeNameLanguageItem(): string; } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/AbstractCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/AbstractCommentUserNotificationEvent.class.php new file mode 100644 index 0000000000..7f1c57761e --- /dev/null +++ b/wcfsetup/install/files/lib/system/user/notification/event/AbstractCommentUserNotificationEvent.class.php @@ -0,0 +1,72 @@ + + * @since 6.0 + */ +abstract class AbstractCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent +{ + /** + * @inheritDoc + */ + protected $stackable = true; + + /** + * @inheritDoc + */ + public function getTitle(): string + { + $count = \count($this->getAuthors()); + if ($count > 1) { + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.title.stacked', [ + 'count' => $count, + 'timesTriggered' => $this->notification->timesTriggered, + 'typeName' => $this->getTypeName(), + ]); + } + + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.title', [ + 'typeName' => $this->getTypeName(), + ]); + } + + /** + * @inheritDoc + */ + public function getEmailTitle() + { + $count = \count($this->getAuthors()); + if ($count > 1) { + return $this->getTitle(); + } + + return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.mail.title', [ + 'objectTitle' => $this->getObjectTitle(), + 'typeName' => $this->getTypeName(), + ]); + } + + /** + * @inheritDoc + */ + public function getEventHash() + { + return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID); + } + + /** + * Returns the name of the type to which the comment belong. + */ + protected abstract function getTypeName(): string; + + /** + * Returns the title of the object to which the comment belong. + */ + protected abstract function getObjectTitle(): string; +} diff --git a/wcfsetup/install/files/lib/system/user/notification/event/ArticleCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/ArticleCommentUserNotificationEvent.class.php index 7508ee196e..1c7fe13741 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/ArticleCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/ArticleCommentUserNotificationEvent.class.php @@ -15,17 +15,12 @@ use wcf\system\user\notification\object\CommentUserNotificationObject; * * @method CommentUserNotificationObject getUserNotificationObject() */ -class ArticleCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements +class ArticleCommentUserNotificationEvent extends AbstractCommentUserNotificationEvent implements ITestableUserNotificationEvent { use TTestableCommentUserNotificationEvent; use TTestableArticleCommentUserNotificationEvent; - /** - * @inheritDoc - */ - protected $stackable = true; - /** * @inheritDoc */ @@ -34,22 +29,6 @@ class ArticleCommentUserNotificationEvent extends AbstractSharedUserNotification ViewableArticleContentRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID); } - /** - * @inheritDoc - */ - public function getTitle(): string - { - $count = \count($this->getAuthors()); - if ($count > 1) { - return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.title.stacked', [ - 'count' => $count, - 'timesTriggered' => $this->notification->timesTriggered, - ]); - } - - return $this->getLanguage()->getDynamicVariable('wcf.user.notification.articleComment.title'); - } - /** * @inheritDoc */ @@ -111,8 +90,17 @@ class ArticleCommentUserNotificationEvent extends AbstractSharedUserNotification /** * @inheritDoc */ - public function getEventHash() + protected function getTypeName(): string + { + return $this->getLanguage()->get('wcf.user.recentActivity.com.woltlab.wcf.article.recentActivityEvent'); + } + + /** + * @inheritDoc + */ + protected function getObjectTitle(): string { - return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID); + return ViewableArticleContentRuntimeCache::getInstance() + ->getObject($this->getUserNotificationObject()->objectID)->getTitle(); } } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentUserNotificationEvent.class.php index 1ccd4a9ca8..17a5666750 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/ModerationQueueCommentUserNotificationEvent.class.php @@ -23,7 +23,7 @@ use wcf\system\WCF; * * @method CommentUserNotificationObject getUserNotificationObject() */ -class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificationEvent implements +class ModerationQueueCommentUserNotificationEvent extends AbstractCommentUserNotificationEvent implements ITestableUserNotificationEvent { use TTestableCommentUserNotificationEvent; @@ -36,15 +36,16 @@ class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificati protected $languageItemPrefix = ''; /** - * moderation queue object the notifications (indirectly) belong to - * @var ViewableModerationQueue + * language item for the type name + * @var string */ - protected $moderationQueue; + protected $typeName = ''; /** - * @inheritDoc + * moderation queue object the notifications (indirectly) belong to + * @var ViewableModerationQueue */ - protected $stackable = true; + protected $moderationQueue; /** * @inheritDoc @@ -124,17 +125,8 @@ class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificati /** * @inheritDoc */ - public function getTitle(): string + protected function prepare() { - $count = \count($this->getAuthors()); - if ($count > 1) { - return $this->getLanguage()->getDynamicVariable($this->languageItemPrefix . '.comment.title.stacked', [ - 'count' => $count, - 'timesTriggered' => $this->notification->timesTriggered, - ]); - } - - return $this->getLanguage()->get($this->languageItemPrefix . '.comment.title'); } /** @@ -159,6 +151,7 @@ class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificati ->getObjectType($this->moderationQueue->objectTypeID) ->getProcessor(); $this->languageItemPrefix = $moderationHandler->getCommentNotificationLanguageItemPrefix(); + $this->typeName = $this->getLanguage()->get($moderationHandler->getCommentNotificationTypeNameLanguageItem()); } } @@ -182,4 +175,20 @@ class ModerationQueueCommentUserNotificationEvent extends AbstractUserNotificati 'objectTypeID' => CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue'), ]; } + + /** + * @inheritDoc + */ + protected function getTypeName(): string + { + return $this->typeName; + } + + /** + * @inheritDoc + */ + protected function getObjectTitle(): string + { + return $this->moderationQueue->getTitle(); + } } diff --git a/wcfsetup/install/files/lib/system/user/notification/event/PageCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/PageCommentUserNotificationEvent.class.php index 85078a65ea..868faa35bf 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/PageCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/PageCommentUserNotificationEvent.class.php @@ -18,17 +18,12 @@ use wcf\system\user\notification\object\CommentUserNotificationObject; * * @method CommentUserNotificationObject getUserNotificationObject() */ -class PageCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements +class PageCommentUserNotificationEvent extends AbstractCommentUserNotificationEvent implements ITestableUserNotificationEvent { use TTestableCommentUserNotificationEvent; use TTestablePageUserNotificationEvent; - /** - * @inheritDoc - */ - protected $stackable = true; - /** * @inheritDoc */ @@ -37,22 +32,6 @@ class PageCommentUserNotificationEvent extends AbstractSharedUserNotificationEve UserProfileRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID); } - /** - * @inheritDoc - */ - public function getTitle(): string - { - $count = \count($this->getAuthors()); - if ($count > 1) { - return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.title.stacked', [ - 'count' => $count, - 'timesTriggered' => $this->notification->timesTriggered, - ]); - } - - return $this->getLanguage()->getDynamicVariable('wcf.user.notification.pageComment.title'); - } - /** * @inheritDoc */ @@ -111,9 +90,17 @@ class PageCommentUserNotificationEvent extends AbstractSharedUserNotificationEve /** * @inheritDoc */ - public function getEventHash() + protected function getTypeName(): string + { + return $this->getLanguage()->get('wcf.search.object.com.woltlab.wcf.page'); + } + + /** + * @inheritDoc + */ + protected function getObjectTitle(): string { - return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->objectID); + return PageCache::getInstance()->getPage($this->getUserNotificationObject()->objectID)->getTitle(); } /** diff --git a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php index 61aad7e52b..b58d089753 100644 --- a/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php +++ b/wcfsetup/install/files/lib/system/user/notification/event/UserProfileCommentUserNotificationEvent.class.php @@ -16,16 +16,11 @@ use wcf\system\user\notification\object\CommentUserNotificationObject; * * @method CommentUserNotificationObject getUserNotificationObject() */ -class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotificationEvent implements +class UserProfileCommentUserNotificationEvent extends AbstractCommentUserNotificationEvent implements ITestableUserNotificationEvent { use TTestableCommentUserNotificationEvent; - /** - * @inheritDoc - */ - protected $stackable = true; - /** * @inheritDoc */ @@ -34,22 +29,6 @@ class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotifica UserProfileRuntimeCache::getInstance()->cacheObjectID($this->getUserNotificationObject()->objectID); } - /** - * @inheritDoc - */ - public function getTitle(): string - { - $count = \count($this->getAuthors()); - if ($count > 1) { - return $this->getLanguage()->getDynamicVariable('wcf.user.notification.comment.title.stacked', [ - 'count' => $count, - 'timesTriggered' => $this->notification->timesTriggered, - ]); - } - - return $this->getLanguage()->get('wcf.user.notification.comment.title'); - } - /** * @inheritDoc */ @@ -108,9 +87,18 @@ class UserProfileCommentUserNotificationEvent extends AbstractSharedUserNotifica /** * @inheritDoc */ - public function getEventHash() + protected function getTypeName(): string + { + return $this->getLanguage()->get('wcf.user.profile.menu.wall'); + } + + /** + * @inheritDoc + */ + protected function getObjectTitle(): string { - return \sha1($this->eventID . '-' . $this->notification->userID); + return UserProfileRuntimeCache::getInstance() + ->getObject($this->getUserNotificationObject()->objectID)->username; } /** diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index d27649e25e..976ea55d92 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4290,8 +4290,6 @@ Dateianhänge: - - userID}{$author}{else}Ein Gast{/if} hat einen Kommentar zum Moderationseintrag {$moderationQueue} verfasst.]]> {$moderationQueue} verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} zum Moderationseintrag {@$moderationQueue->getTitle()} [URL:{@$moderationQueue->getLink()}] verfasst{if $count == 1 && $guestTimesTriggered < 2 && (!$event->getAuthor()->userID || $guestTimesTriggered == 0)}:{else}.{/if}]]> @@ -4338,8 +4336,6 @@ Dateianhänge: - - userID}{$author}{else}Ein Gast{/if} hat einen Kommentar zum freizuschaltenden Inhalt {$moderationQueue} verfasst.]]> {$moderationQueue} verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} zum freizuschaltenden Inhalt {@$moderationQueue->getTitle()} [URL:{@$moderationQueue->getLink()}] verfasst{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -4357,8 +4353,6 @@ Dateianhänge: - - userID}{$author}{else}Ein Gast{/if} hat einen Kommentar zur Meldung {$moderationQueue} verfasst.]]> {$moderationQueue} verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} zu der Meldung {@$moderationQueue->getTitle()} [URL:{@$moderationQueue->getLink()}] verfasst{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5358,8 +5352,6 @@ Benachrichtigungen auf {PAGE_TITLE|phra {@$authorList} {if $count == 1}folgt{else}folgen{/if} {if LANGUAGE_USE_INFORMAL_VARIANT}dir{else}Ihnen{/if}:

]]>
- - userID}{$author}{else}Ein Gast{/if} hat einen Kommentar an {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} an {if LANGUAGE_USE_INFORMAL_VARIANT}deiner{else}Ihrer{/if} Pinnwand [URL:{@$owner->getLink()}#wall/comment{@$commentID}] verfasst{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5403,8 +5395,6 @@ Benachrichtigungen auf
{PAGE_TITLE|phra - - userID}{$author}{else}Ein Gast{/if} hat einen Kommentar auf der Seite {$page->getTitle()} verfasst.]]> {$page->getTitle()} verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} auf der Seite „{@$page->getTitle()}“ [URL:{@$page->getLink()}#comment{@$commentID}] verfasst{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5424,8 +5414,9 @@ Benachrichtigungen auf {PAGE_TITLE|phra - - + + + userID}{$author}{else}Ein Gast{/if} hat einen Kommentar zu dem Artikel {$article->getTitle()} verfasst.]]> {$article->getTitle()} verfasst.]]> getAuthor()->userID || $guestTimesTriggered == 0)}hat einen Kommentar{else}haben Kommentare{/if} zu dem Artikel „{@$article->getTitle()}“ [URL:{@$article->getLink()}#comment{@$commentID}] verfasst{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index a62028cf96..4ad71f2190 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4239,8 +4239,6 @@ Attachments: - - userID}{$author}{else}A guest{/if} commented on the moderation entry {$moderationQueue}.]]> {$moderationQueue}.]]> getTitle()} [URL:{@$moderationQueue->getLink()}]{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -4287,8 +4285,6 @@ Attachments: - - userID}{$author}{else}A guest{/if} commented on {$moderationQueue} waiting for approval.]]> {$moderationQueue} waiting for approval.]]> getTitle()} [URL:{@$moderationQueue->getLink()}] waiting for approval{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -4306,8 +4302,6 @@ Attachments: - - userID}{$author}{else}A guest{/if} commented on the report {$moderationQueue}.]]> {$moderationQueue}.]]> getTitle()} [URL:{@$moderationQueue->getLink()}]{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5359,8 +5353,6 @@ your notifications on {PAGE_TITLE|phras {@$authorList} {if $authors|count == 1}follows{else}follow{/if} you:

]]>
- - userID}{$author}{else}A guest{/if} commented on your wall.]]> getLink()}#wall/comment{@$commentID}]{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5404,8 +5396,6 @@ your notifications on
{PAGE_TITLE|phras - - userID}{$author}{else}A guest{/if} commented on the page {$page->getTitle()}.]]> {$page->getTitle()}.]]> getTitle()}” [URL:{@$page->getLink()}#comment{@$commentID}]{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> @@ -5425,8 +5415,9 @@ your notifications on {PAGE_TITLE|phras - - + + + userID}{$author}{else}A guest{/if} commented on the article {$article->getTitle()}.]]> {$article->getTitle()}.]]> getTitle()}” [URL:{@$article->getLink()}#comment{@$commentID}]{if $count == 1 && !$guestTimesTriggered}:{else}.{/if}]]> -- 2.20.1