Skip to content

Commit

Permalink
Merge pull request #11741 from bdach/beatmap-lio-save-events-to-db
Browse files Browse the repository at this point in the history
Add submission-relevant events to database via LIO endpoints
  • Loading branch information
peppy authored Dec 24, 2024
2 parents 59fc6c1 + b2937ec commit 65d1967
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 15 deletions.
19 changes: 19 additions & 0 deletions app/Http/Controllers/InterOp/BeatmapsetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Models\BeatmapDiscussion;
use App\Models\BeatmapDiscussionPost;
use App\Models\Beatmapset;
use App\Models\Event;
use App\Models\User;

class BeatmapsetsController extends Controller
Expand All @@ -22,6 +23,10 @@ public function broadcastNew($id)

(new UserBeatmapsetNew($beatmapset))->dispatch();

if (request()->boolean('create_event')) {
Event::generate('beatmapsetUpload', ['beatmapset' => $beatmapset]);
}

return response(null, 204);
}

Expand All @@ -31,6 +36,20 @@ public function broadcastRevive($id)

(new UserBeatmapsetRevive($beatmapset))->dispatch();

if (request()->boolean('create_event')) {
Event::generate('beatmapsetRevive', ['beatmapset' => $beatmapset]);
}

return response(null, 204);
}

public function broadcastUpdate($id)
{
$beatmapset = Beatmapset::findOrFail($id);
$user = User::findOrFail(request()->integer('user_id'));

Event::generate('beatmapsetUpdate', ['beatmapset' => $beatmapset, 'user' => $user]);

return response(null, 204);
}

Expand Down
89 changes: 74 additions & 15 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,14 @@ public static function generate($type, $options)

case 'beatmapsetApprove':
$beatmapset = $options['beatmapset'];

$beatmapsetUrl = e(route('beatmapsets.show', $beatmapset, false));
$beatmapsetTitle = e($beatmapset->artist.' - '.$beatmapset->title);
$userName = e($beatmapset->user->username);
$userUrl = e(route('users.show', $beatmapset->user, false));
$beatmapsetParams = static::beatmapsetParams($beatmapset);
$userParams = static::userParams($options['beatmapset']->user);
$approval = e($beatmapset->status());

$textCleanBeatmapsetUrl = $GLOBALS['cfg']['app']['url'].$beatmapsetUrl;
$textCleanUserUrl = $GLOBALS['cfg']['app']['url'].$userUrl;
$textClean = "[{$textCleanBeatmapsetUrl} {$beatmapsetTitle}] by [{$textCleanUserUrl} {$userName}] has just been {$approval}!";

$template = '%s by %s has just been %s!';
$params = [
'text' => "<a href='{$beatmapsetUrl}'>{$beatmapsetTitle}</a> by <b><a href='{$userUrl}'>{$userName}</a></b> has just been {$approval}!",
'text_clean' => $textClean,
'text' => sprintf($template, "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a>", "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b>", $approval),
'text_clean' => sprintf($template, "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]", "[{$userParams['url_clean']} {$userParams['username']}]", $approval),
'beatmap_id' => 0,
'beatmapset_id' => $beatmapset->getKey(),
'user_id' => $beatmapset->user->getKey(),
Expand All @@ -113,11 +107,10 @@ public static function generate($type, $options)

case 'beatmapsetDelete':
$beatmapset = $options['beatmapset'];
$beatmapsetUrl = e(route('beatmapsets.show', $beatmapset, false));
$beatmapsetTitle = e($beatmapset->artist.' - '.$beatmapset->title);
$beatmapsetParams = static::beatmapsetParams($beatmapset);

$params = [
'text' => "<a href='{$beatmapsetUrl}'>{$beatmapsetTitle}</a> has been deleted.",
'text' => "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a> has been deleted.",
'beatmapset_id' => $beatmapset->getKey(),
'user_id' => $options['user']->getKey(),
'private' => false,
Expand All @@ -126,6 +119,60 @@ public static function generate($type, $options)

break;

case 'beatmapsetRevive':
$beatmapset = $options['beatmapset'];
$beatmapsetParams = static::beatmapsetParams($beatmapset);
$userParams = static::userParams($beatmapset->user);

$template = '%s has been revived from eternal slumber by %s.';
$params = [
'text' => sprintf($template, "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a>", "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b>"),
'text_clean' => sprintf($template, "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]", "[{$userParams['url_clean']} {$userParams['username']}]"),
'beatmapset_id' => $beatmapset->getKey(),
'user_id' => $beatmapset->user->getKey(),
'private' => false,
'epicfactor' => 5,
];

break;

case 'beatmapsetUpdate':
$beatmapset = $options['beatmapset'];
$beatmapsetParams = static::beatmapsetParams($beatmapset);
// retrieved separately from options because it doesn't necessarily need to be the same user
// as $beatmapset->user in some cases (see: direct guest difficulty update)
$user = $options['user'];
$userParams = static::userParams($user);

$template = '%s has updated the beatmap "%s"';
$params = [
'text' => sprintf($template, "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b>", "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a>"),
'text_clean' => sprintf($template, "[{$userParams['url_clean']} {$userParams['username']}]", "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"),
'beatmapset_id' => $beatmapset->getKey(),
'user_id' => $user->getKey(),
'private' => false,
'epicfactor' => 2,
];

break;

case 'beatmapsetUpload':
$beatmapset = $options['beatmapset'];
$beatmapsetParams = static::beatmapsetParams($beatmapset);
$userParams = static::userParams($beatmapset->user);

$template = '%s has submitted a new beatmap "%s"';
$params = [
'text' => sprintf($template, "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b>", "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a>"),
'text_clean' => sprintf($template, "[{$userParams['url_clean']} {$userParams['username']}]", "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]"),
'beatmapset_id' => $beatmapset->getKey(),
'user_id' => $beatmapset->user->getKey(),
'private' => false,
'epicfactor' => 4,
];

break;

case 'usernameChange':
$user = static::userParams($options['user']);
$oldUsername = e($options['history']->username_last);
Expand Down Expand Up @@ -430,10 +477,22 @@ public function scopeRecent($query)

private static function userParams($user)
{
$url = e(route('users.show', $user, false));
return [
'id' => $user->getKey(),
'username' => e($user->username),
'url' => e(route('users.show', $user, false)),
'url' => $url,
'url_clean' => $GLOBALS['cfg']['app']['url'].$url,
];
}

private static function beatmapsetParams($beatmapset)
{
$url = e(route('beatmapsets.show', $beatmapset, false));
return [
'title' => e($beatmapset->artist.' - '.$beatmapset->title),
'url' => $url,
'url_clean' => $GLOBALS['cfg']['app']['url'].$url,
];
}
}
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@
Route::group(['prefix' => '{beatmapset}'], function () {
Route::post('broadcast-new', 'BeatmapsetsController@broadcastNew')->name('broadcast-new');
Route::post('broadcast-revive', 'BeatmapsetsController@broadcastRevive')->name('broadcast-revive');
Route::post('broadcast-update', 'BeatmapsetsController@broadcastUpdate')->name('broadcast-update');
Route::post('disqualify', 'BeatmapsetsController@disqualify')->name('disqualify');
});
});
Expand Down

0 comments on commit 65d1967

Please sign in to comment.