@@ -60,7 +60,8 @@ public function __construct(array $apiKeys = array(), $TTL = null, $timeout = nu
60
60
* @param string|null $userPublicKey
61
61
* @param bool $flush If you want to flush directly (usually when you send only one notification)
62
62
*
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.
64
65
* @throws \ErrorException
65
66
*/
66
67
public function sendNotification ($ endpoint , $ payload = null , $ userPublicKey = null , $ flush = false )
@@ -81,12 +82,17 @@ public function sendNotification($endpoint, $payload = null, $userPublicKey = nu
81
82
* Flush notifications. Triggers the requests.
82
83
*
83
84
* @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).
85
87
*
86
88
* @throws \ErrorException
87
89
*/
88
90
public function flush ()
89
91
{
92
+ if (empty ($ this ->notificationsByServerType )) {
93
+ return false ;
94
+ }
95
+
90
96
// if GCM is present, we should check for the API key
91
97
if (array_key_exists ('GCM ' , $ this ->notificationsByServerType )) {
92
98
if (empty ($ this ->apiKeys ['GCM ' ])) {
@@ -139,6 +145,9 @@ public function flush()
139
145
}
140
146
}
141
147
148
+ // reset queue
149
+ $ this ->notificationsByServerType = null ;
150
+
142
151
return $ completeSuccess ? true : $ return ;
143
152
}
144
153
0 commit comments