diff --git a/.gitignore b/.gitignore index 83713b9..e12f586 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor .phpunit.result.cache composer.lock +.idea/ diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Android.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Android.php index c6322ed..ed89f8c 100644 --- a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Android.php +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Android.php @@ -22,7 +22,7 @@ class Android implements \JsonSerializable * @var int */ private $badges; - + private $banner; private $customIcon; @@ -33,24 +33,31 @@ class Android implements \JsonSerializable * @var int */ private $gcmTtl; + + /** + * Identifier to group related notifications. + * Messages with the same thread ID will be grouped in the Notification Center. + */ + private ?string $groupId; + private $header; - + /** * The icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc. * * @var string */ private $ibc; - + private $icon; - + /** * The LED hex color, device will do its best approximation. * * @var string */ private $led; - + /** * The priority of the push in the Android push drawer, valid values are -2, -1, 0, 1 and 2. * @@ -60,7 +67,7 @@ class Android implements \JsonSerializable private $rootParams; private $sound; - + /** * A boolean used to force vibration for high-priority pushes. * @@ -113,12 +120,17 @@ public function getGcmTtl() } + public function getGroupId(): ?string + { + return $this->groupId; + } + public function getHeader() { return $this->header; } - + /** * Gets the icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc. * @@ -133,7 +145,7 @@ public function getIcon() { return $this->icon; } - + /** * Gets the LED hex color, device will do its best approximation. * @@ -143,7 +155,7 @@ public function getLed() { return $this->led; } - + /** * Gets priority of the push in the Android push drawer, valid values are -2, -1, 0, 1 and 2. * @@ -163,7 +175,7 @@ public function getSound() { return $this->sound; } - + /** * Gets the boolean used to force vibration for high-priority pushes. * @@ -173,14 +185,14 @@ public function isVibration() { return $this->vibration; } - + /** * {@inheritdoc} */ public function jsonSerialize(): mixed { $json = []; - + isset($this->badges) ? $json['android_badges'] = $this->badges : false; isset($this->banner) ? $json['android_banner'] = $this->banner : false; isset($this->customIcon) ? $json['android_custom_icon'] = $this->customIcon : false; @@ -193,9 +205,13 @@ public function jsonSerialize(): mixed isset($this->rootParams) ? $json['android_root_params'] = $this->rootParams : false; isset($this->sound) ? $json['android_sound'] = $this->sound : false; isset($this->vibration) ? $json['android_vibration'] = ($this->vibration ? 1 : 0) : false; - + + if ($this->groupId !== null) { + $json['android_group_id'] = $this->groupId; + } + return $json; - + } /** @@ -208,7 +224,7 @@ public function jsonSerialize(): mixed public function setBadges($badges) { $this->badges = $badges; - + return $this; } @@ -242,6 +258,13 @@ public function setGcmTtl($gcmTtl) return $this; } + public function setGroupId(?string $groupId): self + { + $this->groupId = $groupId; + + return $this; + } + public function setHeader($header) { $this->header = $header; @@ -249,7 +272,7 @@ public function setHeader($header) return $this; } - + /** * Sets the icon background color on Lollipop, #RRGGBB, #AARRGGBB, "red", "black", "yellow", etc. * @@ -260,7 +283,7 @@ public function setHeader($header) public function setIbc($ibc) { $this->ibc = $ibc; - + return $this; } @@ -270,7 +293,7 @@ public function setIcon($icon) return $this; } - + /** * Sets the LED hex color, device will do its best approximation. * @@ -281,10 +304,10 @@ public function setIcon($icon) public function setLed($led) { $this->led = $led; - + return $this; } - + /** * Sets the priority of the push in the Android push drawer, valid values are -2, -1, 0, 1 and 2. * @@ -295,7 +318,7 @@ public function setLed($led) public function setPriority($priority) { $this->priority = $priority; - + return $this; } @@ -312,7 +335,7 @@ public function setSound($sound) return $this; } - + /** * Sets the boolean used to force vibration for high-priority pushes. * @@ -323,7 +346,7 @@ public function setSound($sound) public function setVibration($vibration) { $this->vibration = $vibration; - + return $this; } } diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php index ab5c7af..9e51e6e 100644 --- a/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/Huawei.php @@ -24,6 +24,12 @@ final class Huawei implements \JsonSerializable */ private $gcmTtl; + /** + * Identifier to group related notifications. + * Messages with the same thread ID will be grouped in the Notification Center. + */ + private ?string $groupId; + /** * @var string|null */ @@ -89,6 +95,11 @@ public function getGcmTtl() return $this->gcmTtl; } + public function getGroupId(): ?string + { + return $this->groupId; + } + public function getHeader() { return $this->header; @@ -149,6 +160,10 @@ public function jsonSerialize(): mixed $json['huawei_android_gcm_ttl'] = $this->gcmTtl; } + if ($this->groupId !== null) { + $json['huawei_android_group_id'] = $this->groupId; + } + if ($this->header !== null) { $json['huawei_android_header'] = $this->header; } @@ -212,6 +227,13 @@ public function setGcmTtl($gcmTtl) return $this; } + public function setGroupId(?string $groupId): self + { + $this->groupId = $groupId; + + return $this; + } + public function setHeader($header) { $this->header = $header; diff --git a/src/main/php/Gomoob/Pushwoosh/Model/Notification/IOS.php b/src/main/php/Gomoob/Pushwoosh/Model/Notification/IOS.php index 8671867..9a74f99 100644 --- a/src/main/php/Gomoob/Pushwoosh/Model/Notification/IOS.php +++ b/src/main/php/Gomoob/Pushwoosh/Model/Notification/IOS.php @@ -23,16 +23,23 @@ class IOS implements \JsonSerializable private $apnsTrimContent; private $badges; - + /** * The iOS 8 category ID from Pushwoosh. * * @var int */ private $categoryId; - + private $rootParams; private $sound; + + /** + * Identifier to group related notifications. + * Messages with the same thread ID will be grouped on the lock screen and in the Notification Center. + */ + private ?string $threadId; + private $ttl; private $trimContent; @@ -50,7 +57,7 @@ public function getBadges() { return $this->badges; } - + /** * Gets the iOS 8 category ID from Pushwoosh. * @@ -72,6 +79,11 @@ public function getSound() } + public function getThreadId(): ?string + { + return $this->threadId; + } + public function getTtl() { return $this->ttl; @@ -93,14 +105,14 @@ public function isTrimContent() return $this->trimContent; } - + /** * {@inheritdoc} */ public function jsonSerialize(): mixed { $json = []; - + isset($this->apnsTrimContent) ? $json['apns_trim_content'] = intval($this->apnsTrimContent) : false; isset($this->badges) ? $json['ios_badges'] = $this->badges : false; isset($this->categoryId) ? $json['ios_category_id'] = $this->categoryId : false; @@ -108,9 +120,13 @@ public function jsonSerialize(): mixed isset($this->sound) ? $json['ios_sound'] = $this->sound : false; isset($this->ttl) ? $json['ios_ttl'] = $this->ttl : false; isset($this->trimContent) ? $json['ios_trim_content'] = intval($this->trimContent) : false; - + + if ($this->threadId !== null) { + $json['ios_thread_id'] = $this->threadId; + } + return $json; - + } /** @@ -135,7 +151,7 @@ public function setBadges($badges) return $this; } - + /** * Sets the iOS 8 category ID from Pushwoosh. * @@ -146,7 +162,7 @@ public function setBadges($badges) public function setCategoryId($categoryId) { $this->categoryId = $categoryId; - + return $this; } @@ -165,6 +181,13 @@ public function setSound($sound) return $this; } + public function setThreadId(?string $threadId): self + { + $this->threadId = $threadId; + + return $this; + } + public function setTtl($ttl) { $this->ttl = $ttl; diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/AndroidTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/AndroidTest.php index a5ea5f7..4078ff7 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/AndroidTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/AndroidTest.php @@ -25,7 +25,7 @@ public function testCreate() { $this->assertNotNull(Android::create()); } - + /** * Test method for the #getBadges() and setBadges($badges) functions. */ @@ -66,6 +66,13 @@ public function testGetSetGcmTtl() $this->assertSame(3600, $android->getGcmTtl()); } + public function testGetSetGroupId() + { + $android = new Android(); + $this->assertSame($android, $android->setGroupId('test_group')); + $this->assertSame('test_group', $android->getGroupId()); + } + /** * Test method for the #getHeader() and #setHeader($header) functions. */ @@ -85,7 +92,7 @@ public function testGetSetIbc() $this->assertSame($android, $android->setIbc('#AA9966')); $this->assertSame('#AA9966', $android->getIbc()); } - + /** * Test method for the #getIcon() and #setIcon($icon) functions. */ @@ -105,7 +112,7 @@ public function testGetSetLed() $this->assertSame($android, $android->setLed('#4455cc')); $this->assertSame('#4455cc', $android->getLed()); } - + /** * Test method for the #getPriority() and #setPriority($priority) functions. */ @@ -115,7 +122,7 @@ public function testGetSetPriority() $this->assertSame($android, $android->setPriority(-1)); $this->assertSame(-1, $android->getPriority()); } - + /** * Test method for the #getRootParams() and #setRootParams($rootParams) functions. */ @@ -145,7 +152,7 @@ public function testIsSetVibration() $this->assertSame($android, $android->setVibration(true)); $this->assertTrue($android->isVibration()); } - + /** * Test method for the #jsonSerialize() function. */ @@ -156,6 +163,7 @@ public function testJsonSerialize() ->setBadges(5) ->setCustomIcon('http://example.com/image.png') ->setGcmTtl(3600) + ->setGroupId('test_group') ->setHeader('Header') ->setIbc('#AA9966') ->setIcon('icon') @@ -166,11 +174,12 @@ public function testJsonSerialize() ->setVibration(true) ->jsonSerialize(); - $this->assertCount(12, $array); + $this->assertCount(13, $array); $this->assertSame('http://example.com/banner.png', $array['android_banner']); $this->assertSame(5, $array['android_badges']); $this->assertSame('http://example.com/image.png', $array['android_custom_icon']); $this->assertSame(3600, $array['android_gcm_ttl']); + $this->assertSame('test_group', $array['android_group_id']); $this->assertSame('Header', $array['android_header']); $this->assertSame('#AA9966', $array['android_ibc']); $this->assertSame('icon', $array['android_icon']); diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php index dac94ef..3738724 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/HuaweiTest.php @@ -39,6 +39,13 @@ public function testGetSetGcmTtl() $this->assertSame(3600, $huawei->getGcmTtl()); } + public function testGetSetGroupId() + { + $huawei = new Huawei(); + $this->assertSame($huawei, $huawei->setGroupId('test_group')); + $this->assertSame('test_group', $huawei->getGroupId()); + } + public function testGetSetHeader() { $huawei = new Huawei(); @@ -102,6 +109,7 @@ public function testJsonSerialize() ->setBadges(5) ->setCustomIcon('http://example.com/image.png') ->setGcmTtl(3600) + ->setGroupId('test_group') ->setHeader('Header') ->setIbc('#AA9966') ->setIcon('icon') @@ -112,11 +120,12 @@ public function testJsonSerialize() ->setVibration(true) ->jsonSerialize(); - $this->assertCount(12, $array); + $this->assertCount(13, $array); $this->assertSame('http://example.com/banner.png', $array['huawei_android_banner']); $this->assertSame(5, $array['huawei_android_badges']); $this->assertSame('http://example.com/image.png', $array['huawei_android_custom_icon']); $this->assertSame(3600, $array['huawei_android_gcm_ttl']); + $this->assertSame('test_group', $array['huawei_android_group_id']); $this->assertSame('Header', $array['huawei_android_header']); $this->assertSame('#AA9966', $array['huawei_android_ibc']); $this->assertSame('icon', $array['huawei_android_icon']); diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/IOSTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/IOSTest.php index 91a7a43..467413f 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/IOSTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/IOSTest.php @@ -35,7 +35,7 @@ public function testGetSetBadges() $this->assertSame($iOS, $iOS->setBadges(5)); $this->assertSame(5, $iOS->getBadges()); } - + /** * Test method for the #getCategoryId() and #setCategoryId($categoryId) functions. */ @@ -66,6 +66,13 @@ public function testGetSetSound() $this->assertSame('sound file.wav', $iOS->getSound()); } + public function testGetSetThreadId() + { + $iOS = new IOS(); + $this->assertSame($iOS, $iOS->setThreadId('test_thread')); + $this->assertSame('test_thread', $iOS->getThreadId()); + } + /** * Test method for the #getTtl() and #setTtl($ttl) functions. */ @@ -108,16 +115,18 @@ public function testJsonSerialize() ->setCategoryId('1') ->setRootParams(['aps' => ['content-available' => '1']]) ->setSound('sound file.wav') + ->setThreadId('test_thread') ->setTtl(3600) ->setTrimContent(true) ->jsonSerialize(); - $this->assertCount(7, $array); + $this->assertCount(8, $array); $this->assertSame(1, $array['apns_trim_content']); $this->assertSame(5, $array['ios_badges']); $this->assertSame('1', $array['ios_category_id']); $this->assertSame(['aps' => ['content-available' => '1']], $array['ios_root_params']); $this->assertSame('sound file.wav', $array['ios_sound']); + $this->assertSame('test_thread', $array['ios_thread_id']); $this->assertSame(3600, $array['ios_ttl']); $this->assertSame(1, $array['ios_trim_content']); } diff --git a/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php b/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php index 0e62d35..8feb71b 100644 --- a/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php +++ b/src/test/php/Gomoob/Pushwoosh/Model/Notification/NotificationTest.php @@ -537,6 +537,7 @@ public function testJsonSerialize() ->setBanner('http://example.com/banner.png') ->setCustomIcon('http://example.com/image.png') ->setGcmTtl(3600) + ->setGroupId('test_group') ->setHeader('Header') ->setIbc('#AA9966') ->setIcon('icon') @@ -552,6 +553,7 @@ public function testJsonSerialize() ->setBanner('http://example.com/banner.png') ->setCustomIcon('http://example.com/image.png') ->setGcmTtl(3600) + ->setGroupId('test_group') ->setHeader('Header') ->setIbc('#AA9966') ->setIcon('icon') @@ -579,6 +581,7 @@ public function testJsonSerialize() ->setCategoryId('1') ->setRootParams(['aps' => ['content-available' => '1']]) ->setSound('sound file.wav') + ->setThreadId('test_thread') ->setTtl(3600) ->setTrimContent(true) ) @@ -619,7 +622,7 @@ public function testJsonSerialize() ->jsonSerialize(); // Test the generic properties - $this->assertCount(77, $array); + $this->assertCount(80, $array); $this->assertSame('now', $array['send_date']); $this->assertSame('America/New_York', $array['timezone']); $this->assertTrue($array['ignore_user_timezone']); @@ -681,6 +684,7 @@ public function testJsonSerialize() $this->assertSame('http://example.com/banner.png', $array['android_banner']); $this->assertSame('http://example.com/image.png', $array['android_custom_icon']); $this->assertSame(3600, $array['android_gcm_ttl']); + $this->assertSame('test_group', $array['android_group_id']); $this->assertSame('Header', $array['android_header']); $this->assertSame('#AA9966', $array['android_ibc']); $this->assertSame('icon', $array['android_icon']); @@ -695,6 +699,7 @@ public function testJsonSerialize() $this->assertSame('http://example.com/banner.png', $array['huawei_android_banner']); $this->assertSame('http://example.com/image.png', $array['huawei_android_custom_icon']); $this->assertSame(3600, $array['huawei_android_gcm_ttl']); + $this->assertSame('test_group', $array['huawei_android_group_id']); $this->assertSame('Header', $array['huawei_android_header']); $this->assertSame('#AA9966', $array['huawei_android_ibc']); $this->assertSame('icon', $array['huawei_android_icon']); @@ -719,6 +724,7 @@ public function testJsonSerialize() $this->assertSame('1', $array['ios_category_id']); $this->assertSame(['aps' => ['content-available' => '1']], $array['ios_root_params']); $this->assertSame('sound file.wav', $array['ios_sound']); + $this->assertSame('test_thread', $array['ios_thread_id']); $this->assertSame(3600, $array['ios_ttl']); $this->assertSame(1, $array['ios_trim_content']);