From 3972abdf52299d861060cf2b1d80d5816b9419c6 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 31 Jul 2020 17:50:01 +0200 Subject: [PATCH] * Notifications: taking push server into account for checking user is online for popup or email notifications --- api/src/Json/Push.php | 10 ++++++++++ notifications/inc/class.notifications.inc.php | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/api/src/Json/Push.php b/api/src/Json/Push.php index cd4eb987a6..50b81c2ac8 100644 --- a/api/src/Json/Push.php +++ b/api/src/Json/Push.php @@ -104,6 +104,16 @@ class Push extends Msg return self::$online; } + /** + * Get given user is online / connected to push-server + * + * @return boolean + */ + public function isOnline($account_id) + { + return in_array($account_id, $this->online()); + } + /** * Check and if neccessary set push backend * diff --git a/notifications/inc/class.notifications.inc.php b/notifications/inc/class.notifications.inc.php index 84ec2ac23c..ac9ecec83c 100644 --- a/notifications/inc/class.notifications.inc.php +++ b/notifications/inc/class.notifications.inc.php @@ -489,6 +489,7 @@ class notifications { Api\Translation::add_app('notifications'); $available_chains = $this->get_available_chains('routing'); + $push = new Api\Json\Push(); foreach ($this->receivers as $receiver) { $user_notified = false; @@ -574,7 +575,7 @@ class notifications { // This is to make popup_or_email option sensfull since // we save popup notifications in database anyway, email // notifications should be based on user availability. - if ($backend == 'popup' && $action== 'fail' && !Api\Session::notifications_active($receiver->account_id)) + if ($backend === 'popup' && $action === 'fail' && !$push->isOnline($receiver->account_id)) { throw new Exception(); }