PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.11.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.11.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
← All changes | app/Hooks/Handlers/EmailNotificationHandler.php +72 -32 2.6.012.11.0 View file →
@@ -12,8 +12,9 @@
12 12 use FluentCommunity\App\Models\XProfile;
13 13 use FluentCommunity\App\Services\Helper;
14 14 use FluentCommunity\App\Services\Libs\DailyDigest;
15 15 use FluentCommunity\App\Services\Libs\Mailer;
16 +use FluentCommunity\App\Services\FeedsHelper;
16 17 use FluentCommunity\App\Services\NotificationPref;
17 18 use FluentCommunity\App\Services\ProfileHelper;
18 19 use FluentCommunity\Framework\Support\Arr;
19 20
@@ -59,22 +60,23 @@
59 60 if (!$space) {
60 61 return false;
61 62 }
62 63
63 - $types = ['np_by_member_mail'];
64 + $events = ['np_by_member'];
64 65 $spaceRole = $feed->user->getSpaceRole($feed->space);
65 66 if (in_array($spaceRole, ['admin', 'moderator'])) {
66 - $types[] = 'np_by_admin_mail';
67 + $events[] = 'np_by_admin';
67 68 }
68 69
69 - $hasSubscribers = User::query()->where(function ($query) use ($types, $space, $feed) {
70 - $query->whereHas('notificationSubscriptions', function ($query) use ($types, $space) {
71 - $query->whereIn('notification_type', $types)
70 + $hasSubscribers = User::query()->where(function ($query) use ($events, $space, $feed) {
71 + $query->whereHas('notificationPreferences', function ($query) use ($events, $space) {
72 + $query->where('channel', 'mail')
73 + ->whereIn('event_key', $events)
72 74 ->where('object_id', $space->id)
73 - ->where('is_read', 1);
75 + ->where('value', 1);
74 76 });
75 77
76 - do_action_ref_array('fluent_community/space_feed/email_notify_sub_query', [&$query, $feed, $space, $types]);
78 + do_action_ref_array('fluent_community/space_feed/email_notify_sub_query', [&$query, $feed, $space, $events]);
77 79
78 80 return $query;
79 81 })->exists();
80 82
@@ -106,20 +108,21 @@
106 108 if (!$space || !$feed->user) {
107 109 return;
108 110 }
109 111
110 - $types = ['np_by_member_mail'];
112 + $events = ['np_by_member'];
111 113 $spaceRole = $feed->user->getSpaceRole($feed->space);
112 114 if (in_array($spaceRole, ['admin', 'moderator'])) {
113 - $types[] = 'np_by_admin_mail';
115 + $events[] = 'np_by_admin';
114 116 }
115 117
116 118 $lastSendUserId = (int)$feed->getCustomMeta('_last_email_user_id', 0);
117 - $usersQuery = User::query()->where(function ($query) use ($types, $space, $feed) {
118 - $query->whereHas('notificationSubscriptions', function ($query) use ($types, $space) {
119 - $query->whereIn('notification_type', $types)
119 + $usersQuery = User::query()->where(function ($query) use ($events, $space, $feed) {
120 + $query->whereHas('notificationPreferences', function ($query) use ($events, $space) {
121 + $query->where('channel', 'mail')
122 + ->whereIn('event_key', $events)
120 123 ->where('object_id', $space->id)
121 - ->where('is_read', 1);
124 + ->where('value', 1);
122 125 });
123 126
124 127 $mentionedUserIds = Arr::get($feed->meta, 'mentioned_user_ids', []);
125 128
@@ -126,9 +129,9 @@
126 129 if ($mentionedUserIds) {
127 130 $query->orWhereIn('ID', $mentionedUserIds);
128 131 }
129 132
130 - do_action_ref_array('fluent_community/space_feed/email_notify_sub_query', [&$query, $feed, $space, $types]);
133 + do_action_ref_array('fluent_community/space_feed/email_notify_sub_query', [&$query, $feed, $space, $events]);
131 134
132 135 return $query;
133 136 })
134 137 ->whereHas('space_pivot', function ($query) use ($space) {
@@ -149,12 +152,14 @@
149 152 if ($users->isEmpty()) {
150 153 return; // It's done
151 154 }
152 155
156 + $undeliverableEmails = Helper::getUndeliverableEmails($users->pluck('user_email')->toArray());
157 +
153 158 $emailSubject = \sprintf(
154 159 /* translators: %1$s is the author name and %2$s is the post excerpt (max 30 chars) */
155 160 __('New Post By %1$s: %2$s', 'fluent-community'),
156 - $feed->user->getDisplayName(),
161 + $feed->user->getPublicDisplayName(),
157 162 $feed->getHumanExcerpt(30)
158 163 );
159 164
160 165 $emailBody = $feed->getFeedHtml(true);
@@ -174,8 +179,12 @@
174 179 if ($user->ID == $feed->user_id) {
175 180 continue;
176 181 }
177 182
183 + if ($undeliverableEmails && in_array(strtolower($user->user_email), $undeliverableEmails)) {
184 + continue;
185 + }
186 +
178 187 $newEmailBody = str_replace([
179 188 '##feed_permalink##',
180 189 '##email_notification_url##'
181 190 ], [
@@ -236,10 +245,12 @@
236 245 } else {
237 246 $globalCommentStatus = $this->isEnabled('com_my_post_mail');
238 247 }
239 248
249 + $authorId = FeedsHelper::getNotificationAuthorId($feed);
250 +
240 251 $notificationUserIds = [];
241 - if ($comment->user_id != $feed->user_id && NotificationPref::willGetCommentEmail($feed->user_id, $globalCommentStatus)) {
252 + if ($comment->user_id != $authorId && NotificationPref::willGetNotification($authorId, 'comment', 'mail', $globalCommentStatus)) {
242 253 as_schedule_single_action(time(), 'fluent_community/comment_added_async', [$comment->id, 0], 'fluent-community');
243 254 return true;
244 255 }
245 256
@@ -245,9 +256,9 @@
245 256
246 257 if ($comment->parent_id) {
247 258 $notificationUserIds = $comment->getCommentParentUserIds();
248 259 $notificationUserIds = array_filter($notificationUserIds, function ($userId) use ($globalCommentStatus) {
249 - return NotificationPref::willGetCommentReplyEmail($userId, $globalCommentStatus);
260 + return NotificationPref::willGetNotification($userId, 'reply', 'mail', $globalCommentStatus);
250 261 });
251 262 }
252 263
253 264 if (!$notificationUserIds) {
@@ -280,21 +291,22 @@
280 291 }
281 292
282 293 $notificationUserIds = $comment->getCommentParentUserIds($lastUserId);
283 294 $notificationUserIds = array_filter($notificationUserIds, function ($userId) use ($globalCommentStatus) {
284 - return NotificationPref::willGetCommentReplyEmail($userId, $globalCommentStatus);
295 + return NotificationPref::willGetNotification($userId, 'reply', 'mail', $globalCommentStatus);
285 296 });
286 297
287 298 $notificationUserIds = array_diff($notificationUserIds, [$comment->user_id]);
288 - if ($comment->user_id != $feed->user_id && NotificationPref::willGetCommentEmail($feed->user_id, $globalCommentStatus)) {
299 + $authorId = FeedsHelper::getNotificationAuthorId($feed);
300 + if ($comment->user_id != $authorId && NotificationPref::willGetNotification($authorId, 'comment', 'mail', $globalCommentStatus)) {
289 301 // Add at the first
290 - $notificationUserIds[] = $feed->user_id;
302 + $notificationUserIds[] = $authorId;
291 303 }
292 304
293 305 // the mentioned user ids
294 306 if ($mentionedUserIds = Arr::get($comment->meta, 'mentioned_user_ids', [])) {
295 307 foreach ($mentionedUserIds as $mentionedUserId) {
296 - if (NotificationPref::willGetMentionEmail($mentionedUserId, $this->isEnabled('mention_mail'))) {
308 + if (NotificationPref::willGetNotification($mentionedUserId, 'mention', 'mail', $this->isEnabled('mention_mail'))) {
297 309 $notificationUserIds[] = $mentionedUserId;
298 310 }
299 311 }
300 312 }
@@ -318,8 +330,10 @@
318 330 if ($users->isEmpty()) {
319 331 return; // it's done
320 332 }
321 333
334 + $undeliverableEmails = Helper::getUndeliverableEmails($users->pluck('user_email')->toArray());
335 +
322 336 $emailBody = $comment->getCommentHtml(true);
323 337 $emailSubject = $comment->getEmailSubject($feed);
324 338
325 339 $feedPermalik = $feed->getPermalink() . '?comment_id=' . $comment->id;
@@ -332,8 +346,12 @@
332 346 if ($user->ID == $comment->user_id) {
333 347 continue;
334 348 }
335 349
350 + if ($undeliverableEmails && in_array(strtolower($user->user_email), $undeliverableEmails)) {
351 + continue;
352 + }
353 +
336 354 $newEmailBody = str_replace([
337 355 '##feed_permalink##',
338 356 '##email_notification_url##'
339 357 ], [
@@ -406,11 +424,12 @@
406 424 if (!$notification) {
407 425 return true;
408 426 }
409 427
410 - $users = User::whereDoesntHave('notificationSubscriptions', function ($query) {
411 - $query->where('notification_type', 'mention_mail')
412 - ->where('is_read', 0);
428 + $users = User::whereDoesntHave('notificationPreferences', function ($query) {
429 + $query->where('channel', 'mail')
430 + ->where('event_key', 'mention')
431 + ->where('value', 0);
413 432 })
414 433 ->whereHas('space_pivot', function ($query) use ($feed) {
415 434 $query->where('space_id', $feed->space_id)
416 435 ->where('status', 'active');
@@ -428,8 +447,10 @@
428 447 if ($users->isEmpty()) {
429 448 return true; // it's done
430 449 }
431 450
451 + $undeliverableEmails = Helper::getUndeliverableEmails($users->pluck('user_email')->toArray());
452 +
432 453 $author = $feed->user;
433 454
434 455 $emailSubject = \sprintf(
435 456 /* translators: for admin post to send email all space members: %1$s is the feed title, %2$s is the author name and %3$s space name */
@@ -434,9 +455,9 @@
434 455 $emailSubject = \sprintf(
435 456 /* translators: for admin post to send email all space members: %1$s is the feed title, %2$s is the author name and %3$s space name */
436 457 __('%1$s - %2$s [%3$s]', 'fluent-community'),
437 458 $feed->getHumanExcerpt(30),
438 - $author->display_name,
459 + $author->getPublicDisplayName(),
439 460 $feed->space->title
440 461 );
441 462
442 463 $emailBody = $feed->getFeedHtml(true);
@@ -450,8 +471,12 @@
450 471 if ($user->ID == $author->ID) {
451 472 continue;
452 473 }
453 474
475 + if ($undeliverableEmails && in_array(strtolower($user->user_email), $undeliverableEmails)) {
476 + continue;
477 + }
478 +
454 479 $newEmailBody = str_replace([
455 480 '##feed_permalink##',
456 481 '##email_notification_url##'
457 482 ], [
@@ -521,11 +546,12 @@
521 546 $globalEnabled = Arr::get($settings, 'digest_email_status') === 'yes';
522 547 $lastSentUserId = Utility::getOption('last_digest_sent_user_id');
523 548
524 549 if ($globalEnabled) {
525 - $users = User::whereDoesntHave('notification_records', function ($query) {
526 - $query->where('notification_type', 'digest_mail')
527 - ->where('is_read', 0);
550 + $users = User::whereDoesntHave('notificationPreferences', function ($query) {
551 + $query->where('channel', 'mail')
552 + ->where('event_key', 'digest')
553 + ->where('value', 0);
528 554 })
529 555 ->whereHas('xprofile', function ($query) {
530 556 $query->where('status', 'active');
531 557 })
@@ -535,11 +561,12 @@
535 561 ->limit(100)
536 562 ->orderBy('ID', 'ASC')
537 563 ->get();
538 564 } else {
539 - $users = User::whereHas('notification_records', function ($query) {
540 - $query->where('notification_type', 'digest_mail')
541 - ->where('is_read', 1);
565 + $users = User::whereHas('notificationPreferences', function ($query) {
566 + $query->where('channel', 'mail')
567 + ->where('event_key', 'digest')
568 + ->where('value', 1);
542 569 })
543 570 ->whereHas('xprofile', function ($query) {
544 571 $query->where('status', 'active');
545 572 })
@@ -557,8 +584,10 @@
557 584 Utility::updateOption('last_digest_sent_user_id', 0);
558 585 return false;
559 586 }
560 587
588 + $undeliverableEmails = Helper::getUndeliverableEmails($users->pluck('user_email')->toArray());
589 +
561 590 $startAt = microtime(true);
562 591 $maxSendPerSecond = 10;
563 592 $sentCount = 0;
564 593
@@ -563,8 +592,13 @@
563 592 $sentCount = 0;
564 593
565 594 foreach ($users as $user) {
566 595 Utility::updateOption('last_digest_sent_user_id', $user->ID);
596 +
597 + if ($undeliverableEmails && in_array(strtolower($user->user_email), $undeliverableEmails)) {
598 + continue;
599 + }
600 +
567 601 $emailDigest = new DailyDigest($user);
568 602 if ($emailDigest->send()) {
569 603 $sentCount++;
570 604 }
@@ -640,9 +674,9 @@
640 674 $modUserId = $moderatorsUserIds[0];
641 675
642 676 $moderator = get_user_by('ID', $modUserId);
643 677
644 - if (!$moderator || !$moderator->user_email) {
678 + if (!$moderator || !$moderator->user_email || Helper::isUndeliverableEmail($moderator->user_email)) {
645 679 return;
646 680 }
647 681
648 682 $mailer->to($moderator->user_email, $moderator->display_name);
@@ -656,11 +690,17 @@
656 690
657 691 $mailer = new Mailer('', $emailSubject, $emailBody);
658 692
659 693 $users = User::whereIn('ID', $chunk)->get();
694 + $undeliverableEmails = Helper::getUndeliverableEmails($users->pluck('user_email')->toArray());
695 +
660 696 $first = null;
661 697 foreach ($users as $user) {
662 698 if (!$user || !$user->user_email) {
699 + continue;
700 + }
701 +
702 + if ($undeliverableEmails && in_array(strtolower($user->user_email), $undeliverableEmails)) {
663 703 continue;
664 704 }
665 705 if (!$first) {
666 706 $mailer->to($user->user_email, $user->display_name);