@@ -63,7 +63,8 @@ public function __construct(array $apiKeys = array(), $TTL = null, $timeout = nu
63
63
* @param string|null $userPublicKey
64
64
* @param bool $flush If you want to flush directly (usually when you send only one notification)
65
65
*
66
- * @return bool|array Return an array of information if $flush is set to true and the request has failed. Else return true.
66
+ * @return bool|array Return an array of information if $flush is set to true and the request has failed.
67
+ * Else return true.
67
68
* @throws \ErrorException
68
69
*/
69
70
public function sendNotification ($ endpoint , $ payload = null , $ userPublicKey = null , $ flush = false )
@@ -84,12 +85,17 @@ public function sendNotification($endpoint, $payload = null, $userPublicKey = nu
84
85
* Flush notifications. Triggers the requests.
85
86
*
86
87
* @return array|bool If there are no errors, return true.
87
- * Else return an array of information for each notification sent (success, statusCode, headers).
88
+ * If there were no notifications in the queue, return false.
89
+ * Else return an array of information for each notification sent (success, statusCode, headers).
88
90
*
89
91
* @throws \ErrorException
90
92
*/
91
93
public function flush ()
92
94
{
95
+ if (empty ($ this ->notificationsByServerType )) {
96
+ return false ;
97
+ }
98
+
93
99
// if GCM is present, we should check for the API key
94
100
if (array_key_exists ('GCM ' , $ this ->notificationsByServerType )) {
95
101
if (empty ($ this ->apiKeys ['GCM ' ])) {
@@ -142,6 +148,9 @@ public function flush()
142
148
}
143
149
}
144
150
151
+ // reset queue
152
+ $ this ->notificationsByServerType = null ;
153
+
145
154
return $ completeSuccess ? true : $ return ;
146
155
}
147
156
0 commit comments