eac7e7de11678022a6430ad782c35317d6635e7f
[GitHub/WoltLab/com.woltlab.wcf.conversation.git] / files / lib / system / user / notification / event / ConversationMessageUserNotificationEvent.class.php
1 <?php
2
3 namespace wcf\system\user\notification\event;
4
5 use wcf\data\user\UserProfile;
6 use wcf\system\email\Email;
7 use wcf\system\user\notification\object\ConversationMessageUserNotificationObject;
8
9 /**
10 * User notification event for conversation messages.
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()
18 */
19 class 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
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],
85 'variables' => [
86 'author' => $this->author,
87 'message' => $this->userNotificationObject,
88 'conversation' => $this->userNotificationObject->getConversation(),
89 ],
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,
106 ]);
107 }
108
109 /**
110 * @inheritDoc
111 */
112 public function getLink()
113 {
114 return $this->getUserNotificationObject()->getLink();
115 }
116
117 /**
118 * @inheritDoc
119 */
120 public function getEventHash()
121 {
122 return \sha1($this->eventID . '-' . $this->getUserNotificationObject()->conversationID);
123 }
124
125 /**
126 * @inheritDoc
127 */
128 public function checkAccess()
129 {
130 return $this->getUserNotificationObject()->getConversation()->canRead();
131 }
132
133 /**
134 * @inheritDoc
135 */
136 public static function getTestObjects(UserProfile $recipient, UserProfile $author)
137 {
138 return [
139 new ConversationMessageUserNotificationObject(self::createTestConversationMessage($recipient, $author)),
140 ];
141 }
142 }