a few fixes related to highscore notifications (#1086)
Some checks failed
Continuous Integration / Build & Test (push) Has been cancelled
Upload Translations to Crowdin / crowdin-sync (push) Has been cancelled
Build Docker Image / Build and Publish (push) Has been cancelled
Qodana / qodana (push) Has been cancelled

This commit is contained in:
Kat 2025-01-13 19:13:41 -08:00 committed by GitHub
parent a528c65445
commit b428b35f3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -152,7 +152,9 @@ public class ScoreController : ControllerBase
this.database.Scores.Add(existingScore);
}
if (score.Points > existingScore.Points)
bool personalBest = score.Points > existingScore.Points;
if (personalBest)
{
existingScore.Points = score.Points;
existingScore.Timestamp = TimeHelper.TimestampMillis;
@ -172,12 +174,14 @@ public class ScoreController : ControllerBase
TargetPlayerIds = null,
});
if (score.Type == 1 && scores.YourRank == 1 && scores.Total > 1)
// if this is a PB, singleplayer, at the top of the leaderboard (not scores.YourRank==1 because it might be tied), and there is at least one other score,
// send a notification to the user with the previous highscore
if (personalBest && score.Type == 1 && scores.Scores[0].UserId == token.UserId && scores.Total > 1)
{
GameScore? second = scores.Scores[1];
UserEntity? user = await this.database.UserFromGameToken(token);
await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", true);
await this.database.SendNotification(second.UserId, $"{user?.InfoXml} beat your highscore (<em>{second.Points}</em>) on {slot.InfoXml} with a score of <em>{score.Points}</em>.", false);
}
return this.Ok(scores);