1<?php
2
3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
4// See the LICENCE file in the repository root for full licence text.
5
6namespace App\Events;
7
8use App\Models\Notification;
9use Illuminate\Broadcasting\Channel;
10use Illuminate\Queue\SerializesModels;
11
12class NewPrivateNotificationEvent extends NotificationEventBase
13{
14 use SerializesModels;
15
16 /**
17 * Create a new event instance.
18 *
19 * @return void
20 */
21 public function __construct(public Notification $notification, private array $receiverIds)
22 {
23 parent::__construct();
24
25 $this->notification = $notification;
26 $this->receiverIds = $receiverIds;
27 }
28
29 public function broadcastAs()
30 {
31 return 'new';
32 }
33
34 /**
35 * Get the channels the event should broadcast on.
36 *
37 * @return Channel|array
38 */
39 public function broadcastOn()
40 {
41 return array_map(function ($userId) {
42 return new Channel("private:user:{$userId}");
43 }, $this->receiverIds);
44 }
45
46 public function broadcastWith()
47 {
48 return json_item($this->notification, 'Notification');
49 }
50
51 public function getReceiverIds()
52 {
53 return $this->receiverIds;
54 }
55}