PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.5.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.5.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.5.0, at app/Hooks/Handlers/NotificationEventHandler.php

727 lines 27.4 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 ->first();
248
249 $totalUsers = $feed->comments
250 ->where('user_id', '!=', $feed->user_id)
251 ->pluck('user_id')
252 ->unique()
253 ->count();
254
255 if ($feed->space_id) {
256 if ($totalUsers > 1) {
257 $notificationContent = \sprintf(
258 /* translators: %1$s is the user name, %2$s is the people count, %3$s is the feed title and %4$s space title*/
259 __('%1$s and %2$s other people commented on your post %3$s in %4$s', 'fluent-community'),
260 $commenter,
261 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
262 '<span class="fcom_nft">' . $feedTitle . '</span>',
263 '<b class="fcom_nst">' . $feed->space->title . '</b>'
264 );
265 } else {
266 $notificationContent = \sprintf(
267 /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/
268 __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'),
269 $commenter,
270 '<span class="fcom_nft">' . $feedTitle . '</span>',
271 '<b class="fcom_nst">' . $feed->space->title . '</b>'
272 );
273 }
274 } else {
275
276 if ($totalUsers > 1) {
277 $notificationContent = \sprintf(
278 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */
279 __('%1$s and %2$s other people commented on your post %3$s', 'fluent-community'),
280 $commenter,
281 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
282 '<span class="fcom_nft">' . $feedTitle . '</span>'
283 );
284 } else {
285 $notificationContent = \sprintf(
286 /* translators: %1$s is the user name & %2$s is the feed title */
287 __('%1$s commented on your post: %2$s', 'fluent-community'),
288 $commenter,
289 '<span class="fcom_nft">' . $feedTitle . '</span>'
290 );
291 }
292 }
293 } else {
294 if ($feed->space_id) {
295 $notificationContent = \sprintf(
296 /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */
297 __('%1$s commented on your post: %2$s in %3$s', 'fluent-community'),
298 $commenter,
299 '<span class="fcom_nft">' . $feedTitle . '</span>',
300 '<b class="fcom_nst">' . $feed->space->title . '</b>'
301 );
302 } else {
303 $notificationContent = \sprintf(
304 /* translators: %1$s is the commenter name & %2$s is the feed title */
305 __('%1$s commented on your post: %2$s', 'fluent-community'),
306 $commenter,
307 '<span class="fcom_nft">' . $feedTitle . '</span>'
308 );
309 }
310 }
311
312 $route = $feed->getJsRoute();
313
314 if ($exist) {
315 $exist->content = $notificationContent;
316 $exist->updated_at = current_time('mysql');
317 $exist->src_user_id = $comment->user->ID;
318 $exist->object_id = $comment->id;
319 $exist->save();
320
321 NotificationSubscriber::where('object_id', $exist->id)
322 ->where('user_id', $feed->user_id)
323 ->update([
324 'is_read' => 0,
325 'updated_at' => current_time('mysql')
326 ]);
327
328 do_action('fluent_community/notification/comment/notifed_to_author', [
329 'user_ids' => [$feed->user_id],
330 'notification' => $exist,
331 'key' => 'notifed_to_author',
332 'comment' => $comment,
333 'feed' => $feed,
334 'created' => false
335 ]);
336
337 return;
338 }
339
340 $notification = [
341 'feed_id' => $feed->id,
342 'object_id' => $comment->id,
343 'src_user_id' => $comment->user_id,
344 'src_object_type' => 'comment',
345 'action' => 'comment_added',
346 'content' => $notificationContent,
347 'route' => $route,
348 ];
349
350 $notification = Notification::create($notification);
351
352 $notification->subscribe([$feed->user_id]);
353
354 do_action('fluent_community/notification/comment/notifed_to_author', [
355 'user_ids' => [$feed->user_id],
356 'notification' => $notification,
357 'comment' => $comment,
358 'key' => 'notifed_to_author',
359 'feed' => $feed,
360 'created' => true
361 ]);
362 }
363
364 protected function commentNotificationToFeedCommenters($comment, $feed)
365 {
366 if ($comment->parent_id) {
367 return $this->notifyForChildCommentReply($comment, $feed);
368 }
369
370 $userIds = Comment::whereNotIn('user_id', [$feed->user_id, $comment->user_id])
371 ->where('post_id', $feed->id)
372 ->whereNull('parent_id')
373 ->distinct()
374 ->pluck('user_id')
375 ->toArray();
376
377 $mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', []);
378
379 if (!$userIds && !$mentionedUserIds) {
380 return;
381 }
382
383 $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>';
384 $feedTitle = '<span class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</span>';
385
386 $route = $feed->getJsRoute();
387 $space = $feed->space;
388
389 if ($feed->comments_count > 1) {
390 $totalUsers = $feed->comments
391 ->where('user_id', '!=', $comment->user_id)
392 ->pluck('user_id')
393 ->unique()
394 ->count();
395
396 if ($feed->space_id) {
397 if ($totalUsers > 1) {
398 $notificationContent = \sprintf(
399 /* translators: %1$s is the user name, %2$s is the people count, %3$s is the feed title and %4$s space title*/
400 __('%1$s and %2$s other people also commented on %3$s in %4$s', 'fluent-community'),
401 $commenter,
402 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
403 $feedTitle,
404 '<b class="fcom_nst">' . $feed->space->title . '</b>'
405 );
406 } else {
407 $notificationContent = \sprintf(
408 /* translators: %1$s is the user name, %2$s is the feed title and %3$s space title*/
409 __('%1$s also commented on %2$s in %3$s', 'fluent-community'),
410 $commenter,
411 $feedTitle,
412 '<b class="fcom_nst">' . $feed->space->title . '</b>'
413 );
414 }
415 } else {
416 if ($totalUsers > 1) {
417 $notificationContent = \sprintf(
418 /* translators: %1$s is the user name, %2$s is the like count & %3$s is the feed title */
419 __('%1$s and %2$s other people also commented on %3$s', 'fluent-community'),
420 $commenter,
421 '<b class="fcom_nrc">' . ($totalUsers - 1) . '</b>',
422 $feedTitle,
423 );
424 } else {
425 $notificationContent = \sprintf(
426 /* translators: %1$s is the user name & %2$s is the feed title */
427 __('%1$s also commented on %2$s', 'fluent-community'),
428 $commenter,
429 $feedTitle,
430 );
431 }
432 }
433 } else {
434 if ($feed->space_id) {
435 $notificationContent = \sprintf(
436 /* translators: %1$s is the commenter name, %2$s is the feed title & %3$s is the space title */
437 __('%1$s also commented on %2$s in %3$s', 'fluent-community'),
438 $commenter,
439 $feedTitle,
440 '<b class="fcom_nst">' . $space->title . '</b>'
441 );
442 } else {
443 $notificationContent = \sprintf(
444 /* translators: %1$s is the commenter name & %2$s is the feed title */
445 __('%1$s also commented on %2$s', 'fluent-community'),
446 $commenter,
447 $feedTitle,
448 );
449 }
450 }
451
452 if ($mentionedUserIds) {
453 $mentionNotification = Notification::create([
454 'feed_id' => $feed->id,
455 'object_id' => $comment->id,
456 'src_user_id' => $comment->user_id,
457 'src_object_type' => 'comment',
458 'action' => 'mention_added',
459 'content' => \sprintf(
460 /* translators: %1$s is the commenter name & %2$s is the feed title */
461 __('%1$s mentioned you in a comment at %2$s', 'fluent-community'),
462 $commenter,
463 $feedTitle,
464 ),
465 'route' => $route,
466 ]);
467
468 $mentionNotification->subscribe($mentionedUserIds);
469
470 do_action('fluent_community/notification/comment/notifed_to_mentions', [
471 'user_ids' => $mentionedUserIds,
472 'notification' => $mentionNotification,
473 'key' => 'notifed_to_mentions',
474 'comment' => $comment,
475 'feed' => $feed
476 ]);
477 }
478
479 if ($mentionedUserIds) {
480 $userIds = array_values(array_diff($userIds, $mentionedUserIds));
481 }
482
483 if (!$userIds) {
484 return;
485 }
486
487 $existIds = Notification::where('feed_id', $feed->id)
488 ->where('action', 'comment_added')
489 ->whereDoesntHave('subscribers', function ($query) use ($feed, $comment) {
490 $query->whereIn('user_id', [$feed->user_id, $comment->user_id]);
491 })
492 ->pluck('id')
493 ->toArray();
494
495 $existingSubscriberUserIds = [];
496 if (!empty($existIds)) {
497 Notification::whereIn('id', $existIds)->update([
498 'content' => $notificationContent,
499 'updated_at' => current_time('mysql'),
500 'src_user_id' => $comment->user_id,
501 'object_id' => $comment->id
502 ]);
503
504 $existingSubscriberUserIds = NotificationSubscriber::whereIn('object_id', $existIds)
505 ->pluck('user_id')
506 ->unique()
507 ->toArray();
508
509 NotificationSubscriber::whereIn('object_id', $existIds)
510 ->whereIn('user_id', $existingSubscriberUserIds)
511 ->update([
512 'is_read' => 0,
513 'updated_at' => current_time('mysql')
514 ]);
515 }
516
517 if (!empty($existingSubscriberUserIds)) {
518 $userIds = array_values(array_diff($userIds, $existingSubscriberUserIds));
519 }
520
521 $notification = [
522 'feed_id' => $feed->id,
523 'object_id' => $comment->id,
524 'src_user_id' => $comment->user_id,
525 'src_object_type' => 'comment',
526 'action' => 'comment_added',
527 'content' => $notificationContent,
528 'route' => $route,
529 ];
530
531 foreach ($userIds as $userId) {
532 $createdNotification = Notification::create($notification);
533 $createdNotification->subscribe([$userId]);
534 }
535
536 $sendingUserIds = array_merge($userIds, $existingSubscriberUserIds);
537
538 do_action('fluent_community/notification/comment/notifed_to_other_users', [
539 'user_ids' => $sendingUserIds,
540 'key' => 'notifed_to_other_users',
541 'notification' => $notification,
542 'comment' => $comment,
543 'feed' => $feed
544 ]);
545 }
546
547 protected function notifyForChildCommentReply($comment, $feed)
548 {
549 // This is a parent comment, so we need to notify the parent comment author & all child comment authors
550 $childCommentUserIds = Comment::where(function ($q) use ($comment) {
551 $q->where('parent_id', $comment->parent_id)
552 ->orWhere('id', $comment->parent_id);
553 })
554 ->whereNotIn('user_id', [$comment->user_id, $feed->user_id])
555 ->select(['user_id'])
556 ->distinct('user_id')
557 ->get()
558 ->pluck('user_id')
559 ->toArray();
560
561 if (!$childCommentUserIds) {
562 return false;
563 }
564
565 $commenter = '<b class="fcom_nudn">' . esc_html($comment->user->display_name) . '</b>';
566
567 $existingNotification = Notification::where('object_id', $comment->parent_id)
568 ->where('action', 'child_comment_added')
569 ->first();
570
571 if ($existingNotification) {
572 $newContent = \sprintf(
573 /* translators: %1$s is the commenter name, %2$s is the comment user count & %3$s feed excerpt */
574 __('%1$s and %2$s other people replied to your comment at %3$s', 'fluent-community'),
575 $commenter,
576 '<b class="fcom_nrc">' . count($childCommentUserIds) . '</b>',
577 '<b class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</b>'
578 );
579
580 $route = $existingNotification->route;
581 $route['query'] = [
582 'comment_id' => $comment->id
583 ];
584
585 $existingNotification->content = $newContent;
586 $existingNotification->updated_at = current_time('mysql');
587 $existingNotification->src_user_id = $comment->user_id;
588 $existingNotification->route = $route;
589 $existingNotification->save();
590
591 NotificationSubscriber::where('object_id', $existingNotification->id)
592 ->whereIn('user_id', $childCommentUserIds)
593 ->update([
594 'is_read' => 0,
595 'updated_at' => current_time('mysql')
596 ]);
597
598 do_action('fluent_community/notification/comment/notifed_to_thread_commetenter', [
599 'user_ids' => $childCommentUserIds,
600 'notification' => $existingNotification,
601 'key' => 'notifed_to_thread_commetenter',
602 'comment' => $comment,
603 'feed' => $feed
604 ]);
605
606 return $existingNotification;
607 }
608
609 $notificationContent = \sprintf(
610 /* translators: %1$s is the commenter name & %2$s is the feed excerpt */
611 __('%1$s replied to your comment at %2$s', 'fluent-community'),
612 $commenter,
613 '<b class="fcom_nft">' . $feed->getHumanExcerpt(60) . '</b>'
614 );
615
616 $route = $feed->getJsRoute();
617
618 $route['query'] = [
619 'comment_id' => $comment->id
620 ];
621
622 $notification = [
623 'feed_id' => $feed->id,
624 'object_id' => $comment->parent_id,
625 'src_user_id' => $comment->user_id,
626 'src_object_type' => 'comment',
627 'action' => 'child_comment_added',
628 'content' => $notificationContent,
629 'route' => $route,
630 ];
631
632 $notification = Notification::create($notification);
633 $notification->subscribe($childCommentUserIds);
634
635 do_action('fluent_community/notification/comment/notifed_to_thread_commetenter', [
636 'user_ids' => $childCommentUserIds,
637 'notification' => $notification,
638 'key' => 'notifed_to_thread_commetenter',
639 'comment' => $comment,
640 'feed' => $feed
641 ]);
642
643 return $notification;
644 }
645
646 public function maybeHandleMentionedUserIds($feed)
647 {
648 $mentionedUserIds = Arr::get($feed->meta, 'mentioned_user_ids', []);
649 if (!$mentionedUserIds) {
650 return;
651 }
652
653 do_action('fluent_community/feed_mentioned_user_ids', $feed, $mentionedUserIds);
654
655 $feedTitle = $feed->getHumanExcerpt(60);
656 $user = $feed->user;
657
658 $notificationContent = \sprintf(
659 /* translators: %1$s is the user name, %2$s is the feed title */
660 __('%1$s mentioned you in a post: %2$s', 'fluent-community'),
661 '<b class="fcom_nudn">' . esc_html($user->display_name) . '</b>',
662 '<b class="fcom_nft">' . $feedTitle . '</b>'
663 );
664
665 $route = $feed->getJsRoute();
666
667 $notification = [
668 'feed_id' => $feed->id,
669 'src_user_id' => $user->ID,
670 'src_object_type' => 'feed',
671 'action' => 'feed/mentioned',
672 'content' => $notificationContent,
673 'route' => $route,
674 ];
675
676 $notification = Notification::create($notification);
677
678 $notification->subscribe($mentionedUserIds);
679 }
680
681 private function maybeHasEveryoneTag(Feed $feed)
682 {
683 if (!$feed->space_id) {
684 return;
685 }
686
687 if (!$feed->isEnabledForEveryoneTag()) {
688 return;
689 }
690
691 // we have everyone
692 // check if current user is a moderator or admin
693 $user = $feed->user;
694 $spaceRole = $user->getSpaceRole($feed->space);
695 if (!in_array($spaceRole, ['admin', 'moderator'])) {
696 return;
697 }
698
699 do_action('fluent_community/feed/scheduling_everyone_tag', $feed);
700 // Let's schedule an email hook to send email to everyone for this post
701 // We are scheduling this after 5 minutes of the post publish for performance
702 as_schedule_single_action(time() + 300, 'fluent_community/email_notify_users_everyone_tag', [
703 $feed->id,
704 0
705 ], 'fluent-community');
706 }
707
708 private function willCreateFeedCreatedNotification($feed)
709 {
710 // validate if the user is a moderator
711 if (!$feed->user) {
712 return;
713 }
714
715 if ($feed->user->isCommunityModerator()) {
716 return true;
717 }
718
719 if ($feed->space) {
720 $role = $feed->user->getSpaceRole($feed->space);
721 return in_array($role, ['admin', 'moderator']);
722 }
723
724 return false;
725 }
726 }
727