File tree Expand file tree Collapse file tree 2 files changed +55
-0
lines changed
Expand file tree Collapse file tree 2 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ class PushwooshMessage implements JsonSerializable
2424 protected $ throughput ;
2525 protected $ url ;
2626 protected $ when ;
27+ protected $ androidSilent = null ;
28+ protected $ iosSilent = null ;
2729
2830 /**
2931 * Create a new push message.
@@ -150,6 +152,8 @@ public function jsonSerialize()
150152 'send_rate ' => $ this ->throughput ,
151153 'transactionId ' => $ this ->identifier ,
152154 'timezone ' => $ this ->timezone ,
155+ 'ios_silent ' => $ this ->iosSilent ,
156+ 'android_silent ' => $ this ->androidSilent ,
153157 ];
154158
155159 return array_filter ($ payload , function ($ value ) {
@@ -248,4 +252,23 @@ public function useRecipientTimezone()
248252
249253 return $ this ;
250254 }
255+
256+ /**
257+ * Enable or disable silent notifications for both Android and iOS platforms.
258+ *
259+ * @param bool $silent
260+ * @return $this
261+ */
262+ public function silent (bool $ silent = true )
263+ {
264+ if ($ silent ) {
265+ $ this ->androidSilent = 1 ;
266+ $ this ->iosSilent = 1 ;
267+ } else {
268+ $ this ->androidSilent = null ;
269+ $ this ->iosSilent = null ;
270+ }
271+
272+ return $ this ;
273+ }
251274}
Original file line number Diff line number Diff line change @@ -271,4 +271,36 @@ public function testTimezoneStrategyModification()
271271 $ message = (new PushwooshMessage )->useRecipientTimezone ();
272272 $ this ->assertFalse ($ message ->jsonSerialize ()['ignore_user_timezone ' ]);
273273 }
274+
275+ /**
276+ * Test modification of the silent parameters .
277+ *
278+ * @return void
279+ */
280+ public function testSilentModification ()
281+ {
282+ $ message = new PushwooshMessage ();
283+ $ message ->silent ();
284+ $ this ->assertArrayHasKey ('ios_silent ' , $ message ->jsonSerialize ());
285+ $ this ->assertEquals (1 , $ message ->jsonSerialize ()['ios_silent ' ]);
286+ $ this ->assertArrayHasKey ('android_silent ' , $ message ->jsonSerialize ());
287+ $ this ->assertEquals (1 , $ message ->jsonSerialize ()['android_silent ' ]);
288+ }
289+
290+ /**
291+ * Test modification of the silent parameters .
292+ *
293+ * @return void
294+ */
295+ public function testSilentModificationNull ()
296+ {
297+ $ message = new PushwooshMessage ();
298+
299+ $ this ->assertArrayNotHasKey ('ios_silent ' , $ message ->jsonSerialize ());
300+ $ this ->assertArrayNotHasKey ('android_silent ' , $ message ->jsonSerialize ());
301+
302+ $ message ->silent ()->silent (false );
303+ $ this ->assertArrayNotHasKey ('ios_silent ' , $ message ->jsonSerialize ());
304+ $ this ->assertArrayNotHasKey ('android_silent ' , $ message ->jsonSerialize ());
305+ }
274306}
You can’t perform that action at this time.
0 commit comments