From cb202c9671bbe332204f21a73998224128cac071 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 8 Apr 2019 14:38:27 -0600 Subject: [PATCH] Add broadcast events for real time updates --- app/Events/NewMention.php | 51 ++++++++++++++++++++ app/Events/Notification/NewPublicPost.php | 57 +++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 app/Events/NewMention.php create mode 100644 app/Events/Notification/NewPublicPost.php diff --git a/app/Events/NewMention.php b/app/Events/NewMention.php new file mode 100644 index 000000000..90adcc0d8 --- /dev/null +++ b/app/Events/NewMention.php @@ -0,0 +1,51 @@ +user = $user; + $this->data = $data; + } + + public function broadcastAs() + { + return 'notification.new.mention'; + } + + public function broadcastOn() + { + return new PrivateChannel('App.User.' . $this->user->id); + } + + public function broadcastWith() + { + return ['id' => $this->user->id]; + } + + public function via() + { + return 'broadcast'; + } +} diff --git a/app/Events/Notification/NewPublicPost.php b/app/Events/Notification/NewPublicPost.php new file mode 100644 index 000000000..e43b1f19b --- /dev/null +++ b/app/Events/Notification/NewPublicPost.php @@ -0,0 +1,57 @@ +status = $status; + } + + public function broadcastAs() + { + return 'status'; + } + + public function broadcastOn() + { + return new Channel('firehost.public'); + } + + public function broadcastWith() + { + $resource = new Fractal\Resource\Item($this->status, new StatusTransformer()); + $res = $this->fractal->createData($resource)->toArray(); + return [ + 'entity' => $res + ]; + } + + public function via() + { + return 'broadcast'; + } +}