Skip to content

Commit 3088c20

Browse files
authored
Merge branch 'master' into beatmapset-user-tags
2 parents 62ac40d + 3a7773c commit 3088c20

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+444
-255
lines changed

app/Http/Controllers/ArtistTracksController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
namespace App\Http\Controllers;
77

88
use App\Libraries\Search\ArtistTrackSearch;
9-
use App\Libraries\Search\ArtistTrackSearchParamsFromRequest;
9+
use App\Libraries\Search\ArtistTrackSearchRequestParams;
1010
use App\Models\ArtistTrack;
1111
use App\Transformers\ArtistTrackTransformer;
1212

1313
class ArtistTracksController extends Controller
1414
{
1515
public function index()
1616
{
17-
$params = ArtistTrackSearchParamsFromRequest::fromArray(request()->all());
17+
$params = new ArtistTrackSearchRequestParams(\Request::all());
1818
$search = new ArtistTrackSearch($params);
1919

2020
$tracks = $search->records();
2121
$index = [
22-
'artist_tracks' => json_collection($tracks, new ArtistTrackTransformer(), ['artist', 'album']),
23-
'search' => ArtistTrackSearchParamsFromRequest::toArray($params),
22+
'artist_tracks' => json_collection(
23+
$tracks,
24+
new ArtistTrackTransformer(),
25+
ArtistTrackTransformer::CARD_INCLUDES,
26+
),
27+
'search' => $params->toArray(),
2428
...cursor_for_response($search->getSortCursor()),
2529
];
2630

app/Http/Controllers/HomeController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,11 @@ public function search()
184184
$currentUser = Auth::user();
185185
$allSearch = new AllSearch(Request::all(), ['user' => $currentUser]);
186186

187-
if ($allSearch->getMode() === 'beatmapset') {
188-
return ujs_redirect(route('beatmapsets.index', ['q' => $allSearch->getRawQuery()]));
187+
switch ($allSearch->getMode()) {
188+
case 'artist_track':
189+
return ujs_redirect(route('artists.tracks.index', ['query' => $allSearch->getRawQuery()]));
190+
case 'beatmapset':
191+
return ujs_redirect(route('beatmapsets.index', ['q' => $allSearch->getRawQuery()]));
189192
}
190193

191194
$isSearchPage = true;

app/Http/Controllers/Teams/ApplicationsController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use App\Http\Controllers\Controller;
1111
use App\Jobs\Notifications\TeamApplicationReject;
12+
use App\Jobs\Notifications\TeamApplicationStore;
1213
use App\Models\Team;
1314
use App\Models\TeamApplication;
1415
use Symfony\Component\HttpFoundation\Response;
@@ -39,7 +40,7 @@ public function accept(string $teamId, string $id): Response
3940
public function destroy(string $teamId, string $id): Response
4041
{
4142
$currentUser = \Auth::user();
42-
TeamApplication::where('team_id', $teamId)->findOrFail($currentUser->getKey())->delete();
43+
TeamApplication::where('team_id', $teamId)->findOrFail($currentUser->getKey())->cancel();
4344

4445
\Session::flash('popup', osu_trans('teams.applications.destroy.ok'));
4546

@@ -65,7 +66,9 @@ public function store(string $teamId): Response
6566
$team = Team::findOrFail($teamId);
6667
priv_check('TeamApplicationStore', $team)->ensureCan();
6768

68-
$team->applications()->createOrFirst(['user_id' => \Auth::id()]);
69+
$user = \Auth::user();
70+
$application = $team->applications()->createOrFirst(['user_id' => $user->getKey()]);
71+
(new TeamApplicationStore($application, $user))->dispatch();
6972
\Session::flash('popup', osu_trans('teams.applications.store.ok'));
7073

7174
return response(null, 204);

app/Jobs/Notifications/BroadcastNotificationBase.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public function handle()
177177
$deliverySettings = static::applyDeliverySettings($receiverIds);
178178

179179
if (empty($deliverySettings)) {
180-
return;
180+
return null;
181181
}
182182

183183
$notification = $this->makeNotification();
@@ -215,6 +215,11 @@ public function handle()
215215
if (!empty($pushReceiverIds)) {
216216
(new NewPrivateNotificationEvent($notification, $pushReceiverIds))->broadcast();
217217
}
218+
219+
return [
220+
'notification' => $notification,
221+
'receiverIds' => $receiverIds,
222+
];
218223
}
219224

220225
public function makeNotification(): Notification

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+
}

app/Jobs/Notifications/TeamApplicationBase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public function getDetails(): array
3434
{
3535
return [
3636
'cover_url' => $this->team->flag()->url(),
37-
'team_id' => $this->team->getKey(),
3837
'title' => $this->team->name,
3938
];
4039
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\User;
11+
12+
class TeamApplicationStore extends TeamApplicationBase
13+
{
14+
public function getListeningUserIds(): array
15+
{
16+
return [$this->team->leader_id];
17+
}
18+
19+
public function getDetails(): array
20+
{
21+
return [
22+
...parent::getDetails(),
23+
'title' => User::find($this->userId)?->username ?? '',
24+
];
25+
}
26+
27+
public function handle()
28+
{
29+
$currentAppllication = $this->team->applications()->firstWhere([
30+
'notification_id' => null,
31+
'user_id' => $this->userId,
32+
]);
33+
34+
if ($currentAppllication === null) {
35+
return null;
36+
}
37+
38+
$data = parent::handle();
39+
40+
if ($data !== null) {
41+
$currentAppllication->update(['notification_id' => $data['notification']->getKey()]);
42+
}
43+
44+
return $data;
45+
}
46+
}

app/Libraries/Ip2AsnUpdater.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,32 @@
1212

1313
class Ip2AsnUpdater
1414
{
15+
public static function fetch(Ip $version): string
16+
{
17+
static $baseUrls = [
18+
'https://iptoasn.com/data',
19+
'https://assets.ppy.sh',
20+
];
21+
22+
foreach ($baseUrls as $baseUrl) {
23+
try {
24+
$gz = file_get_contents("{$baseUrl}/ip2asn-{$version->value}.tsv.gz");
25+
26+
if ($gz !== false) {
27+
break;
28+
}
29+
} catch (\Throwable) {
30+
// retry
31+
}
32+
}
33+
34+
if (!isset($gz) || !is_string($gz)) {
35+
throw new \Exception('failed downloading source database');
36+
}
37+
38+
return gzdecode($gz);
39+
}
40+
1541
public static function getDbPath(Ip $version): string
1642
{
1743
return database_path("ip2asn/{$version->value}.tsv");
@@ -60,7 +86,7 @@ private function update(Ip $version, callable $logger): void
6086

6187
if ($newDb) {
6288
$logger('Db file is outdated. Downloading');
63-
$tsv = gzdecode(file_get_contents("https://iptoasn.com/data/ip2asn-{$version->value}.tsv.gz"));
89+
$tsv = static::fetch($version);
6490
} else {
6591
$tsv = file_get_contents($dbPath);
6692
}

0 commit comments

Comments
 (0)