Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add submission-relevant events to database via LIO endpoints #11741

Merged
merged 4 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 76 additions & 13 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +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}!";
$textClean = "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}] by [{$userParams['url_clean']} {$userParams['username']}] has just been {$approval}!";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it's better to have same template string for both text and textClean and fill it up with sprintf accordingly, kinda similar to how it was originally done

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like b2937ec?

I'd say it's a beneficial change yeah, because only thanks to it I noticed two of the events I added had quotes missing in the text_clean variant that should have been there 😅


$params = [
'text' => "<a href='{$beatmapsetUrl}'>{$beatmapsetTitle}</a> by <b><a href='{$userUrl}'>{$userName}</a></b> has just been {$approval}!",
'text' => "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a> by <b><a href='{$userParams['url']}'>{$userParams['username']}</a></b> has just been {$approval}!",
'text_clean' => $textClean,
'beatmap_id' => 0,
'beatmapset_id' => $beatmapset->getKey(),
Expand All @@ -113,11 +108,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 +120,63 @@ public static function generate($type, $options)

break;

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

$textClean = "[{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}] has been revived from eternal slumber by [{$userParams['url_clean']} {$userParams['username']}]";

$params = [
'text' => "<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a> has been revived from eternal slumber by <b><a href='{$userParams['url']}'>{$userParams['username']}</a></b>",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing period

'text_clean' => $textClean,
'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);

$textClean = "[{$userParams['url_clean']} {$userParams['username']}] has updated the beatmap [{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]";

$params = [
'text' => "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b> has updated the beatmap \"<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}</a>\"",
'text_clean' => $textClean,
'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);

$textClean = "[{$userParams['url_clean']} {$userParams['username']}] has submitted a new beatmap [{$beatmapsetParams['url_clean']} {$beatmapsetParams['title']}]";

$params = [
'text' => "<b><a href='{$userParams['url']}'>{$userParams['username']}</a></b> has submitted a new beatmap \"<a href='{$beatmapsetParams['url']}'>{$beatmapsetParams['title']}\"</a>",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closing quote should be after </a>

'text_clean' => $textClean,
'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 +481,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 @@ -588,6 +588,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
Loading