PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.10.0
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.10.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
← All changes | Modules/PushNotification/PushNotificationModule.php +33 -11 2.9.12.10.0 View file →
@@ -4,14 +4,14 @@
4 4
5 5 use FluentCommunity\App\Functions\Utility;
6 6 use FluentCommunity\App\Services\Helper;
7 7 use FluentCommunity\App\Services\NotificationPref;
8 -use FluentCommunity\App\Services\OnboardingService;
9 8 use FluentCommunity\Framework\Support\Arr;
10 9
11 10 class PushNotificationModule
12 11 {
13 12 const SETUP_NOT_INSTALLED = 'not_installed';
13 + const SETUP_INACTIVE = 'inactive';
14 14 const SETUP_DISABLED = 'disabled';
15 15 const SETUP_INCOMPLETE = 'incomplete';
16 16 const SETUP_READY = 'ready';
17 17
@@ -23,8 +23,10 @@
23 23 'fluent_community/notification/comment/notifed_to_thread_commetenter',
24 24 'fluent_community/notification/comment/notifed_to_other_users'
25 25 ];
26 26
27 + const PUSHED_ACTIONS = ['comment_added', 'child_comment_added', 'mention_added'];
28 +
27 29 public static function isFluentNotifyActive()
28 30 {
29 31 return self::getSetupState() === self::SETUP_READY;
30 32 }
@@ -37,8 +39,14 @@
37 39 */
38 40 public static function getSetupState()
39 41 {
40 42 if (!defined('FLUENT_NOTIFY_PLUGIN_VERSION')) {
43 + // The files can be there while the plugin is deactivated, which needs
44 + // activating rather than another download.
45 + if (file_exists(WP_PLUGIN_DIR . '/fluent-notify/fluent-notify.php')) {
46 + return self::SETUP_INACTIVE;
47 + }
48 +
41 49 return self::SETUP_NOT_INSTALLED;
42 50 }
43 51
44 52 if (!\FluentNotify\App\Services\Helper::isEnabled()) {
@@ -65,18 +73,28 @@
65 73
66 74 return self::isFluentNotifyActive() && $pushEnabledInCommunity;
67 75 }
68 76
77 + public static function getPushedCommentIds($userId, $commentIds)
78 + {
79 + if (!$userId || !$commentIds || !class_exists('\FluentNotify\App\Models\NotificationLog')) {
80 + return [];
81 + }
82 +
83 + $pushed = \FluentNotify\App\Models\NotificationLog::query()
84 + ->join('fn_subscriptions', 'fn_subscriptions.id', '=', 'fn_notifications.subscription_id')
85 + ->where('fn_subscriptions.user_id', $userId)
86 + ->where('fn_notifications.source', 'community_comment')
87 + ->whereIn('fn_notifications.source_id', $commentIds)
88 + ->whereNotIn('fn_notifications.status', ['fcm_failed', 'fcm_skipped'])
89 + ->pluck('fn_notifications.source_id')
90 + ->toArray();
91 +
92 + return array_values(array_unique(array_map('intval', $pushed)));
93 + }
94 +
69 95 public function register()
70 96 {
71 - add_action('fluent_community/install_fluent_notify_plugin', function () {
72 - OnboardingService::backgroundInstaller([
73 - 'name' => 'Fluent Notify',
74 - 'repo-slug' => 'fluent-notify',
75 - 'file' => 'fluent-notify.php'
76 - ], 'https://fluentapi.wpmanageninja.com/addons/download/fluent-notify/1.0.0.zip');
77 - });
78 -
79 97 if (!self::isAvailable()) return;
80 98
81 99 foreach (self::COMMENT_ACTIONS as $action) {
82 100 add_action($action, [$this, 'handleCommentNotification'], 10, 1);
@@ -174,15 +192,19 @@
174 192 /* translators: %1$s is the commenter name, %2$s is the post title */
175 193 $content = \sprintf(__('Comment by %1$s on %2$s', 'fluent-community'), $commenter, $feedTitle);
176 194 endswitch;
177 195
178 - $feedPermalik = $feed->getPermalink() . '?comment_id=' . $comment->id;
196 + $actionUrl = add_query_arg([
197 + 'comment_id' => $comment->id,
198 + 'fcom_pn' => 'true',
199 + 'feed_id' => $feed->id,
200 + ], $feed->getPermalink());
179 201
180 202 do_action('fluent_notify/schedule_notifications', $userIds, [
181 203 'user_ids' => $userIds,
182 204 'title' => $title,
183 205 'message' => $content,
184 - 'action_url' => $feedPermalik,
206 + 'action_url' => $actionUrl,
185 207 'icon' => $xprofile->avatar,
186 208 'source' => 'community_comment',
187 209 'source_id' => $comment->id,
188 210 ]);