From f6be1041b7f820b6e908bfe081a6b4616d8473fb Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 29 Feb 2016 22:21:15 +1100 Subject: [PATCH] iOS Push Notifications --- app/Listeners/NotificationListener.php | 12 ++++++- app/Ninja/Notifications/PushService.php | 44 +++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 app/Ninja/Notifications/PushService.php diff --git a/app/Listeners/NotificationListener.php b/app/Listeners/NotificationListener.php index aba304457528..c7b58fe30ba5 100644 --- a/app/Listeners/NotificationListener.php +++ b/app/Listeners/NotificationListener.php @@ -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'); } } \ No newline at end of file diff --git a/app/Ninja/Notifications/PushService.php b/app/Ninja/Notifications/PushService.php new file mode 100644 index 000000000000..c304ed14d273 --- /dev/null +++ b/app/Ninja/Notifications/PushService.php @@ -0,0 +1,44 @@ +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); + + + } +} \ No newline at end of file