From f5d9ca5174982f59efe3de46e34dda936522d2f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 17 Sep 2024 18:37:27 +0200 Subject: [PATCH 1/9] update pusher conf --- config/broadcasting.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/config/broadcasting.php b/config/broadcasting.php index fa0beea47388..34f0cf4736de 100644 --- a/config/broadcasting.php +++ b/config/broadcasting.php @@ -32,18 +32,15 @@ return [ 'pusher' => [ 'driver' => 'pusher', - 'key' => env('PUSHER_APP_KEY', ''), - 'secret' => env('PUSHER_APP_SECRET', ''), - 'app_id' => env('PUSHER_APP_ID', ''), + 'key' => env('PUSHER_APP_KEY', 'app-key'), + 'secret' => env('PUSHER_APP_SECRET', 'app-secret'), + 'app_id' => env('PUSHER_APP_ID', 'app-id'), 'options' => [ - 'host' => env('PUSHER_HOST', 'api-'.env('PUSHER_APP_CLUSTER', 'mt1').'.pusher.com'), - 'port' => env('PUSHER_PORT', 443), - 'scheme' => env('PUSHER_SCHEME', 'https'), - 'encrypted' => false, - 'useTLS' => env('PUSHER_SCHEME', 'https') === 'https', - ], - 'client_options' => [ - // Guzzle client options: https://docs.guzzlephp.org/en/stable/request-options.html + 'host' => env('PUSHER_HOST', '127.0.0.1'), + 'port' => env('PUSHER_PORT', 6001), + 'scheme' => env('PUSHER_SCHEME', 'http'), + 'encrypted' => true, + 'useTLS' => env('PUSHER_SCHEME') === 'https', ], ], From 693f4e0f6b5b1aa72d676ef34e428cdab119311c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Tue, 17 Sep 2024 18:57:51 +0200 Subject: [PATCH 2/9] broadcast event on invoice.paid --- app/Events/Invoice/InvoiceWasPaid.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index 34c574275a86..6f845592ce9b 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -1,4 +1,5 @@ company = $company; $this->event_vars = $event_vars; } + + public function broadcastOn(): array + { + return [ + // @todo: make sure this is PrivateChannel once we have auth configured. + + new Channel( + name: $this->company->company_key . '_invoices', + ), + ]; + } + + public function broadcastAs(): string + { + return 'invoice.paid'; + } } From d12e277230f66f08aeb540ea3a8c22a3c629a5d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 18 Sep 2024 13:12:05 +0200 Subject: [PATCH 3/9] update channel name --- app/Events/Invoice/InvoiceWasPaid.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index 6f845592ce9b..d2370535b62f 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -16,6 +16,7 @@ use App\Models\Company; use App\Models\Invoice; use App\Models\Payment; use Illuminate\Broadcasting\Channel; +use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Queue\SerializesModels; @@ -55,11 +56,7 @@ class InvoiceWasPaid implements ShouldBroadcast public function broadcastOn(): array { return [ - // @todo: make sure this is PrivateChannel once we have auth configured. - - new Channel( - name: $this->company->company_key . '_invoices', - ), + new PrivateChannel("{$this->company->company_key}.invoices"), ]; } From 48a60531008d6172dc73b68e5d6467821747fbe0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 18 Sep 2024 17:44:14 +0200 Subject: [PATCH 4/9] extract broadcasting properties --- .../Broadcasting/DefaultInvoiceBroadcast.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/Utils/Traits/Invoice/Broadcasting/DefaultInvoiceBroadcast.php diff --git a/app/Utils/Traits/Invoice/Broadcasting/DefaultInvoiceBroadcast.php b/app/Utils/Traits/Invoice/Broadcasting/DefaultInvoiceBroadcast.php new file mode 100644 index 000000000000..cfabf2164559 --- /dev/null +++ b/app/Utils/Traits/Invoice/Broadcasting/DefaultInvoiceBroadcast.php @@ -0,0 +1,42 @@ +company->company_key}"), + ]; + } + + public function broadcastWith(): array + { + $manager = new Manager(); + $manager->setSerializer(new ArraySerializer()); + $class = sprintf('App\\Transformers\\%sTransformer', class_basename($this->invoice)); + + $transformer = new $class(); + + $resource = new Item($this->invoice, $transformer, $this->invoice->getEntityType()); + $data = $manager->createData($resource)->toArray(); + + return $data; + } +} From a59e0388c03f02fd1211d4631ac0b10d141cf72c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 18 Sep 2024 17:44:27 +0200 Subject: [PATCH 5/9] refactor invoice was paid --- app/Events/Invoice/InvoiceWasPaid.php | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/app/Events/Invoice/InvoiceWasPaid.php b/app/Events/Invoice/InvoiceWasPaid.php index d2370535b62f..a5a8812f1b90 100644 --- a/app/Events/Invoice/InvoiceWasPaid.php +++ b/app/Events/Invoice/InvoiceWasPaid.php @@ -15,8 +15,7 @@ namespace App\Events\Invoice; use App\Models\Company; use App\Models\Invoice; use App\Models\Payment; -use Illuminate\Broadcasting\Channel; -use Illuminate\Broadcasting\PrivateChannel; +use App\Utils\Traits\Invoice\Broadcasting\DefaultInvoiceBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Queue\SerializesModels; @@ -25,7 +24,7 @@ use Illuminate\Queue\SerializesModels; */ class InvoiceWasPaid implements ShouldBroadcast { - use SerializesModels; + use SerializesModels, DefaultInvoiceBroadcast; /** * @var Invoice @@ -52,16 +51,4 @@ class InvoiceWasPaid implements ShouldBroadcast $this->company = $company; $this->event_vars = $event_vars; } - - public function broadcastOn(): array - { - return [ - new PrivateChannel("{$this->company->company_key}.invoices"), - ]; - } - - public function broadcastAs(): string - { - return 'invoice.paid'; - } } From e4a58212724498c37b83f12c827540067165fc95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 18 Sep 2024 18:10:47 +0200 Subject: [PATCH 6/9] define channel for accessing invoice presence --- routes/channels.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/routes/channels.php b/routes/channels.php index 9d8de62648d0..583b8f986814 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -11,6 +11,8 @@ | */ +use App\Models\User; + // Broadcast::channel('App.User.{id}', function ($user, $id) { // nlog($id); @@ -18,6 +20,18 @@ // // return (int) $user->id === (int) $id; // }); -Broadcast::channel('company-{company_key}', function (\App\Models\User $user, string $company_key) { +Broadcast::channel('company-{company_key}', function (User $user, string $company_key) { return $user->company()->company_key === $company_key; -}); \ No newline at end of file +}); + +Broadcast::channel('company-${company.company_key}.{roomId}', function (User $user, int $roomId) { + if ($user->canJoinRoom($roomId)) { + return ['id' => $user->id, 'name' => $user->name]; + } +}); + +Broadcast::channel('company-{company_key}.invoices.{invoice_id}', function (User $user, string $company_key, string $invoice_id) { + // @todo + + return true; +}); From 0a5ac9b332ebe1666cf347a766aa5806d4056e95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Thu, 19 Sep 2024 16:25:35 +0200 Subject: [PATCH 7/9] add translation for invoice status change --- lang/en/texts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/texts.php b/lang/en/texts.php index c3ad8e1f214c..27a17b48a961 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5333,6 +5333,7 @@ $lang = array( 'country_Melilla' => 'Melilla', 'country_Ceuta' => 'Ceuta', 'country_Canary Islands' => 'Canary Islands', + 'invoice_status_changed' => 'Please note that the status of your invoice has been updated. We recommend refreshing the page to view the most current version.', ); return $lang; From 7b7974fbfae02ae7014d101ea893a5383340aece Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 20 Sep 2024 18:35:53 +0200 Subject: [PATCH 8/9] clean up channels --- routes/channels.php | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/routes/channels.php b/routes/channels.php index 583b8f986814..0395b473facb 100644 --- a/routes/channels.php +++ b/routes/channels.php @@ -11,8 +11,6 @@ | */ -use App\Models\User; - // Broadcast::channel('App.User.{id}', function ($user, $id) { // nlog($id); @@ -20,18 +18,6 @@ use App\Models\User; // // return (int) $user->id === (int) $id; // }); -Broadcast::channel('company-{company_key}', function (User $user, string $company_key) { +Broadcast::channel('company-{company_key}', function (\App\Models\User $user, string $company_key) { return $user->company()->company_key === $company_key; }); - -Broadcast::channel('company-${company.company_key}.{roomId}', function (User $user, int $roomId) { - if ($user->canJoinRoom($roomId)) { - return ['id' => $user->id, 'name' => $user->name]; - } -}); - -Broadcast::channel('company-{company_key}.invoices.{invoice_id}', function (User $user, string $company_key, string $invoice_id) { - // @todo - - return true; -}); From 5c57f721b4c3ebf2b2087fb27eb911a9115f9f2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Fri, 20 Sep 2024 18:36:09 +0200 Subject: [PATCH 9/9] translation for notifications --- lang/en/texts.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lang/en/texts.php b/lang/en/texts.php index 27a17b48a961..a5700e4e4730 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5334,6 +5334,7 @@ $lang = array( 'country_Ceuta' => 'Ceuta', 'country_Canary Islands' => 'Canary Islands', 'invoice_status_changed' => 'Please note that the status of your invoice has been updated. We recommend refreshing the page to view the most current version.', + 'no_unread_notifications' => 'You’re all caught up! No new notifications.', ); return $lang;