PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.6.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.6.0
2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 1.1.0 All 77 releases
fluent-community / app / Hooks / Handlers / NotificationEventHandler.php

NotificationEventHandler.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.6.0, at app/Hooks/Handlers/NotificationEventHandler.php

733 lines 27.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\App\Hooks\Handlers;
4
5 use FluentCommunity\App\Models\Comment;
6 use FluentCommunity\App\Models\Feed;
7 use FluentCommunity\App\Models\Notification;
8 use FluentCommunity\App\Models\NotificationSubscriber;
9 use FluentCommunity\App\Models\SpaceUserPivot;
10 use FluentCommunity\Framework\Support\Arr;
11
12 class NotificationEventHandler
13 {
14 public function register()
15 {
16 add_action('fluent_community/comment_added', [$this, 'handleNewCommentEvent'], 10, 2);
17 add_action('fluent_community/space_feed/created', [$this, 'handleNewSpaceFeed'], 10);
18 add_action('fluent_community/feed/react_added', [$this, 'handleNewFeedReact'], 10, 2);
19 add_action('fluent_community/comment/react_added', [$this, 'handleNewCommentReact'], 10, 3);
20
21 add_action('fluent_community/space/member/role_updated', [$this, 'handleSpaceMemberRoleUpdated'], 10, 2);
22
23 /*
24 * Mentions handler
25 */
26 add_action('fluent_community/feed/created', [$this, 'maybeHandleMentionedUserIds'], 10, 1);
27 }
28
29 public function handleNewCommentEvent($comment, $feed)
30 {
31 $this->commentNotificationToAuthorFeed($comment, $feed);
32
33 // now notify all users who commented on this feed
34 $this->commentNotificationToFeedCommenters($comment, $feed);
35 }
36
37 public function handleNewSpaceFeed($feed)
38 {
39 if (!$this->willCreateFeedCreatedNotification($feed)) {
40 return;
41 }
42
43 $user = $feed->user;
44 $space = $feed->space;
45
46 $this->maybeHasEveryoneTag($feed);
47
48 $userIds = SpaceUserPivot::where('space_id', $space->id)
49 ->where('user_id', '!=', $user->ID)
50 ->where('status', 'active')
51 ->pluck('user_id')
52 ->toArray();
53
54 if (!$userIds) {
55 return;
56 }
57
58 $feedTitle = $feed->getHumanExcerpt(60);
59
60 $notificationContent = \sprintf(
61 /* translators: %1$s is the user name, %2$s is the feed title and %3$3s is the space title */
62 __('%1$s posted %2$s in %3$s', 'fluent-community'),
63 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
64 '<span class="fcom_nft">' . $feedTitle . '</span>',
65 '<b class="fcom_nst">' . esc_html($space->title) . '</b>'
66 );
67
68 $route = $feed->getJsRoute();
69
70 $notification = [
71 'feed_id' => $feed->id,
72 'src_user_id' => $user->ID,
73 'src_object_type' => 'feed',
74 'action' => 'space_feed/created',
75 'content' => $notificationContent,
76 'route' => $route,
77 ];
78
79 $notification = Notification::create($notification);
80
81 $notification->subscribe($userIds);
82 }
83
84 public function handleNewFeedReact($react, $feed)
85 {
86 if ($react->user_id == $feed->user_id) {
87 return;
88 }
89
90 $feedTitle = $feed->getHumanExcerpt(40);
91 $user = $react->user;
92
93 if ($feed->reactions_count > 1) {
94 // check if we have existing notification for this feed and user
95 $existingNotification = Notification::where('feed_id', $feed->id)
96 ->where('action', 'feed/react_added')
97 ->first();
98
99 if ($existingNotification) {
100 $notificationContent = \sprintf(
101 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */
102 __('%1$s and %2$s other people reacted to your post %3$s', 'fluent-community'),
103 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
104 '<b class="fcom_nrc">' . ($feed->reactions_count - 1) . '</b>',
105 '<span class="fcom_nft">' . $feedTitle . '</span>'
106 );
107
108 $existingNotification->content = $notificationContent;
109 $existingNotification->src_user_id = $user->ID;
110 $existingNotification->save();
111 NotificationSubscriber::where('object_id', $existingNotification->id)
112 ->where('user_id', $feed->user_id)
113 ->update([
114 'is_read' => 0,
115 'updated_at' => current_time('mysql')
116 ]);
117 return;
118 }
119 }
120
121 $notificationContent = \sprintf(
122 /* translators: %1$s is the user name, %2$s is the feed title */
123 __('%1$s reacted to your post %2$s', 'fluent-community'),
124 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
125 '<span class="fcom_nft">' . $feedTitle . '</span>'
126 );
127
128 $route = $feed->getJsRoute();
129
130 $notification = [
131 'feed_id' => $feed->id,
132 'src_user_id' => $user->ID,
133 'src_object_type' => 'feed',
134 'action' => 'feed/react_added',
135 'content' => $notificationContent,
136 'route' => $route,
137 ];
138
139 $notification = Notification::create($notification);
140
141 $notification->subscribe([$feed->user_id]);
142 }
143
144 public function handleNewCommentReact($react, $comment, $feed)
145 {
146 if ($react->user_id == $comment->user_id) {
147 return;
148 }
149
150 $commentExcerpt = $comment->getHumanExcerpt(40);
151 $user = $react->user;
152
153 if ($comment->reactions_count > 1) {
154 $notificationContent = \sprintf(
155 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the comment excerpt */
156 __('%1$s and %2$s other people reacted to your comment %3$s', 'fluent-community'),
157 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
158 '<b class="fcom_nrc">' . ($comment->reactions_count - 1) . '</b>',
159 '<span class="fcom_nft">' . $commentExcerpt . '</span>'
160 );
161 } else {
162 $notificationContent = \sprintf(
163 /* translators: %1$s is the user name, %2$s is the comment excerpt */
164 __('%1$s reacted to your comment %2$s', 'fluent-community'),
165 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
166 '<span class="fcom_nft">' . $commentExcerpt . '</span>'
167 );
168 }
169
170 $existingNotification = Notification::where('feed_id', $feed->id)
171 ->where('object_id', $comment->id)
172 ->where('action', 'comment/react_added')
173 ->first();
174
175 if ($existingNotification) {
176 $existingNotification->content = $notificationContent;
177 $existingNotification->src_user_id = $user->ID;
178 $existingNotification->save();
179 NotificationSubscriber::where('object_id', $existingNotification->id)
180 ->where('user_id', $comment->user_id)
181 ->update(['is_read' => 0, 'updated_at' => current_time('mysql')]);
182 return;
183 }
184
185 $notification = Notification::create([
186 'feed_id' => $feed->id,
187 'object_id' => $comment->id,
188 'src_user_id' => $user->ID,
189 'src_object_type' => 'comment',
190 'action' => 'comment/react_added',
191 'content' => $notificationContent,
192 'route' => $feed->getJsRoute(),
193 ]);
194
195 $notification->subscribe([$comment->user_id]);
196 }
197
198 public function handleSpaceMemberRoleUpdated($space, $pivot)
199 {
200 $user = $pivot->user;
201
202 $notificationContent = \sprintf(
203 /* translators: %1$s is the role name, %2$s is the space title */
204 __('You have been added as %1$s in %2$s', 'fluent-community'),
205 '<b>' . $pivot->role . '</b>',
206 '<b>' . $space->title . '</b>'
207 );
208
209 $route = [
210 'name' => 'space_feeds',
211 'params' => [
212 'space' => $space->slug
213 ]
214 ];
215
216 $notification = [
217 'object_id' => $space->id,
218 'src_user_id' => $user->ID,
219 'src_object_type' => 'space',
220 'action' => 'space/member/role_updated',
221 'content' => $notificationContent,
222 'route' => $route,
223 ];
224 $notification = Notification::create($notification);
225 $notification->subscribe([$pivot->user_id]);
226 }
227
228 protected function commentNotificationToAuthorFeed(Comment $comment, Feed $feed)
229 {
230 if ($comment->user_id == $feed->user_id) {
231 return;
232 }
233
234 $mentionedUserIds = Arr::get($feed->meta, 'mentioned_user_ids', []);
235 if (in_array($feed->user_id, $mentionedUserIds)) {
236 return;
237 }
238
239 $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>';
240 $feedTitle = $feed->getHumanExcerpt(60);
241
242 $exist = null;
243 if ($feed->comments_count > 1) {
244 // check if we have existing notification for this feed and user
245 $exist = Notification::where('feed_id', $feed->id)
246 ->where('action', 'comment_added')
247 ->whereHas('subscribers', function ($q) use ($feed) {
248 $q->where('user_id', $feed->user_id);
249 })
250 ->first();
251
252 $totalUsers = $feed->comments
253 ->where('user_id', '!=', $feed->user_id)
254 ->pluck('user_id')
255 ->unique()
256 ->count();
257
258 if ($feed->space_id) {
259 if ($totalUsers > 1) {
260 $notificationContent = \sprintf(
261 /* translators: %1$s is the user name, %2$s is the people count, %3$s is the feed title and %4$s space title*/
262 __('%1$s and %2$s other people commented on your post %3$s in %4$s', 'fluent-community'),
263 $commenter,
264 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
265 '<span class="fcom_nft">' . $feedTitle . '</span>',
266 '<b class="fcom_nst">' . $feed->space->title . '</b>'
267 );
268 } else {
269 $notificationContent = \sprintf(
270 /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/
271 __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'),
272 $commenter,
273 '<span class="fcom_nft">' . $feedTitle . '</span>',
274 '<b class="fcom_nst">' . $feed->space->title . '</b>'
275 );
276 }
277 } else {
278
279 if ($totalUsers > 1) {
280 $notificationContent = \sprintf(
281 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */
282 __('%1$s and %2$s other people commented on your post %3$s', 'fluent-community'),
283 $commenter,
284 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
285 '<span class="fcom_nft">' . $feedTitle . '</span>'
286 );
287 } else {
288 $notificationContent = \sprintf(
289 /* translators: %1$s is the user name & %2$s is the feed title */
290 __('%1$s commented on your post: %2$s', 'fluent-community'),
291 $commenter,
292 '<span class="fcom_nft">' . $feedTitle . '</span>'
293 );
294 }
295 }
296 } else {
297 if ($feed->space_id) {
298 $notificationContent = \sprintf(
299 /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */
300 __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'),
301 $commenter,
302 '<span class="fcom_nft">' . $feedTitle . '</span>',
303 '<b class="fcom_nst">' . $feed->space->title . '</b>'
304 );
305 } else {
306 $notificationContent = \sprintf(
307 /* translators: %1$s is the commenter name & %2$s is the feed title */
308 __('%1$s commented on your post: %2$s', 'fluent-community'),
309 $commenter,
310 '<span class="fcom_nft">' . $feedTitle . '</span>'
311 );
312 }
313 }
314
315 $route = $feed->getJsRoute();
316
317 if ($exist) {
318 $exist->content = $notificationContent;
319 $exist->updated_at = current_time('mysql');
320 $exist->src_user_id = $comment->user->ID;
321 $exist->object_id = $comment->id;
322 $exist->save();
323
324 NotificationSubscriber::where('object_id', $exist->id)
325 ->where('user_id', $feed->user_id)
326 ->update([
327 'is_read' => 0,
328 'updated_at' => current_time('mysql')
329 ]);
330
331 do_action('fluent_community/notification/comment/notifed_to_author', [
332 'user_ids' => [$feed->user_id],
333 'notification' => $exist,
334 'key' => 'notifed_to_author',
335 'comment' => $comment,
336 'feed' => $feed,
337 'created' => false
338 ]);
339
340 return;
341 }
342
343 $notification = [
344 'feed_id' => $feed->id,
345 'object_id' => $comment->id,
346 'src_user_id' => $comment->user_id,
347 'src_object_type' => 'comment',
348 'action' => 'comment_added',
349 'content' => $notificationContent,
350 'route' => $route,
351 ];
352
353 $notification = Notification::create($notification);
354
355 $notification->subscribe([$feed->user_id]);
356
357 do_action('fluent_community/notification/comment/notifed_to_author', [
358 'user_ids' => [$feed->user_id],
359 'notification' => $notification,
360 'comment' => $comment,
361 'key' => 'notifed_to_author',
362 'feed' => $feed,
363 'created' => true
364 ]);
365 }
366
367 protected function commentNotificationToFeedCommenters($comment, $feed)
368 {
369 if ($comment->parent_id) {
370 return $this->notifyForChildCommentReply($comment, $feed);
371 }
372
373 $userIds = Comment::whereNotIn('user_id', [$feed->user_id, $comment->user_id])
374 ->where('post_id', $feed->id)
375 ->whereNull('parent_id')
376 ->distinct()
377 ->pluck('user_id')
378 ->toArray();
379
380 $mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', []);
381
382 if (!$userIds && !$mentionedUserIds) {
383 return;
384 }
385
386 $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>';
387 $feedTitle = '<span class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</span>';
388
389 $route = $feed->getJsRoute();
390 $space = $feed->space;
391
392 if ($feed->comments_count > 1) {
393 $totalUsers = $feed->comments
394 ->where('user_id', '!=', $comment->user_id)
395 ->pluck('user_id')
396 ->unique()
397 ->count();
398
399 if ($feed->space_id) {
400 if ($totalUsers > 1) {
401 $notificationContent = \sprintf(
402 /* translators: %1$s is the user name, %2$s is the people count, %3$s is the feed title and %4$s space title*/
403 __('%1$s and %2$s other people also commented on %3$s in %4$s', 'fluent-community'),
404 $commenter,
405 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
406 $feedTitle,
407 '<b class="fcom_nst">' . $feed->space->title . '</b>'
408 );
409 } else {
410 $notificationContent = \sprintf(
411 /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/
412 __('%1$s also commented on %2$s in %3$s', 'fluent-community'),
413 $commenter,
414 $feedTitle,
415 '<b class="fcom_nst">' . $feed->space->title . '</b>'
416 );
417 }
418 } else {
419 if ($totalUsers > 1) {
420 $notificationContent = \sprintf(
421 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */
422 __('%1$s and %2$s other people also commented on %3$s', 'fluent-community'),
423 $commenter,
424 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
425 $feedTitle,
426 );
427 } else {
428 $notificationContent = \sprintf(
429 /* translators: %1$s is the user name & %2$s is the feed title */
430 __('%1$s also commented on %2$s', 'fluent-community'),
431 $commenter,
432 $feedTitle,
433 );
434 }
435 }
436 } else {
437 if ($feed->space_id) {
438 $notificationContent = \sprintf(
439 /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */
440 __('%1$s also commented on %2$s in %3$s', 'fluent-community'),
441 $commenter,
442 $feedTitle,
443 '<b class="fcom_nst">' . $space->title . '</b>'
444 );
445 } else {
446 $notificationContent = \sprintf(
447 /* translators: %1$s is the commenter name & %2$s is the feed title */
448 __('%1$s also commented on %2$s', 'fluent-community'),
449 $commenter,
450 $feedTitle,
451 );
452 }
453 }
454
455 if ($mentionedUserIds) {
456 $mentionNotification = Notification::create([
457 'feed_id' => $feed->id,
458 'object_id' => $comment->id,
459 'src_user_id' => $comment->user_id,
460 'src_object_type' => 'comment',
461 'action' => 'mention_added',
462 'content' => \sprintf(
463 /* translators: %1$s is the commenter name & %2$s is the feed title */
464 __('%1$s mentioned you in a comment at %2$s', 'fluent-community'),
465 $commenter,
466 $feedTitle,
467 ),
468 'route' => $route,
469 ]);
470
471 $mentionNotification->subscribe($mentionedUserIds);
472
473 do_action('fluent_community/notification/comment/notifed_to_mentions', [
474 'user_ids' => $mentionedUserIds,
475 'notification' => $mentionNotification,
476 'key' => 'notifed_to_mentions',
477 'comment' => $comment,
478 'feed' => $feed
479 ]);
480 }
481
482 if ($mentionedUserIds) {
483 $userIds = array_values(array_diff($userIds, $mentionedUserIds));
484 }
485
486 if (!$userIds) {
487 return;
488 }
489
490 $existIds = Notification::where('feed_id', $feed->id)
491 ->where('action', 'comment_added')
492 ->whereDoesntHave('subscribers', function ($query) use ($feed, $comment) {
493 $query->whereIn('user_id', [$feed->user_id, $comment->user_id]);
494 })
495 ->pluck('id')
496 ->toArray();
497
498 $existingSubscriberUserIds = [];
499 if (!empty($existIds)) {
500 Notification::whereIn('id', $existIds)->update([
501 'content' => $notificationContent,
502 'updated_at' => current_time('mysql'),
503 'src_user_id' => $comment->user_id,
504 'object_id' => $comment->id
505 ]);
506
507 $existingSubscriberUserIds = NotificationSubscriber::whereIn('object_id', $existIds)
508 ->pluck('user_id')
509 ->unique()
510 ->toArray();
511
512 NotificationSubscriber::whereIn('object_id', $existIds)
513 ->whereIn('user_id', $existingSubscriberUserIds)
514 ->update([
515 'is_read' => 0,
516 'updated_at' => current_time('mysql')
517 ]);
518 }
519
520 if (!empty($existingSubscriberUserIds)) {
521 $userIds = array_values(array_diff($userIds, $existingSubscriberUserIds));
522 }
523
524 $notification = [
525 'feed_id' => $feed->id,
526 'object_id' => $comment->id,
527 'src_user_id' => $comment->user_id,
528 'src_object_type' => 'comment',
529 'action' => 'comment_added',
530 'content' => $notificationContent,
531 'route' => $route,
532 ];
533
534 foreach ($userIds as $userId) {
535 $createdNotification = Notification::create($notification);
536 $createdNotification->subscribe([$userId]);
537 }
538
539 $sendingUserIds = array_merge($userIds, $existingSubscriberUserIds);
540
541 do_action('fluent_community/notification/comment/notifed_to_other_users', [
542 'user_ids' => $sendingUserIds,
543 'key' => 'notifed_to_other_users',
544 'notification' => $notification,
545 'comment' => $comment,
546 'feed' => $feed
547 ]);
548 }
549
550 protected function notifyForChildCommentReply($comment, $feed)
551 {
552 // This is a parent comment, so we need to notify the parent comment author & all child comment authors
553 $childCommentUserIds = Comment::where(function ($q) use ($comment) {
554 $q->where('parent_id', $comment->parent_id)
555 ->orWhere('id', $comment->parent_id);
556 })
557 ->whereNotIn('user_id', [$comment->user_id, $feed->user_id])
558 ->select(['user_id'])
559 ->distinct('user_id')
560 ->get()
561 ->pluck('user_id')
562 ->toArray();
563
564 if (!$childCommentUserIds) {
565 return false;
566 }
567
568 $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>';
569
570 $existingNotification = Notification::where('object_id', $comment->parent_id)
571 ->where('action', 'child_comment_added')
572 ->whereHas('subscribers', function ($q) use ($childCommentUserIds) {
573 $q->whereIn('user_id', $childCommentUserIds);
574 })
575 ->first();
576
577 if ($existingNotification) {
578 $newContent = \sprintf(
579 /* translators: %1$s is the commenter name, %2$s is the comment user count & %3$s feed excerpt */
580 __('%1$s and %2$s other people replied to your comment at %3$s', 'fluent-community'),
581 $commenter,
582 '<b class="fcom_nrc">' . count($childCommentUserIds) . '</b>',
583 '<b class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</b>'
584 );
585
586 $route = $existingNotification->route;
587 $route['query'] = [
588 'comment_id' => $comment->id
589 ];
590
591 $existingNotification->content = $newContent;
592 $existingNotification->updated_at = current_time('mysql');
593 $existingNotification->src_user_id = $comment->user_id;
594 $existingNotification->route = $route;
595 $existingNotification->save();
596
597 NotificationSubscriber::where('object_id', $existingNotification->id)
598 ->whereIn('user_id', $childCommentUserIds)
599 ->update([
600 'is_read' => 0,
601 'updated_at' => current_time('mysql')
602 ]);
603
604 do_action('fluent_community/notification/comment/notifed_to_thread_commetenter', [
605 'user_ids' => $childCommentUserIds,
606 'notification' => $existingNotification,
607 'key' => 'notifed_to_thread_commetenter',
608 'comment' => $comment,
609 'feed' => $feed
610 ]);
611
612 return $existingNotification;
613 }
614
615 $notificationContent = \sprintf(
616 /* translators: %1$s is the commenter name & %2$s is the feed excerpt */
617 __('%1$s replied to your comment at %2$s', 'fluent-community'),
618 $commenter,
619 '<b class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</b>'
620 );
621
622 $route = $feed->getJsRoute();
623
624 $route['query'] = [
625 'comment_id' => $comment->id
626 ];
627
628 $notification = [
629 'feed_id' => $feed->id,
630 'object_id' => $comment->parent_id,
631 'src_user_id' => $comment->user_id,
632 'src_object_type' => 'comment',
633 'action' => 'child_comment_added',
634 'content' => $notificationContent,
635 'route' => $route,
636 ];
637
638 $notification = Notification::create($notification);
639 $notification->subscribe($childCommentUserIds);
640
641 do_action('fluent_community/notification/comment/notifed_to_thread_commetenter', [
642 'user_ids' => $childCommentUserIds,
643 'notification' => $notification,
644 'key' => 'notifed_to_thread_commetenter',
645 'comment' => $comment,
646 'feed' => $feed
647 ]);
648
649 return $notification;
650 }
651
652 public function maybeHandleMentionedUserIds($feed)
653 {
654 $mentionedUserIds = Arr::get($feed->meta, 'mentioned_user_ids', []);
655 if (!$mentionedUserIds) {
656 return;
657 }
658
659 do_action('fluent_community/feed_mentioned_user_ids', $feed, $mentionedUserIds);
660
661 $feedTitle = $feed->getHumanExcerpt(60);
662 $user = $feed->user;
663
664 $notificationContent = \sprintf(
665 /* translators: %1$s is the user name, %2$s is the feed title */
666 __('%1$s mentioned you in a post: %2$s', 'fluent-community'),
667 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
668 '<b class="fcom_nft">' . $feedTitle . '</b>'
669 );
670
671 $route = $feed->getJsRoute();
672
673 $notification = [
674 'feed_id' => $feed->id,
675 'src_user_id' => $user->ID,
676 'src_object_type' => 'feed',
677 'action' => 'feed/mentioned',
678 'content' => $notificationContent,
679 'route' => $route,
680 ];
681
682 $notification = Notification::create($notification);
683
684 $notification->subscribe($mentionedUserIds);
685 }
686
687 private function maybeHasEveryoneTag(Feed $feed)
688 {
689 if (!$feed->space_id) {
690 return;
691 }
692
693 if (!$feed->isEnabledForEveryoneTag()) {
694 return;
695 }
696
697 // we have everyone
698 // check if current user is a moderator or admin
699 $user = $feed->user;
700 $spaceRole = $user->getSpaceRole($feed->space);
701 if (!in_array($spaceRole, ['admin', 'moderator'])) {
702 return;
703 }
704
705 do_action('fluent_community/feed/scheduling_everyone_tag', $feed);
706 // Let's schedule an email hook to send email to everyone for this post
707 // We are scheduling this after 5 minutes of the post publish for performance
708 as_schedule_single_action(time() + 300, 'fluent_community/email_notify_users_everyone_tag', [
709 $feed->id,
710 0
711 ], 'fluent-community');
712 }
713
714 private function willCreateFeedCreatedNotification($feed)
715 {
716 // validate if the user is a moderator
717 if (!$feed->user) {
718 return;
719 }
720
721 if ($feed->user->isCommunityModerator()) {
722 return true;
723 }
724
725 if ($feed->space) {
726 $role = $feed->user->getSpaceRole($feed->space);
727 return in_array($role, ['admin', 'moderator']);
728 }
729
730 return false;
731 }
732 }
733