mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Firebase notifications for Android (#1269)
* revert error reporting * fix for non boolean output * Firebase notifications for Android
This commit is contained in:
parent
0275ab92ab
commit
6a41353a96
@ -3,6 +3,7 @@
|
|||||||
namespace App\Ninja\Notifications;
|
namespace App\Ninja\Notifications;
|
||||||
|
|
||||||
use Davibennun\LaravelPushNotification\Facades\PushNotification;
|
use Davibennun\LaravelPushNotification\Facades\PushNotification;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class PushFactory
|
* Class PushFactory
|
||||||
@ -15,7 +16,6 @@ class PushFactory
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->certificate = IOS_PUSH_CERTIFICATE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,14 +28,15 @@ class PushFactory
|
|||||||
* @param $token
|
* @param $token
|
||||||
* @param $message
|
* @param $message
|
||||||
* @param $messageArray
|
* @param $messageArray
|
||||||
|
* @param string $device - Type of device the message is being pushed to.
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function customMessage($token, $message, $messageArray)
|
public function customMessage($token, $message, $messageArray, $device)
|
||||||
{
|
{
|
||||||
$customMessage = PushNotification::Message($message, $messageArray);
|
$customMessage = PushNotification::Message($message, $messageArray);
|
||||||
|
|
||||||
$this->message($token, $customMessage);
|
$this->message($token, $customMessage, $device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -51,11 +52,17 @@ class PushFactory
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function message($token, $message)
|
public function message($token, $message, $device)
|
||||||
{
|
{
|
||||||
PushNotification::app($this->certificate)
|
try {
|
||||||
->to($token)
|
PushNotification::app($device)
|
||||||
->send($message);
|
->to($token)
|
||||||
|
->send($message);
|
||||||
|
}
|
||||||
|
catch(\Exception $e) {
|
||||||
|
Log::error($e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,13 +76,13 @@ class PushFactory
|
|||||||
*
|
*
|
||||||
* @param string $token - A valid token (can be any valid token)
|
* @param string $token - A valid token (can be any valid token)
|
||||||
* @param string $message - Nil value for message
|
* @param string $message - Nil value for message
|
||||||
*
|
* @param string $device - Type of device the message is being pushed to.
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getFeedback($token, $message = '')
|
public function getFeedback($token, $message = '', $device)
|
||||||
{
|
{
|
||||||
|
|
||||||
$feedback = PushNotification::app($this->certificate)
|
$feedback = PushNotification::app($device)
|
||||||
->to($token)
|
->to($token)
|
||||||
->send($message);
|
->send($message);
|
||||||
|
|
||||||
|
@ -30,10 +30,6 @@ class PushService
|
|||||||
*/
|
*/
|
||||||
public function sendNotification(Invoice $invoice, $type)
|
public function sendNotification(Invoice $invoice, $type)
|
||||||
{
|
{
|
||||||
if (! IOS_PUSH_CERTIFICATE) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//check user has registered for push notifications
|
//check user has registered for push notifications
|
||||||
if(!$this->checkDeviceExists($invoice->account))
|
if(!$this->checkDeviceExists($invoice->account))
|
||||||
return;
|
return;
|
||||||
@ -43,8 +39,10 @@ class PushService
|
|||||||
|
|
||||||
foreach($devices as $device)
|
foreach($devices as $device)
|
||||||
{
|
{
|
||||||
if(($device["notify_{$type}"] == TRUE) && ($device['device'] == 'ios'))
|
if(($device["notify_{$type}"] == TRUE) && ($device['device'] == 'ios') && IOS_DEVICE)
|
||||||
$this->pushMessage($invoice, $device['token'], $type);
|
$this->pushMessage($invoice, $device['token'], $type, IOS_DEVICE);
|
||||||
|
elseif(($device["notify_{$type}"] == TRUE) && ($device['device'] == 'fcm') && ANDROID_DEVICE)
|
||||||
|
$this->pushMessage($invoice, $device['token'], $type, ANDROID_DEVICE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,9 +55,9 @@ class PushService
|
|||||||
* @param $token
|
* @param $token
|
||||||
* @param $type
|
* @param $type
|
||||||
*/
|
*/
|
||||||
private function pushMessage(Invoice $invoice, $token, $type)
|
private function pushMessage(Invoice $invoice, $token, $type, $device)
|
||||||
{
|
{
|
||||||
$this->pushFactory->message($token, $this->messageType($invoice, $type));
|
$this->pushFactory->message($token, $this->messageType($invoice, $type), $device);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,8 +16,8 @@ return [
|
|||||||
],
|
],
|
||||||
'ninjaAndroid' => [
|
'ninjaAndroid' => [
|
||||||
'environment' =>'production',
|
'environment' =>'production',
|
||||||
'apiKey' =>'yourAPIKey',
|
'apiKey' =>env(FCM_API_TOKEN),
|
||||||
'service' =>'gcm'
|
'service' =>'fcm'
|
||||||
]
|
]
|
||||||
|
|
||||||
];
|
];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user