diff --git a/api/src/Json/Push.php b/api/src/Json/Push.php index 9d504e2916..f8b1b8656d 100644 --- a/api/src/Json/Push.php +++ b/api/src/Json/Push.php @@ -36,7 +36,7 @@ class Push extends Msg /** * account_id we are pushing too * - * @var int + * @var int|int[] */ protected $account_id; @@ -63,7 +63,7 @@ class Push extends Msg /** * - * @param int $account_id =null account_id to push message too or + * @param ?int|int[] $account_id =null account_id(s) to push message too or * self::SESSION(=null): for current session only or self::ALL(=0) for whole instance / broadcast */ public function __construct($account_id=self::SESSION) diff --git a/api/src/Json/PushBackend.php b/api/src/Json/PushBackend.php index 3e6f9402fe..b7be149266 100644 --- a/api/src/Json/PushBackend.php +++ b/api/src/Json/PushBackend.php @@ -20,8 +20,7 @@ interface PushBackend /** * Adds any type of data to the message * - * @param int $account_id =null account_id to push message too or - * null: for current session only or 0 for whole instance / broadcast + * @param ?int|int[] $account_id account_id(s) to push message too, null: session, 0: whole instance * @param string $key * @param mixed $data * @throws Exception\NotOnline if $account_id is not online diff --git a/notifications/inc/class.notifications_push.inc.php b/notifications/inc/class.notifications_push.inc.php index 870392a325..70d62efece 100644 --- a/notifications/inc/class.notifications_push.inc.php +++ b/notifications/inc/class.notifications_push.inc.php @@ -86,8 +86,7 @@ class notifications_push implements Json\PushBackend /** * Adds any type of data to the message * - * @param int|null $account_id account_id to push message too, 0 for broadcast - * or null for curent session (we can only send to current user) + * @param ?int|int[] $account_id account_id(s) to push message too, null: session, 0: whole instance * @param string $key * @param mixed $data * @@ -99,23 +98,26 @@ class notifications_push implements Json\PushBackend { if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id']; - self::$db->insert(self::TABLE, array( - 'account_id' => $account_id, - 'notify_type' => self::TYPE, - 'notify_message' => json_encode(array( - 'method' => $key, - 'data' => $data, - )), - ), false, __LINE__, __FILE__, self::APP); + foreach((array)$account_id as $account_id) + { + self::$db->insert(self::TABLE, array( + 'account_id' => $account_id, + 'notify_type' => self::TYPE, + 'notify_message' => json_encode(array( + 'method' => $key, + 'data' => $data, + )), + ), false, __LINE__, __FILE__, self::APP); + } - // cache highest id, to not poll database + // cache the highest id, to not poll database Api\Cache::setInstance(__CLASS__, 'max_id', self::$db->get_last_insert_id(self::TABLE, 'notify_id')); self::cleanup_push_msgs(); } /** - * Delete push messges older then our heartbeat-limit (poll frequency of notifications) + * Delete push messages older then our heartbeat-limit (poll frequency of notifications) */ protected static function cleanup_push_msgs() {