diff --git a/app/Http/Controllers/InterOp/BeatmapsetsController.php b/app/Http/Controllers/InterOp/BeatmapsetsController.php index ed8a9de7803..64b5f1d8064 100644 --- a/app/Http/Controllers/InterOp/BeatmapsetsController.php +++ b/app/Http/Controllers/InterOp/BeatmapsetsController.php @@ -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 @@ -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); } @@ -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); } diff --git a/app/Models/Event.php b/app/Models/Event.php index b7e48085928..1a58e0372f3 100644 --- a/app/Models/Event.php +++ b/app/Models/Event.php @@ -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' => "{$beatmapsetTitle} by {$userName} has just been {$approval}!", - 'text_clean' => $textClean, + 'text' => sprintf($template, "{$beatmapsetParams['title']}", "{$userParams['username']}", $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(), @@ -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' => "{$beatmapsetTitle} has been deleted.", + 'text' => "{$beatmapsetParams['title']} has been deleted.", 'beatmapset_id' => $beatmapset->getKey(), 'user_id' => $options['user']->getKey(), 'private' => false, @@ -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, "{$beatmapsetParams['title']}", "{$userParams['username']}"), + '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, "{$userParams['username']}", "{$beatmapsetParams['title']}"), + '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, "{$userParams['username']}", "{$beatmapsetParams['title']}"), + '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); @@ -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, ]; } } diff --git a/routes/web.php b/routes/web.php index bdfac527ab9..2dc8ccb6689 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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'); }); });