iOS Push Notifications

This commit is contained in:
David Bomba 2016-02-29 22:21:15 +11:00
parent 2cd3571f25
commit f6be1041b7
2 changed files with 55 additions and 1 deletions

View File

@ -9,16 +9,19 @@ use App\Events\InvoiceInvitationWasViewed;
use App\Events\QuoteInvitationWasViewed; use App\Events\QuoteInvitationWasViewed;
use App\Events\QuoteInvitationWasApproved; use App\Events\QuoteInvitationWasApproved;
use App\Events\PaymentWasCreated; use App\Events\PaymentWasCreated;
use App\Ninja\Notifications;
class NotificationListener class NotificationListener
{ {
protected $userMailer; protected $userMailer;
protected $contactMailer; 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->userMailer = $userMailer;
$this->contactMailer = $contactMailer; $this->contactMailer = $contactMailer;
$this->pushService = $pushService;
} }
private function sendEmails($invoice, $type, $payment = null) private function sendEmails($invoice, $type, $payment = null)
@ -35,26 +38,31 @@ class NotificationListener
public function emailedInvoice(InvoiceWasEmailed $event) public function emailedInvoice(InvoiceWasEmailed $event)
{ {
$this->sendEmails($event->invoice, 'sent'); $this->sendEmails($event->invoice, 'sent');
$this->pushService->sendNotification($event->invoice, 'sent');
} }
public function emailedQuote(QuoteWasEmailed $event) public function emailedQuote(QuoteWasEmailed $event)
{ {
$this->sendEmails($event->quote, 'sent'); $this->sendEmails($event->quote, 'sent');
$this->pushService->sendNotification($event->quote, 'sent');
} }
public function viewedInvoice(InvoiceInvitationWasViewed $event) public function viewedInvoice(InvoiceInvitationWasViewed $event)
{ {
$this->sendEmails($event->invoice, 'viewed'); $this->sendEmails($event->invoice, 'viewed');
$this->pushService->sendNotification($event->invoice, 'viewed');
} }
public function viewedQuote(QuoteInvitationWasViewed $event) public function viewedQuote(QuoteInvitationWasViewed $event)
{ {
$this->sendEmails($event->quote, 'viewed'); $this->sendEmails($event->quote, 'viewed');
$this->pushService->sendNotification($event->quote, 'viewed');
} }
public function approvedQuote(QuoteInvitationWasApproved $event) public function approvedQuote(QuoteInvitationWasApproved $event)
{ {
$this->sendEmails($event->quote, 'approved'); $this->sendEmails($event->quote, 'approved');
$this->pushService->sendNotification($event->quote, 'approved');
} }
public function createdPayment(PaymentWasCreated $event) public function createdPayment(PaymentWasCreated $event)
@ -66,6 +74,8 @@ class NotificationListener
$this->contactMailer->sendPaymentConfirmation($event->payment); $this->contactMailer->sendPaymentConfirmation($event->payment);
$this->sendEmails($event->payment->invoice, 'paid', $event->payment); $this->sendEmails($event->payment->invoice, 'paid', $event->payment);
$this->pushService->sendNotification($event->payment->invoice, 'paid');
} }
} }

View 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);
}
}