allow pushing to multiple users in one request

This commit is contained in:
Ralf Becker 2021-08-31 17:42:28 +02:00
parent 264d22599d
commit c830bdd923
3 changed files with 17 additions and 16 deletions

View File

@ -36,7 +36,7 @@ class Push extends Msg
/** /**
* account_id we are pushing too * account_id we are pushing too
* *
* @var int * @var int|int[]
*/ */
protected $account_id; 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 * self::SESSION(=null): for current session only or self::ALL(=0) for whole instance / broadcast
*/ */
public function __construct($account_id=self::SESSION) public function __construct($account_id=self::SESSION)

View File

@ -20,8 +20,7 @@ interface PushBackend
/** /**
* Adds any type of data to the message * Adds any type of data to the message
* *
* @param int $account_id =null account_id to push message too or * @param ?int|int[] $account_id account_id(s) to push message too, null: session, 0: whole instance
* null: for current session only or 0 for whole instance / broadcast
* @param string $key * @param string $key
* @param mixed $data * @param mixed $data
* @throws Exception\NotOnline if $account_id is not online * @throws Exception\NotOnline if $account_id is not online

View File

@ -86,8 +86,7 @@ class notifications_push implements Json\PushBackend
/** /**
* Adds any type of data to the message * Adds any type of data to the message
* *
* @param int|null $account_id account_id to push message too, 0 for broadcast * @param ?int|int[] $account_id account_id(s) to push message too, null: session, 0: whole instance
* or null for curent session (we can only send to current user)
* @param string $key * @param string $key
* @param mixed $data * @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']; if (!isset($account_id)) $account_id = $GLOBALS['egw_info']['user']['account_id'];
self::$db->insert(self::TABLE, array( foreach((array)$account_id as $account_id)
'account_id' => $account_id, {
'notify_type' => self::TYPE, self::$db->insert(self::TABLE, array(
'notify_message' => json_encode(array( 'account_id' => $account_id,
'method' => $key, 'notify_type' => self::TYPE,
'data' => $data, 'notify_message' => json_encode(array(
)), 'method' => $key,
), false, __LINE__, __FILE__, self::APP); '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')); Api\Cache::setInstance(__CLASS__, 'max_id', self::$db->get_last_insert_id(self::TABLE, 'notify_id'));
self::cleanup_push_msgs(); 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() protected static function cleanup_push_msgs()
{ {