Skip to content

Commit

Permalink
Merge branch 'master' into legacy-score-id-zero
Browse files Browse the repository at this point in the history
  • Loading branch information
nanaya authored Apr 24, 2024
2 parents b589471 + 5630138 commit efd5bf9
Show file tree
Hide file tree
Showing 25 changed files with 242 additions and 171 deletions.
16 changes: 15 additions & 1 deletion app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Handler extends ExceptionHandler
public static function exceptionMessage($e)
{
if ($e instanceof ModelNotFoundException) {
return;
return static::modelNotFoundMessage($e);
}

if (static::statusCode($e) >= 500) {
Expand Down Expand Up @@ -90,6 +90,20 @@ private static function isOAuthSessionException(Throwable $e): bool
&& $e->getMessage() === 'Authorization request was not present in the session.';
}

private static function modelNotFoundMessage(ModelNotFoundException $e): string
{
$model = $e->getModel();
$modelTransKey = "models.name.{$model}";

$params = [
'model' => trans_exists($modelTransKey, $GLOBALS['cfg']['app']['fallback_locale'])
? osu_trans($modelTransKey)
: trim(strtr($model, ['App\Models\\' => '']), '\\'),
];

return osu_trans('models.not_found', $params);
}

private static function reportWithSentry(Throwable $e): void
{
$ref = log_error_sentry($e, ['http_code' => (string) static::statusCode($e)]);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/BeatmapsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ private static function beatmapScores(string $id, ?string $scoreTransformerType,
'type' => $type,
'user' => $currentUser,
]);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country']);
$scores = $esFetch->all()->loadMissing(['beatmap', 'user.country', 'processHistory']);
$userScore = $esFetch->userBest();
$scoreTransformer = new ScoreTransformer($scoreTransformerType);

Expand Down Expand Up @@ -494,7 +494,7 @@ public function userScoreAll($beatmapId, $userId)
'sort' => 'score_desc',
'user_id' => (int) $userId,
]);
$scores = (new ScoreSearch($params))->records();
$scores = (new ScoreSearch($params))->records()->loadMissing('processHistory');

return [
'scores' => json_collection($scores, new ScoreTransformer()),
Expand Down
2 changes: 2 additions & 0 deletions app/Libraries/Search/ArtistTrackSearchParams.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ class ArtistTrackSearchParams extends SearchParams
public ?string $album;
public ?string $artist;
public ?array $bpm;
public ?array $bpmInput;
public bool $exclusiveOnly = false;
public ?string $genre;
public bool $isDefaultSort = false;
public ?array $length;
public ?array $lengthInput;
public string $sortField;
public string $sortOrder;

Expand Down
6 changes: 6 additions & 0 deletions app/Models/Solo/Score.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ public function user()
return $this->belongsTo(User::class, 'user_id');
}

public function processHistory()
{
return $this->hasOne(ScoreProcessHistory::class, 'score_id');
}

public function scopeDefault(Builder $query): Builder
{
return $query->whereHas('beatmap.beatmapset');
Expand Down Expand Up @@ -243,6 +248,7 @@ public function getAttribute($key)

'beatmap',
'performance',
'processHistory',
'reportedIn',
'user' => $this->getRelationValue($key),
};
Expand Down
25 changes: 25 additions & 0 deletions app/Models/Solo/ScoreProcessHistory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\Models\Solo;

use App\Models\Model;

/**
* @property int $score_id
* @property int $processed_version
* @property \Carbon\Carbon $processed_at
*/
class ScoreProcessHistory extends Model
{
protected $table = 'score_process_history';

public function score()
{
return $this->belongsTo(Score::class, 'score_id');
}
}
9 changes: 0 additions & 9 deletions app/Transformers/Multiplayer/RoomTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class RoomTransformer extends TransformerAbstract
'playlist',
'playlist_item_stats',
'recent_participants',
'scores',
];

public function transform(Room $room)
Expand Down Expand Up @@ -94,12 +93,4 @@ public function includePlaylistItemStats(Room $room)
{
return $this->primitive($room->playlistItemStats());
}

public function includeScores(Room $room)
{
return $this->collection(
$room->scores()->completed()->get(),
new ScoreTransformer()
);
}
}
3 changes: 3 additions & 0 deletions app/Transformers/ScoreTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ScoreTransformer extends TransformerAbstract
// warning: the preload is actually for PlaylistItemUserHighScore, not for Score
const MULTIPLAYER_BASE_PRELOAD = [
'scoreLink.score',
'scoreLink.score.processHistory',
'scoreLink.user.country',
];

