Skip to content

Commit bb3bd2e

Browse files
authored
Merge pull request ppy#12045 from nanaya/notify-exclude-block
Don't send notification from blocked user
2 parents 69c3eab + f51ad63 commit bb3bd2e

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

app/Jobs/Notifications/BroadcastNotificationBase.php

+19-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use App\Models\UserGroup;
1313
use App\Models\UserNotification;
1414
use App\Models\UserNotificationOption;
15+
use App\Models\UserRelation;
1516
use App\Traits\NotificationQueue;
1617
use Illuminate\Bus\Queueable;
1718
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -171,7 +172,8 @@ public function getTimestamp()
171172

172173
public function handle()
173174
{
174-
$deliverySettings = static::applyDeliverySettings(static::excludeBotUserIds($this->getReceiverIds()));
175+
$receiverIds = $this->excludeBlockedUserIds(static::excludeBotUserIds($this->getReceiverIds()));
176+
$deliverySettings = static::applyDeliverySettings($receiverIds);
175177

176178
if (empty($deliverySettings)) {
177179
return;
@@ -232,4 +234,20 @@ public function makeNotification(): Notification
232234

233235
return $notification;
234236
}
237+
238+
private function excludeBlockedUserIds(array $userIds): array
239+
{
240+
if ($this->source === null) {
241+
return $userIds;
242+
}
243+
244+
$excludedReceiverIds = UserRelation
245+
::where('zebra_id', $this->source->getKey())
246+
->where('foe', true)
247+
->whereIn('user_id', $userIds)
248+
->pluck('user_id')
249+
->all();
250+
251+
return array_diff($userIds, $excludedReceiverIds);
252+
}
235253
}

tests/Controllers/CommentsControllerTest.php

+26
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Models\Follow;
1111
use App\Models\Notification;
1212
use App\Models\User;
13+
use App\Models\UserNotification;
1314
use Tests\TestCase;
1415

1516
class CommentsControllerTest extends TestCase
@@ -82,6 +83,31 @@ public function testStore()
8283
$this->assertSame($previousNotifications + 1, Notification::count());
8384
}
8485

86+
public function testStoreBlockedUser(): void
87+
{
88+
$this->prepareForStore();
89+
$otherUser = User::factory()->create();
90+
91+
$follow = Follow::create([
92+
'notifiable' => $this->beatmapset,
93+
'subtype' => 'comment',
94+
'user' => $otherUser,
95+
]);
96+
$otherUser->relations()->create([
97+
'foe' => true,
98+
'zebra_id' => $this->user->getKey(),
99+
]);
100+
101+
$this->expectCountChange(fn () => Comment::count(), 1);
102+
$this->expectCountChange(fn () => Notification::count(), 0);
103+
$this->expectCountChange(fn () => UserNotification::count(), 0);
104+
105+
$this
106+
->be($this->user)
107+
->post(route('comments.store'), $this->params)
108+
->assertSuccessful();
109+
}
110+
85111
public function testStoreDownloadLimitedBeatmapset()
86112
{
87113
$this->prepareForStore();

0 commit comments

Comments
 (0)