PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.7.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.7.0
2.11.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 All 78 releases
fluent-community / app / Hooks / Handlers / NotificationEventHandler.php

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

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