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