File tree 2 files changed +45
-1
lines changed
2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 12
12
use App \Models \UserGroup ;
13
13
use App \Models \UserNotification ;
14
14
use App \Models \UserNotificationOption ;
15
+ use App \Models \UserRelation ;
15
16
use App \Traits \NotificationQueue ;
16
17
use Illuminate \Bus \Queueable ;
17
18
use Illuminate \Contracts \Queue \ShouldQueue ;
@@ -171,7 +172,8 @@ public function getTimestamp()
171
172
172
173
public function handle ()
173
174
{
174
- $ deliverySettings = static ::applyDeliverySettings (static ::excludeBotUserIds ($ this ->getReceiverIds ()));
175
+ $ receiverIds = $ this ->excludeBlockedUserIds (static ::excludeBotUserIds ($ this ->getReceiverIds ()));
176
+ $ deliverySettings = static ::applyDeliverySettings ($ receiverIds );
175
177
176
178
if (empty ($ deliverySettings )) {
177
179
return ;
@@ -232,4 +234,20 @@ public function makeNotification(): Notification
232
234
233
235
return $ notification ;
234
236
}
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
+ }
235
253
}
Original file line number Diff line number Diff line change 10
10
use App \Models \Follow ;
11
11
use App \Models \Notification ;
12
12
use App \Models \User ;
13
+ use App \Models \UserNotification ;
13
14
use Tests \TestCase ;
14
15
15
16
class CommentsControllerTest extends TestCase
@@ -82,6 +83,31 @@ public function testStore()
82
83
$ this ->assertSame ($ previousNotifications + 1 , Notification::count ());
83
84
}
84
85
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
+
85
111
public function testStoreDownloadLimitedBeatmapset ()
86
112
{
87
113
$ this ->prepareForStore ();
You can’t perform that action at this time.
0 commit comments