Skip to content

Commit 3a7773c

Browse files
authored
Merge pull request #12145 from nanaya/channel-notification-combine
Combine channel notification job classes
2 parents 98abd6b + 9ea9a63 commit 3a7773c

File tree

3 files changed

+56
-72
lines changed

3 files changed

+56
-72
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
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
6+
declare(strict_types=1);
7+
8+
namespace App\Jobs\Notifications;
9+
10+
use App\Models\Chat\Message;
11+
use App\Models\Notification;
12+
use App\Models\User;
13+
14+
abstract class ChannelMessageBase extends BroadcastNotificationBase
15+
{
16+
public static function getBaseKey(Notification $notification): string
17+
{
18+
return "channel.channel.{$notification->details['type']}";
19+
}
20+
21+
public static function getMailLink(Notification $notification): string
22+
{
23+
return route('chat.index', ['channel_id' => $notification->notifiable_id]);
24+
}
25+
26+
public function __construct(protected Message $message, User $source)
27+
{
28+
parent::__construct($source);
29+
}
30+
31+
public function getDetails(): array
32+
{
33+
return [
34+
'title' => truncate($this->message->content, static::CONTENT_TRUNCATE),
35+
'type' => strtolower($this->message->channel->type),
36+
'cover_url' => $this->source->user_avatar,
37+
];
38+
}
39+
40+
public function getListeningUserIds(): array
41+
{
42+
return $this->message->channel->userIds();
43+
}
44+
45+
public function getNotifiable()
46+
{
47+
return $this->message->channel;
48+
}
49+
}

0 commit comments

Comments
 (0)