Skip to content

Commit f0518b9

Browse files
authored
Merge branch 'master' into asn-backup-url
2 parents b7a7407 + 508b2ba commit f0518b9

File tree

14 files changed

+162
-4
lines changed

14 files changed

+162
-4
lines changed

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
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/Models/Notification.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Notification extends Model
4545
const FORUM_TOPIC_REPLY = 'forum_topic_reply';
4646
const TEAM_APPLICATION_ACCEPT = 'team_application_accept';
4747
const TEAM_APPLICATION_REJECT = 'team_application_reject';
48+
const TEAM_APPLICATION_STORE = 'team_application_store';
4849
const USER_ACHIEVEMENT_UNLOCK = 'user_achievement_unlock';
4950
const USER_BEATMAPSET_NEW = 'user_beatmapset_new';
5051
const USER_BEATMAPSET_REVIVE = 'user_beatmapset_revive';
@@ -70,6 +71,7 @@ class Notification extends Model
7071
self::FORUM_TOPIC_REPLY => 'forum_topic_reply',
7172
self::TEAM_APPLICATION_ACCEPT => 'team_application',
7273
self::TEAM_APPLICATION_REJECT => 'team_application',
74+
self::TEAM_APPLICATION_STORE => 'team_application',
7375
self::USER_ACHIEVEMENT_UNLOCK => 'user_achievement_unlock',
7476
self::USER_BEATMAPSET_NEW => 'user_beatmapset_new',
7577
self::USER_BEATMAPSET_REVIVE => 'user_beatmapset_new',

app/Models/TeamApplication.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace App\Models;
99

10+
use App\Libraries\Notification\BatchIdentities;
1011
use Illuminate\Database\Eloquent\Relations\BelongsTo;
1112

1213
class TeamApplication extends Model
@@ -15,6 +16,11 @@ class TeamApplication extends Model
1516

1617
protected $primaryKey = 'user_id';
1718

19+
public function notification(): BelongsTo
20+
{
21+
return $this->belongsTo(Notification::class);
22+
}
23+
1824
public function team(): BelongsTo
1925
{
2026
return $this->belongsTo(Team::class);
@@ -24,4 +30,21 @@ public function user(): BelongsTo
2430
{
2531
return $this->belongsTo(User::class, 'user_id');
2632
}
33+
34+
/**
35+
* Removal from applicant side
36+
*/
37+
public function cancel(): bool
38+
{
39+
if (($notification = $this->notification) !== null) {
40+
UserNotification::batchDestroy(
41+
$this->team->leader_id,
42+
BatchIdentities::fromParams([
43+
'notifications' => [$notification->toIdentityJson()],
44+
]),
45+
);
46+
}
47+
48+
return parent::delete();
49+
}
2750
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
use Illuminate\Database\Migrations\Migration;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\Schema;
11+
12+
return new class extends Migration
13+
{
14+
public function up(): void
15+
{
16+
Schema::table('team_applications', function (Blueprint $table) {
17+
$table->bigInteger('notification_id')->nullable()->after('team_id');
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::table('team_applications', function (Blueprint $table) {
24+
$table->dropColumn('notification_id');
25+
});
26+
}
27+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
use Illuminate\Database\Migrations\Migration;
9+
use Illuminate\Database\Schema\Blueprint;
10+
use Illuminate\Support\Facades\Schema;
11+
12+
return new class extends Migration
13+
{
14+
public function up(): void
15+
{
16+
Schema::table('osu_downloads', function (Blueprint $table) {
17+
$table->unsignedMediumInteger('beatmapset_id')->change();
18+
});
19+
}
20+
21+
public function down(): void
22+
{
23+
Schema::table('osu_downloads', function (Blueprint $table) {
24+
$table->mediumInteger('beatmapset_id')->change();
25+
});
26+
}
27+
};

resources/js/notification-maps/category.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const nameToCategory: Partial<Record<string, string>> = {
4141
forum_topic_reply: 'forum_topic_reply',
4242
team_application_accept: 'team_application',
4343
team_application_reject: 'team_application',
44+
team_application_store: 'team_application',
4445
user_achievement_unlock: 'user_achievement_unlock',
4546
user_beatmapset_new: 'user_beatmapset_new',
4647
user_beatmapset_revive: 'user_beatmapset_new',

resources/js/notification-maps/icons.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const nameToIcons: IconsMap = {
3939
forum_topic_reply: ['fas fa-comment-medical'],
4040
team_application_accept: ['fas fa-users', 'fas fa-check'],
4141
team_application_reject: ['fas fa-users', 'fas fa-times'],
42+
team_application_store: ['fas fa-users', 'fas fa-scroll'],
4243
user_achievement_unlock: ['fas fa-trophy'],
4344
user_beatmapset_new: ['fas fa-music'],
4445
user_beatmapset_revive: ['fas fa-trash-restore'],
@@ -64,6 +65,7 @@ export const nameToIconsCompact: IconsMap = {
6465
forum_topic_reply: ['fas fa-comment-medical'],
6566
team_application_accept: ['fas fa-check'],
6667
team_application_reject: ['fas fa-times'],
68+
team_application_store: ['fas fa-scroll'],
6769
user_beatmapset_new: ['fas fa-music'],
6870
user_beatmapset_revive: ['fas fa-trash-restore'],
6971
};

resources/js/notification-maps/message.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ export function formatMessageGroup(item: Notification) {
9090
};
9191

9292
return trans(`notifications.item.${item.displayType}.${item.category}.${item.category}_group`, replacements);
93+
} else if (item.category === 'team_application') {
94+
return trans('notifications.item.team.team_application.team_application_group');
9395
}
9496

9597
return item.title;

0 commit comments

Comments
 (0)