Skip to content

Commit 5da276e

Browse files
committed
Combine channel notification job classes
1 parent 5850e8e commit 5da276e

File tree

3 files changed

+12
-82
lines changed

3 files changed

+12
-82
lines changed

app/Jobs/Notifications/ChannelAnnouncement.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,29 @@
33
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
44
// See the LICENCE file in the repository root for full licence text.
55

6+
declare(strict_types=1);
7+
68
namespace App\Jobs\Notifications;
79

8-
use App\Models\Chat\Message;
910
use App\Models\Notification;
10-
use App\Models\User;
1111

12-
class ChannelAnnouncement extends BroadcastNotificationBase
12+
class ChannelAnnouncement extends ChannelMessageBase
1313
{
1414
const DELIVERY_MODE_DEFAULTS = ['mail' => true, 'push' => true];
1515

16-
protected $message;
17-
1816
public static function getBaseKey(Notification $notification): string
1917
{
2018
return 'channel.announcement.announce';
2119
}
2220

23-
public static function getMailLink(Notification $notification): string
24-
{
25-
return route('chat.index', ['channel_id' => $notification->notifiable_id]);
26-
}
27-
28-
public function __construct(Message $message, User $source)
29-
{
30-
parent::__construct($source);
31-
32-
$this->message = $message;
33-
}
34-
3521
public function getDetails(): array
3622
{
3723
$channel = $this->message->channel;
3824

3925
return [
26+
...parent::getDetails(),
4027
'channel_id' => $channel->getKey(),
4128
'name' => $channel->name,
42-
'title' => truncate($this->message->content, static::CONTENT_TRUNCATE),
43-
'type' => strtolower($channel->type),
44-
'cover_url' => $this->source->user_avatar,
4529
];
4630
}
47-
48-
public function getListeningUserIds(): array
49-
{
50-
return $this->message->channel->userIds();
51-
}
52-
53-
public function getNotifiable()
54-
{
55-
return $this->message->channel;
56-
}
5731
}

app/Jobs/Notifications/ChannelMessage.php

Lines changed: 3 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,52 +3,13 @@
33
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
44
// See the LICENCE file in the repository root for full licence text.
55

6+
declare(strict_types=1);
7+
68
namespace App\Jobs\Notifications;
79

8-
use App\Models\Chat\Message;
910
use App\Models\Notification;
10-
use App\Models\User;
1111

12-
class ChannelMessage extends BroadcastNotificationBase
12+
class ChannelMessage extends ChannelMessageBase
1313
{
1414
const NOTIFICATION_OPTION_NAME = Notification::CHANNEL_MESSAGE;
15-
16-
protected $message;
17-
18-
public static function getBaseKey(Notification $notification): string
19-
{
20-
return "channel.channel.{$notification->details['type']}";
21-
}
22-
23-
public static function getMailLink(Notification $notification): string
24-
{
25-
// TODO: probably should enable linking to a channel directly...
26-
return route('chat.index', ['sendto' => $notification->source_user_id]);
27-
}
28-
29-
public function __construct(Message $message, User $source)
30-
{
31-
parent::__construct($source);
32-
33-
$this->message = $message;
34-
}
35-
36-
public function getDetails(): array
37-
{
38-
return [
39-
'title' => truncate($this->message->content, static::CONTENT_TRUNCATE),
40-
'type' => strtolower($this->message->channel->type),
41-
'cover_url' => $this->source->user_avatar,
42-
];
43-
}
44-
45-
public function getListeningUserIds(): array
46-
{
47-
return $this->message->channel->userIds();
48-
}
49-
50-
public function getNotifiable()
51-
{
52-
return $this->message->channel;
53-
}
5415
}

app/Jobs/Notifications/ChannelMessageBase.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,29 @@
33
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
44
// See the LICENCE file in the repository root for full licence text.
55

6+
declare(strict_types=1);
7+
68
namespace App\Jobs\Notifications;
79

810
use App\Models\Chat\Message;
911
use App\Models\Notification;
1012
use App\Models\User;
1113

12-
class ChannelMessage extends BroadcastNotificationBase
14+
abstract class ChannelMessageBase extends BroadcastNotificationBase
1315
{
14-
const NOTIFICATION_OPTION_NAME = Notification::CHANNEL_MESSAGE;
15-
16-
protected $message;
17-
1816
public static function getBaseKey(Notification $notification): string
1917
{
2018
return "channel.channel.{$notification->details['type']}";
2119
}
2220

2321
public static function getMailLink(Notification $notification): string
2422
{
25-
// TODO: probably should enable linking to a channel directly...
26-
return route('chat.index', ['sendto' => $notification->source_user_id]);
23+
return route('chat.index', ['channel_id' => $notification->notifiable_id]);
2724
}
2825

29-
public function __construct(Message $message, User $source)
26+
public function __construct(protected Message $message, User $source)
3027
{
3128
parent::__construct($source);
32-
33-
$this->message = $message;
3429
}
3530

3631
public function getDetails(): array

0 commit comments

Comments
 (0)