Simplify phrases for notifications
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / user / notification / event / ConversationMessageUserNotificationEvent.class.php
CommitLineData
64ac54a1 1<?php
fea86294 2
64ac54a1 3namespace wcf\system\user\notification\event;
fea86294 4
5adcd121 5use wcf\data\user\UserProfile;
ffd86462 6use wcf\system\email\Email;
b41c9fd6 7use wcf\system\user\notification\object\ConversationMessageUserNotificationObject;
64ac54a1
MW
8
9/**
10 * User notification event for conversation messages.
fea86294
TD
11 *
12 * @author Marcel Werk
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\User\Notification\Event
16 *
17 * @method ConversationMessageUserNotificationObject getUserNotificationObject()
64ac54a1 18 */
fea86294
TD
19class ConversationMessageUserNotificationEvent extends AbstractUserNotificationEvent implements
20 ITestableUserNotificationEvent
21{
22 use TTestableConversationRelatedUserNotificationEvent;
23 use TTestableUserNotificationEvent;
24
25 /**
26 * @inheritDoc
27 */
28 protected $stackable = true;
29
30 /**
31 * @inheritDoc
32 */
33 public function getTitle()
34 {
35 $count = \count($this->getAuthors());
36 if ($count > 1) {
37 return $this->getLanguage()->getDynamicVariable(
38 'wcf.user.notification.conversation.message.title.stacked',
39 ['count' => $count]
40 );
41 }
42
43 return $this->getLanguage()->get('wcf.user.notification.conversation.message.title');
44 }
45
46 /**
47 * @inheritDoc
48 */
49 public function getMessage()
50 {
51 $authors = \array_values($this->getAuthors());
52 $count = \count($authors);
53
54 if ($count > 1) {
55 return $this->getLanguage()->getDynamicVariable(
56 'wcf.user.notification.conversation.message.message.stacked',
57 [
58 'author' => $this->author,
59 'authors' => $authors,
60 'count' => $count,
61 'message' => $this->userNotificationObject,
62 'others' => $count - 1,
63 ]
64 );
65 }
66
67 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message.message', [
68 'author' => $this->author,
69 'message' => $this->userNotificationObject,
70 ]);
71 }
72
fea86294
TD
73 /**
74 * @inheritDoc
75 */
76 public function getEmailMessage($notificationType = 'instant')
77 {
78 $messageID = '<com.woltlab.wcf.conversation.notification/' . $this->getUserNotificationObject()->getConversation()->conversationID . '@' . Email::getHost() . '>';
79
80 return [
81 'template' => 'email_notification_conversationMessage',
82 'application' => 'wcf',
83 'in-reply-to' => [$messageID],
84 'references' => [$messageID],
acd7061d
MW
85 'variables' => [
86 'author' => $this->author,
87 'message' => $this->userNotificationObject,
88 'conversation' => $this->userNotificationObject->getConversation(),
89 ],
fea86294
TD
90 ];
91 }
92
93 /**
94 * @inheritDoc
95 * @since 5.2
96 */
97 public function getEmailTitle()
98 {
99 if (\count($this->getAuthors()) > 1) {
100 return parent::getEmailTitle();
101 }
102
103 return $this->getLanguage()->getDynamicVariable('wcf.user.notification.conversation.message.mail.title', [
104 'author' => $this->author,
105 'message' => $this->userNotificationObject,
d8756572 106 'conversation' => $this->userNotificationObject->getConversation(),
fea86294
TD
107 ]);
108 }
109
110 /**
111 * @inheritDoc
112 */
113 public function getLink()
114 {
115 return $this->getUserNotificationObject()->getLink();
116 }
117
fea86294
TD
118 /**
119 * @inheritDoc
120 */
121 public function getEventHash()
122 {
123 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->conversationID);
124 }
125
fea86294
TD
126 /**
127 * @inheritDoc
128 */
129 public function checkAccess()
130 {
131 return $this->getUserNotificationObject()->getConversation()->canRead();
132 }
133
134 /**
135 * @inheritDoc
136 */
137 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
138 {
139 return [
140 new ConversationMessageUserNotificationObject(self::createTestConversationMessage($recipient, $author)),
141 ];
142 }
64ac54a1 143}