Skip to content

Commit

Permalink
Merge branch 'master' into feature/beatmapset-show-user-tags
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya authored Jan 14, 2025
2 parents 3dee3fc + 8b77760 commit bdffa17
Show file tree
Hide file tree
Showing 478 changed files with 5,437 additions and 924 deletions.
27 changes: 27 additions & 0 deletions app/Casts/TimestampOrZero.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

declare(strict_types=1);

namespace App\Casts;

use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;

/**
* For columns which use unix timestamp as its value and repurpose 0 as null.
*/
class TimestampOrZero implements CastsAttributes
{
public function get($model, string $key, $value, array $attributes)
{
return $value === null || $value === 0 ? null : Carbon::createFromTimestamp($value);
}

public function set($model, string $key, $value, array $attributes)
{
return $value === null ? 0 : $value->getTimestamp();
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public function setLocale()
]);
}

return ext_view('layout.ujs-reload', [], 'js')
return ext_view('layout.ujs_full_reload', [], 'js')
->withCookie(cookie()->forever('locale', $newLocale));
}

Expand Down
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
17 changes: 17 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@

class TeamsController extends Controller
{
public function __construct()
{
parent::__construct();
$this->middleware('auth', ['only' => ['part']]);
}

public function edit(string $id): Response
{
$team = Team::findOrFail($id);
Expand All @@ -21,6 +27,17 @@ public function edit(string $id): Response
return ext_view('teams.edit', compact('team'));
}

public function part(string $id): Response
{
$team = Team::findOrFail($id);
priv_check('TeamPart', $team)->ensureCan();

$team->members()->findOrFail(\Auth::user()->getKey())->delete();
\Session::flash('popup', osu_trans('teams.part.ok'));

return ujs_redirect(route('teams.show', ['team' => $team]));
}

public function show(string $id): Response
{
$team = Team
Expand Down
2 changes: 1 addition & 1 deletion app/Jobs/Notifications/BroadcastNotificationBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public function handle()

$pushReceiverIds = [];
$notification->getConnection()->transaction(function () use ($deliverySettings, $notification, &$pushReceiverIds) {
$timestamp = (string) $this->getTimestamp();
$timestamp = $this->getTimestamp()->format('Y-m-d H:i:s');
$notificationId = $notification->getKey();
$tempUserNotification = new UserNotification();

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,
];
}
}
16 changes: 3 additions & 13 deletions app/Models/Forum/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Models\Forum;

use App\Casts\TimestampOrZero;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
Expand All @@ -26,7 +27,7 @@
* @property string $forum_image
* @property int $forum_last_post_id
* @property string $forum_last_post_subject
* @property int $forum_last_post_time
* @property \Carbon\Carbon|null $forum_last_post_time
* @property string $forum_last_poster_colour
* @property int $forum_last_poster_id
* @property string $forum_last_poster_name
Expand Down Expand Up @@ -67,10 +68,9 @@ class Forum extends Model
'allow_topic_covers' => 'boolean',
'enable_indexing' => 'boolean',
'enable_sigs' => 'boolean',
'forum_last_post_time' => 'datetime',
'forum_last_post_time' => TimestampOrZero::class,
'moderator_groups' => 'array',
];
protected $dateFormat = 'U';
protected $primaryKey = 'forum_id';
protected $table = 'phpbb_forums';

Expand Down Expand Up @@ -242,16 +242,6 @@ public function setForumLastPosterColourAttribute($value)
$this->attributes['forum_last_poster_colour'] = ltrim($value, '#');
}

public function getForumLastPostTimeAttribute($value)
{
return get_time_or_null($value);
}

public function setForumLastPostTimeAttribute($value)
{
$this->attributes['forum_last_post_time'] = get_timestamp_or_zero($value);
}

// feature forum shall have extra features like sorting and voting
public function isFeatureForum()
{
Expand Down
27 changes: 5 additions & 22 deletions app/Models/Forum/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace App\Models\Forum;

use App\Casts\TimestampOrZero;
use App\Exceptions\ModelNotSavedException;
use App\Jobs\EsDocument;
use App\Jobs\MarkNotificationsRead;
Expand Down Expand Up @@ -48,7 +49,7 @@
* @property int $post_reported
* @property string $post_subject
* @property mixed $post_text
* @property int $post_time
* @property \Carbon\Carbon|null $post_time
* @property string $post_username
* @property int $poster_id
* @property string $poster_ip
Expand Down Expand Up @@ -81,8 +82,10 @@ class Post extends Model implements AfterCommit, Indexable, Traits\ReportableInt
public $timestamps = false;

protected $casts = [
'post_edit_locked' => 'boolean',
'post_approved' => 'boolean',
'post_edit_locked' => 'boolean',
'post_edit_time' => TimestampOrZero::class,
'post_time' => TimestampOrZero::class,
];

private $normalizedUsers = [];
Expand Down Expand Up @@ -156,26 +159,6 @@ public function getPostEditUserAttribute($value)
}
}

public function setPostTimeAttribute($value)
{
$this->attributes['post_time'] = get_timestamp_or_zero($value);
}

public function getPostTimeAttribute($value)
{
return get_time_or_null($value);
}

public function setPostEditTimeAttribute($value)
{
$this->attributes['post_edit_time'] = get_timestamp_or_zero($value);
}

public function getPostEditTimeAttribute($value)
{
return get_time_or_null($value);
}

/**
* Gets a preview of the post_text by stripping anything that
* looks like bbcode or html.
Expand Down
Loading

0 comments on commit bdffa17

Please sign in to comment.