@@ -60,7 +60,8 @@ public function __construct(array $apiKeys = array(), $TTL = null, $timeout = nu
6060 * @param string|null $userPublicKey
6161 * @param bool $flush If you want to flush directly (usually when you send only one notification)
6262 *
63- * @return bool|array Return an array of information if $flush is set to true and the request has failed. Else return true.
63+ * @return bool|array Return an array of information if $flush is set to true and the request has failed.
64+ * Else return true.
6465 * @throws \ErrorException
6566 */
6667 public function sendNotification ($ endpoint , $ payload = null , $ userPublicKey = null , $ flush = false )
@@ -81,12 +82,17 @@ public function sendNotification($endpoint, $payload = null, $userPublicKey = nu
8182 * Flush notifications. Triggers the requests.
8283 *
8384 * @return array|bool If there are no errors, return true.
84- * Else return an array of information for each notification sent (success, statusCode, headers).
85+ * If there were no notifications in the queue, return false.
86+ * Else return an array of information for each notification sent (success, statusCode, headers).
8587 *
8688 * @throws \ErrorException
8789 */
8890 public function flush ()
8991 {
92+ if (empty ($ this ->notificationsByServerType )) {
93+ return false ;
94+ }
95+
9096 // if GCM is present, we should check for the API key
9197 if (array_key_exists ('GCM ' , $ this ->notificationsByServerType )) {
9298 if (empty ($ this ->apiKeys ['GCM ' ])) {
@@ -139,6 +145,9 @@ public function flush()
139145 }
140146 }
141147
148+ // reset queue
149+ $ this ->notificationsByServerType = null ;
150+
142151 return $ completeSuccess ? true : $ return ;
143152 }
144153
0 commit comments