PluginProbe
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration / 2.1.0
FluentBoards – Project Management, Task Management, Goal Tracking, Kanban Board, and, Team Collaboration v2.1.0
2.1.0 2.0.15 2.0.12 2.0.10 2.0.4 2.0.1 2.0.0 1.95.3 1.95.2 1.95 1.91.6 trunk 1.11 1.12 1.13 1.20 1.21 1.22 1.23 1.30 1.31 1.32 1.35 1.40 1.41 All 42 releases
← All changes | app/Hooks/Handlers/NotificationHandler.php +65 -13 1.312.1.0 View file →
@@ -9,15 +9,26 @@
9 9 use FluentBoards\App\Services\Constant;
10 10
11 11 class NotificationHandler
12 12 {
13 + /**
14 + * Add a generic comment notification for watchers who were not explicitly mentioned.
15 + *
16 + * Mentioned users receive the higher-priority mention notification separately, so they
17 + * should not also receive a generic comment notification for the same comment.
18 + *
19 + * @param \FluentBoards\App\Models\Comment $comment
20 + * @return void
21 + */
13 22 public function addCommentNotification($comment)
14 23 {
15 24 if($comment->task_id){
16 25 $task = Task::findOrFail($comment->task_id);
26 + $mentionedUserIds = $this->getMentionedUserIdsFromComment($comment);
17 27 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
28 + $userIdsWhoGetNotification = $this->excludeMentionedUsersFromNotificationRecipients($userIdsWhoGetNotification, $mentionedUserIds);
18 29 if(count($userIdsWhoGetNotification) > 0){
19 - $plainDescription = strip_tags($comment->description);
30 + $plainDescription = wp_strip_all_tags($comment->description);
20 31 $action = $comment->parent_id ? 'task_reply_added' : 'comment_created';
21 32 $message = $plainDescription;
22 33 $settings = [ 'comment_id' => $comment->parent_id ?? $comment->id ];
23 34 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message, $settings);
@@ -25,13 +36,50 @@
25 36 }
26 37 }
27 38 }
28 39
40 + /**
41 + * Get normalized mentioned user IDs from a comment's stored settings.
42 + *
43 + * @param \FluentBoards\App\Models\Comment $comment
44 + * @return array
45 + */
46 + private function getMentionedUserIdsFromComment($comment)
47 + {
48 + $settings = $comment->settings;
49 +
50 + if (!is_array($settings) || empty($settings['mentioned_id']) || !is_array($settings['mentioned_id'])) {
51 + return [];
52 + }
53 +
54 + return array_values(array_filter(array_map('intval', $settings['mentioned_id'])));
55 + }
56 +
57 + /**
58 + * Remove mentioned users from generic notification recipients.
59 + *
60 + * @param array $recipientIds
61 + * @param array $mentionedUserIds
62 + * @return array
63 + */
64 + private function excludeMentionedUsersFromNotificationRecipients($recipientIds, $mentionedUserIds)
65 + {
66 + $mentionedUserIds = array_filter(array_map('intval', $mentionedUserIds));
67 +
68 + if (!$mentionedUserIds) {
69 + return array_values($recipientIds);
70 + }
71 +
72 + return array_values(array_filter($recipientIds, function ($recipientId) use ($mentionedUserIds) {
73 + return !in_array((int) $recipientId, $mentionedUserIds, true);
74 + }));
75 + }
76 +
29 77 public function mentionInCommentNotification($comment, $mentionIds)
30 78 {
31 79 if($comment){
32 80 $task = Task::findOrFail($comment->task_id);
33 - $plainDescription = strip_tags($comment->description);
81 + $plainDescription = wp_strip_all_tags($comment->description);
34 82 $action = 'task_comment_mentioned';
35 83 $message = $plainDescription;
36 84 $settings = [ 'comment_id' => $comment->parent_id ?? $comment->id ];
37 85 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message, $settings);
@@ -110,19 +158,18 @@
110 158 $notification->users()->attach($userIdsWhoGetNotification);
111 159 }
112 160 }
113 161
114 - public function changeTitleOrDescriptionNotification($task, $col, $oldTask)
162 + public function changeTitleNotification($task, $col, $oldTask)
115 163 {
164 + if ($col !== 'title') {
165 + return;
166 + }
167 +
116 168 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
117 169 if(count($userIdsWhoGetNotification) > 0){
118 - if($col == 'title'){
119 - $action = 'task_title_updated';
120 - $message = $task->title;
121 - }else{
122 - $action = 'task_description_updated';
123 - $message = $task->description;
124 - }
170 + $action = 'task_title_updated';
171 + $message = $task->title;
125 172 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
126 173 $notification->users()->attach($userIdsWhoGetNotification);
127 174 }
128 175 }
@@ -132,9 +179,10 @@
132 179 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
133 180 if(count($userIdsWhoGetNotification) > 0){
134 181 $new_board_id = Task::findOrFail($task->board_id)->board_id;
135 182 $new_board_title = Board::findOrFail($new_board_id)->title;
136 - $message = 'moved "' . $task->title . '" task to "' . $new_board_title . '" board.';
183 + // translators: %1$s is the task title, %2$s is the board title
184 + $message = sprintf(__('moved %1$s task to %2$s board.','fluent-boards'), $task->title, $new_board_title);
137 185 $notification = $this->createNotification($oldBoardId, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $message);
138 186 $notification->users()->attach($userIdsWhoGetNotification);
139 187 }
140 188 }
@@ -142,9 +190,9 @@
142 190 public function assigneeAddedNotification($task, $newAssigneeId)
143 191 {
144 192 if($newAssigneeId != get_current_user_id()){
145 193 $action = 'task_assignee_changed';
146 - $message = 'has added you as an assignee.';
194 + $message = __('has added you as an assignee.','fluent-boards');
147 195 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
148 196 $notification->users()->attach($newAssigneeId);
149 197 }
150 198 }
@@ -152,9 +200,9 @@
152 200 public function assigneeRemovedNotification($task, $newAssigneeId)
153 201 {
154 202 if($newAssigneeId != get_current_user_id()){
155 203 $action = 'task_assignee_changed';
156 - $message = 'has removed you as an assignee.';
204 + $message = __('has removed you as an assignee.','fluent-boards');
157 205 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
158 206 $notification->users()->attach($newAssigneeId);
159 207 }
160 208 }
@@ -168,8 +216,12 @@
168 216 'action' => $action,
169 217 'description' => $description,
170 218 'settings' => $settings
171 219 ];
220 + $currentUser = get_current_user_id();
221 + if($currentUser == 0) {
222 + $data['activity_by'] = $task->created_by;
223 + }
172 224 return Notification::create($data);
173 225 }
174 226
175 227 public function findUsersWhoWillGetNotification($task)