1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Ninja/Notifications/PushFactory.php

86 lines
2.0 KiB
PHP
Raw Normal View History

2016-02-29 11:31:58 +01:00
<?php
namespace App\Ninja\Notifications;
use Davibennun\LaravelPushNotification\Facades\PushNotification;
use Illuminate\Support\Facades\Log;
2016-02-29 11:31:58 +01:00
/**
2017-01-30 20:40:43 +01:00
* Class PushFactory.
2016-02-29 11:31:58 +01:00
*/
class PushFactory
{
/**
* PushFactory constructor.
*/
public function __construct()
{
}
/**
2017-01-30 20:40:43 +01:00
* customMessage function.
2016-02-29 11:31:58 +01:00
*
* Send a message with a nested custom payload to perform additional trickery within application
*
*
* @param $token
* @param $message
* @param $messageArray
* @param string $device - Type of device the message is being pushed to.
2016-02-29 11:31:58 +01:00
*
* @return void
*/
public function customMessage($token, $message, $messageArray, $device)
2016-02-29 11:31:58 +01:00
{
$customMessage = PushNotification::Message($message, $messageArray);
$this->message($token, $customMessage, $device);
2016-02-29 11:31:58 +01:00
}
/**
2017-01-30 20:40:43 +01:00
* message function.
2016-02-29 11:31:58 +01:00
*
* Send a plain text only message to a single device.
*
*
* @param $token - device token
* @param $message - user specific message
2017-01-30 20:49:42 +01:00
* @param mixed $device
2016-02-29 11:31:58 +01:00
*
* @return void
*/
public function message($token, $message, $device)
2016-02-29 11:31:58 +01:00
{
try {
PushNotification::app($device)
->to($token)
->send($message);
2017-01-30 17:05:31 +01:00
} catch (\Exception $e) {
Log::error($e->getMessage());
}
2016-02-29 11:31:58 +01:00
}
/**
2017-01-30 20:40:43 +01:00
* getFeedback function.
2016-02-29 11:31:58 +01:00
*
* Returns an array of expired/invalid tokens to be removed from iOS PUSH notifications.
*
* We need to run this once ~ 24hrs
*
*
2017-01-30 20:40:43 +01:00
* @param string $token - A valid token (can be any valid token)
2016-02-29 11:31:58 +01:00
* @param string $message - Nil value for message
2017-01-30 20:40:43 +01:00
* @param string $device - Type of device the message is being pushed to.
*
2016-02-29 11:31:58 +01:00
* @return array
*/
2017-01-30 20:40:43 +01:00
public function getFeedback($token, $message, $device)
2016-02-29 11:31:58 +01:00
{
$feedback = PushNotification::app($device)
2016-02-29 11:31:58 +01:00
->to($token)
->send($message);
return $feedback->getFeedback();
}
}