コード例 #1
0
 public function sendNotify(Message $message, RedmineUser $user)
 {
     if ($user->getDevices()->count()) {
         /** @var Device $device */
         foreach ($user->getDevices() as $device) {
             if ($device->isEnabled()) {
                 $logMessage = 'platform not found';
                 $logCustom = 'custom';
                 if ($device->getPlatform() === self::PLATFORM_ANDROID) {
                     $logMessage = $message->getGcmData();
                     $logCustom = $message->getCustom();
                 }
                 if ($device->getPlatform() === self::PLATFORM_IOS) {
                     $logMessage = $message->getApnsData();
                     $logCustom = $message->getCustom();
                 }
                 if ($device->getPlatform() === self::PLATFORM_IOS_SB) {
                     $logMessage = $message->getApnsData();
                     $logCustom = $message->getCustom();
                 }
                 try {
                     $this->messages->send($message, $device->getArn());
                     $this->logger->info("\nSend message to: ", ['DEVICE' => $device->toLog(), 'MESSAGE' => $logMessage, 'CUSTOM' => $logCustom]);
                 } catch (\Exception $e) {
                     $device->setEnabled(false);
                     $this->em->flush();
                     $this->logger->critical("\n Device is disabled: ", ['DeviceArn: ' => $device->getArn()]);
                 }
             }
             if (!$device->isEnabled()) {
                 $newDevice = $this->getDevice($device->getUser(), $device->getDeviceId(), $device->getPushtoken(), $device->getPlatform());
                 $logMessage = 'platform not found';
                 $logCustom = 'custom';
                 if ($device->getPlatform() === self::PLATFORM_ANDROID) {
                     $logMessage = $message->getGcmData();
                     $logCustom = $message->getCustom();
                 }
                 if ($device->getPlatform() === self::PLATFORM_IOS) {
                     $logMessage = $message->getApnsData();
                     $logCustom = $message->getCustom();
                 }
                 if ($device->getPlatform() === self::PLATFORM_IOS_SB) {
                     $logMessage = $message->getApnsData();
                     $logCustom = $message->getCustom();
                 }
                 try {
                     $this->messages->send($message, $newDevice->getArn());
                     $this->logger->info("\nSend message to: ", ['DEVICE' => $device->toLog(), 'MESSAGE' => $logMessage, 'CUSTOM' => $logCustom]);
                 } catch (\Exception $e) {
                     $device->setEnabled(false);
                     $this->em->flush();
                     $this->logger->critical("\n Device is disabled: ", ['DeviceArn: ' => $device->getArn()]);
                 }
             }
         }
         //  end foreach devices
     }
 }
コード例 #2
0
ファイル: Topics.php プロジェクト: tamcy/awspushbundle
 /**
  * Send a message to all topics in the group
  *
  * @param Message $message
  * @param string $topicArn
  * @deprecated Use Messages send method and pass the topicArn as the destination
  * @see Messages::send
  */
 public function broadcast(Message $message, $topicArn)
 {
     if ($this->debug) {
         $this->logger && $this->logger->notice("Message would have been sent to {$topicArn}", ['Message' => $message]);
         return;
     }
     $this->messages->send($message, $topicArn);
 }
コード例 #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();
         }
     }
 }
コード例 #4
0
 /**
  * Send a tweet to everyone
  *
  * @param array $tweet
  * @throws MaxPushesPerHourException
  * @throws \Mcfedr\AwsPushBundle\Exception\PlatformNotConfiguredException
  */
 public function pushTweet($tweet)
 {
     if ($this->maxPushesPerHour > 0 && $this->cache) {
         $hourAgo = new \DateTime('- 1 hour');
         /** @var \DateTime[] $tweetTimes */
         $tweetTimes = $this->cache->fetch(static::CACHE_KEY) ?: [];
         foreach ($tweetTimes as $k => $time) {
             if ($time < $hourAgo) {
                 unset($tweetTimes[$k]);
             }
         }
         if (($count = count($tweetTimes)) >= $this->maxPushesPerHour) {
             throw new MaxPushesPerHourException("Cannot send push, {$count} have already been sent. The limit is {$this->maxPushesPerHour}");
         }
         $tweetTimes[] = new \DateTime();
         $this->cache->save(static::CACHE_KEY, $tweetTimes, 3600);
     }
     $m = $this->getMessageForTweet($tweet);
     if ($this->topicArn) {
         $this->messages->send($m, $this->topicArn);
     } else {
         $this->messages->broadcast($m);
     }
 }