Example #1
0
 public function shortMessage()
 {
     $ios = new Message();
     $ios->setCustom(['data' => Lorem::text(2000)]);
     $android = new Message();
     $android->setCustom(['data' => Lorem::text(4050)]);
     $android->setPlatforms([Message::PLATFORM_GCM]);
     return [[$ios], [$android]];
 }
 /**
  * @param null $text
  * @param bool $contentAvailable
  * @param array $options
  * @return Message
  */
 public function getMessage($text = null, $contentAvailable = false, $options = [])
 {
     $message = new Message($text);
     $message->setBadge(0);
     if ($contentAvailable) {
         $message->setContentAvailable(true);
     }
     $message->setTtl(self::TTL_ONE_DAY);
     if (count($options)) {
         $message->setCustom($options);
     }
     return $message;
 }
 private function sendPush(RedmineUser $user, $message)
 {
     $message = new Message($message);
     $message->setTtl(86400);
     $message->setBadge(0);
     /** @var Device $device */
     foreach ($user->getDevices() as $device) {
         try {
             $this->messages->send($message, $device->getArn());
         } catch (\Exception $e) {
             $device->setEnabled(false);
             $this->em->flush();
         }
     }
 }
Example #4
0
 /**
  * @dataProvider localizedNoArgs
  */
 public function testLocalizedNoArgsMessageStructure($text, $key)
 {
     $message = new Message($text);
     $message->setLocalizedKey($key);
     $string = (string) $message;
     $data = json_decode($string, true);
     $this->assertEquals($text, $data['default'], 'Default should be just the text of the message');
     $apnsData = json_decode($data['APNS'], true);
     $this->assertCount(1, $apnsData);
     $this->assertCount(1, $apnsData['aps']);
     $this->assertArrayHasKey('alert', $apnsData['aps']);
     $this->assertInternalType('array', $apnsData['aps']['alert']);
     $this->assertCount(1, $apnsData['aps']['alert']);
     $this->assertEquals($key, $apnsData['aps']['alert']['loc-key'], 'APNS.aps.alert.loc-key should be the key of the message');
     $gcmData = json_decode($data['GCM'], true);
     $this->assertCount(4, $gcmData);
     $this->assertCount(2, $gcmData['data']);
     $this->assertEquals($text, $gcmData['data']['message'], 'GCM.data.message should be the text of the message');
     $this->assertEquals($key, $gcmData['data']['message-loc-key'], 'GCM.data.message-loc-key should be the key of the message');
     $admData = json_decode($data['ADM'], true);
     $this->assertCount(1, $admData);
     $this->assertCount(2, $admData['data']);
     $this->assertEquals($text, $admData['data']['message'], 'ADM.data.message should be the text of the message');
     $this->assertEquals($key, $admData['data']['message-loc-key'], 'ADM.data.message-loc-key should be the key of the message');
 }
Example #5
0
 private function getMessageForTweet($tweet)
 {
     $m = new Message($tweet['text']);
     $custom = ['i' => $tweet['id_str']];
     //Check for links in the tweet
     foreach (['urls', 'media'] as $entity) {
         if (isset($tweet['entities']) && isset($tweet['entities'][$entity]) && isset($tweet['entities'][$entity][0])) {
             $entity = $tweet['entities'][$entity][0];
             $custom['u'] = $entity['url'];
             //Remove the link from the text to save space
             $newText = trim(mb_substr($tweet['text'], 0, $entity['indices'][0], 'utf8') . ($this->linkPlaceholder ?: '') . mb_substr($tweet['text'], $entity['indices'][1], null, 'utf8'));
             if ($newText != '') {
                 $m->setText($newText);
             }
             break;
         }
     }
     $m->setCustom($custom);
     $m->setTtl($this->gcmTtl);
     return $m;
 }
Example #6
0
 /**
  * @dataProvider ttl
  */
 public function testTtl($ttl)
 {
     $message = new Message(Lorem::text(1000));
     $message->setTtl($ttl);
     $string = (string) $message;
     $data = json_decode($string, true);
     $gcmData = json_decode($data['GCM'], true);
     $this->assertEquals($ttl, $gcmData['time_to_live']);
     $admData = json_decode($data['ADM'], true);
     $this->assertEquals($ttl, $admData['expiresAfter']);
 }