mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 12:44:30 -04:00
iOS Push Notifications
This commit is contained in:
parent
2cd3571f25
commit
f6be1041b7
@ -9,16 +9,19 @@ use App\Events\InvoiceInvitationWasViewed;
|
||||
use App\Events\QuoteInvitationWasViewed;
|
||||
use App\Events\QuoteInvitationWasApproved;
|
||||
use App\Events\PaymentWasCreated;
|
||||
use App\Ninja\Notifications;
|
||||
|
||||
class NotificationListener
|
||||
{
|
||||
protected $userMailer;
|
||||
protected $contactMailer;
|
||||
protected $pushService;
|
||||
|
||||
public function __construct(UserMailer $userMailer, ContactMailer $contactMailer)
|
||||
public function __construct(UserMailer $userMailer, ContactMailer $contactMailer, Notifications\PushService $pushService)
|
||||
{
|
||||
$this->userMailer = $userMailer;
|
||||
$this->contactMailer = $contactMailer;
|
||||
$this->pushService = $pushService;
|
||||
}
|
||||
|
||||
private function sendEmails($invoice, $type, $payment = null)
|
||||
@ -35,26 +38,31 @@ class NotificationListener
|
||||
public function emailedInvoice(InvoiceWasEmailed $event)
|
||||
{
|
||||
$this->sendEmails($event->invoice, 'sent');
|
||||
$this->pushService->sendNotification($event->invoice, 'sent');
|
||||
}
|
||||
|
||||
public function emailedQuote(QuoteWasEmailed $event)
|
||||
{
|
||||
$this->sendEmails($event->quote, 'sent');
|
||||
$this->pushService->sendNotification($event->quote, 'sent');
|
||||
}
|
||||
|
||||
public function viewedInvoice(InvoiceInvitationWasViewed $event)
|
||||
{
|
||||
$this->sendEmails($event->invoice, 'viewed');
|
||||
$this->pushService->sendNotification($event->invoice, 'viewed');
|
||||
}
|
||||
|
||||
public function viewedQuote(QuoteInvitationWasViewed $event)
|
||||
{
|
||||
$this->sendEmails($event->quote, 'viewed');
|
||||
$this->pushService->sendNotification($event->quote, 'viewed');
|
||||
}
|
||||
|
||||
public function approvedQuote(QuoteInvitationWasApproved $event)
|
||||
{
|
||||
$this->sendEmails($event->quote, 'approved');
|
||||
$this->pushService->sendNotification($event->quote, 'approved');
|
||||
}
|
||||
|
||||
public function createdPayment(PaymentWasCreated $event)
|
||||
@ -66,6 +74,8 @@ class NotificationListener
|
||||
|
||||
$this->contactMailer->sendPaymentConfirmation($event->payment);
|
||||
$this->sendEmails($event->payment->invoice, 'paid', $event->payment);
|
||||
|
||||
$this->pushService->sendNotification($event->payment->invoice, 'paid');
|
||||
}
|
||||
|
||||
}
|
44
app/Ninja/Notifications/PushService.php
Normal file
44
app/Ninja/Notifications/PushService.php
Normal file
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Ninja\Notifications;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
/**
|
||||
* Class PushService
|
||||
* @package App\Ninja\Notifications
|
||||
*/
|
||||
|
||||
class PushService
|
||||
{
|
||||
protected $pushFactory;
|
||||
|
||||
public function __construct(PushFactory $pushFactory)
|
||||
{
|
||||
$this->pushFactory = $pushFactory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $invoice - Invoice object
|
||||
* @param $type - Type of notification, ie. Quote APPROVED, Invoice PAID, Invoice SENT, Invoice VIEWED
|
||||
*/
|
||||
|
||||
public function sendNotification($invoice, $type)
|
||||
{
|
||||
//check user has registered for push notifications
|
||||
if(!$this->checkDeviceExists($invoice->account))
|
||||
return;
|
||||
|
||||
//Harvest an array of devices that are registered for this notification type
|
||||
|
||||
//loop and send
|
||||
|
||||
}
|
||||
|
||||
private function checkDeviceExists($account)
|
||||
{
|
||||
$devices = json_decode($account->devices);
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user