Expand All @@ -35,6 +36,7 @@ class ScoreTransformer extends TransformerAbstract
const USER_PROFILE_INCLUDES_PRELOAD = [
'beatmap',
'beatmap.beatmapset',
'processHistory',
// it's for user profile so the user is already available
// 'user',
];
Expand Down Expand Up @@ -102,6 +104,7 @@ public function transformSolo(MultiplayerScoreLink|ScoreModel|SoloScore $score)
if ($score instanceof SoloScore) {
$extraAttributes['ranked'] = $score->ranked;
$extraAttributes['preserve'] = $score->preserve;
$extraAttributes['processed'] = $score->legacy_score_id !== null || $score->processHistory !== null;
}

$hasReplay = $score->has_replay;
Expand Down
1 change: 0 additions & 1 deletion resources/js/components/block-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export default class BlockButton extends React.Component<Props> {
if (core.currentUser != null) {
core.currentUser.blocks = data.filter((d) => d.relation_type === 'block');
core.currentUser.friends = data.filter((d) => d.relation_type === 'friend');
$.publish('user:update', core.currentUser);
}

this.props.onClick?.();
Expand Down
8 changes: 3 additions & 5 deletions resources/js/components/follow-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface State {
toggling: boolean;
}

// TODO: mobx and turn to observer
export default class FollowToggle extends React.PureComponent<Props, State> {
static defaultProps = {
following: true,
Expand Down Expand Up @@ -81,10 +82,7 @@ export default class FollowToggle extends React.PureComponent<Props, State> {
this.toggleXhr = $.ajax(route('follows.store'), { data: params, method })
.done(() => {
if (this.props.follow.subtype === 'mapping') {
$.publish('user:followUserMapping:update', {
following: !this.state.following,
userId: this.props.follow.notifiable_id,
});
core.currentUserModel.updateFollowUserMapping(!this.state.following, this.props.follow.notifiable_id);
} else {
this.setState({ following: !this.state.following });
}
Expand All @@ -97,7 +95,7 @@ export default class FollowToggle extends React.PureComponent<Props, State> {
private readonly refresh = () => {
if (this.props.follow.subtype === 'mapping') {
this.setState({
following: core.currentUser != null && core.currentUser.follow_user_mapping.includes(this.props.follow.notifiable_id),
following: core.currentUserModel.following.has(this.props.follow.notifiable_id),
});
}
};
Expand Down
7 changes: 4 additions & 3 deletions resources/js/components/follow-user-mapping-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface State {

const bn = 'user-action-button';

// TODO: mobx and turn to observer
export default class FollowUserMappingButton extends React.Component<Props, State> {
private readonly buttonRef = React.createRef<HTMLButtonElement>();
private readonly eventId = `follow-user-mapping-button-${nextVal()}`;
Expand All @@ -35,7 +36,7 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat
constructor(props: Props) {
super(props);

const following = core.currentUser?.follow_user_mapping.includes(this.props.userId) ?? false;
const following = core.currentUserModel.following.has(this.props.userId);
let followersWithoutSelf = this.props.followers ?? 0;

if (following !== false) followersWithoutSelf -= 1;
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat

private readonly refresh = () => {
this.setState({
following: core.currentUser?.follow_user_mapping.includes(this.props.userId) ?? false,
following: core.currentUserModel.following.has(this.props.userId),
});
};

Expand Down Expand Up @@ -152,6 +153,6 @@ export default class FollowUserMappingButton extends React.Component<Props, Stat
}

private readonly updateData = () => {
$.publish('user:followUserMapping:update', { following: !this.state.following, userId: this.props.userId });
core.currentUserModel.updateFollowUserMapping(!this.state.following, this.props.userId);
};
}
1 change: 0 additions & 1 deletion resources/js/components/friend-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export default class FriendButton extends React.Component<Props> {

// TODO: move logic to a user object?
core.currentUser.friends = data;
$.publish('user:update', core.currentUser);
dispatch(new FriendUpdated(this.props.userId));
};
}
32 changes: 0 additions & 32 deletions resources/js/core-legacy/account-edit-blocklist.coffee

This file was deleted.

55 changes: 0 additions & 55 deletions resources/js/core-legacy/current-user-observer.coffee

This file was deleted.

46 changes: 0 additions & 46 deletions resources/js/core-legacy/sticky-footer.coffee

This file was deleted.

Loading

0 comments on commit efd5bf9

Please sign in to comment.