/**
  * @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;
 }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
 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();
         }
     }
 }
Exemplo n.º 4
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']);
 }