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 +88 -15 1.222.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);
@@ -50,13 +98,13 @@
50 98 $notification->users()->attach($userIdsWhoGetNotification);
51 99 }
52 100 }
53 101
54 - public function changeDateNotification($task, $oldDate)
102 + public function changeDueDateNotification($task, $oldDate)
55 103 {
56 104 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
57 105 if(count($userIdsWhoGetNotification) > 0){
58 - $action = 'task_date_changed';
106 + $action = 'task_due_date_changed';
59 107 $message = date_i18n('F j, Y, g:i a', strtotime($task->due_at));
60 108 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
61 109 $notification->users()->attach($userIdsWhoGetNotification);
62 110 }
@@ -61,8 +109,19 @@
61 109 $notification->users()->attach($userIdsWhoGetNotification);
62 110 }
63 111 }
64 112
113 + public function changeStartDateNotification($task, $oldDate)
114 + {
115 + $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
116 + if(count($userIdsWhoGetNotification) > 0){
117 + $action = 'task_start_date_changed';
118 + $message = date_i18n('F j, Y, g:i a', strtotime($task->started_at));
119 + $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
120 + $notification->users()->attach($userIdsWhoGetNotification);
121 + }
122 + }
123 +
65 124 public function changeStageNotification($task, $oldStageId)
66 125 {
67 126 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
68 127 if(count($userIdsWhoGetNotification) > 0){
@@ -99,19 +158,18 @@
99 158 $notification->users()->attach($userIdsWhoGetNotification);
100 159 }
101 160 }
102 161
103 - public function changeTitleOrDescriptionNotification($task, $col, $oldTask)
162 + public function changeTitleNotification($task, $col, $oldTask)
104 163 {
164 + if ($col !== 'title') {
165 + return;
166 + }
167 +
105 168 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
106 169 if(count($userIdsWhoGetNotification) > 0){
107 - if($col == 'title'){
108 - $action = 'task_title_updated';
109 - $message = $task->title;
110 - }else{
111 - $action = 'task_description_updated';
112 - $message = $task->description;
113 - }
170 + $action = 'task_title_updated';
171 + $message = $task->title;
114 172 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
115 173 $notification->users()->attach($userIdsWhoGetNotification);
116 174 }
117 175 }
@@ -121,24 +179,35 @@
121 179 $userIdsWhoGetNotification = $this->findUsersWhoWillGetNotification($task);
122 180 if(count($userIdsWhoGetNotification) > 0){
123 181 $new_board_id = Task::findOrFail($task->board_id)->board_id;
124 182 $new_board_title = Board::findOrFail($new_board_id)->title;
125 - $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);
126 185 $notification = $this->createNotification($oldBoardId, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $message);
127 186 $notification->users()->attach($userIdsWhoGetNotification);
128 187 }
129 188 }
130 189
131 - public function assigneeAddedNotification($task, $newAssigneeId, $operation)
190 + public function assigneeAddedNotification($task, $newAssigneeId)
132 191 {
133 192 if($newAssigneeId != get_current_user_id()){
134 193 $action = 'task_assignee_changed';
135 - $message = 'has '.$operation.' you as an assignee.';
194 + $message = __('has added you as an assignee.','fluent-boards');
136 195 $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
137 196 $notification->users()->attach($newAssigneeId);
138 197 }
139 198 }
140 199
200 + public function assigneeRemovedNotification($task, $newAssigneeId)
201 + {
202 + if($newAssigneeId != get_current_user_id()){
203 + $action = 'task_assignee_changed';
204 + $message = __('has removed you as an assignee.','fluent-boards');
205 + $notification = $this->createNotification($task, Constant::OBJECT_TYPE_BOARD_NOTIFICATION, $action, $message);
206 + $notification->users()->attach($newAssigneeId);
207 + }
208 + }
209 +
141 210 public function createNotification($task, $objectType, $action, $description, $settings = null)
142 211 {
143 212 $data = [
144 213 'object_id' => $task->board_id,
@@ -147,8 +216,12 @@
147 216 'action' => $action,
148 217 'description' => $description,
149 218 'settings' => $settings
150 219 ];
220 + $currentUser = get_current_user_id();
221 + if($currentUser == 0) {
222 + $data['activity_by'] = $task->created_by;
223 + }
151 224 return Notification::create($data);
152 225 }
153 226
154 227 public function findUsersWhoWillGetNotification($task)