diff --git a/osu.Game/Extensions/ModelExtensions.cs b/osu.Game/Extensions/ModelExtensions.cs index efb3c4d633..eef9b63b62 100644 --- a/osu.Game/Extensions/ModelExtensions.cs +++ b/osu.Game/Extensions/ModelExtensions.cs @@ -114,8 +114,24 @@ namespace osu.Game.Extensions /// /// The instance to compare. /// The other instance to compare against. - /// Whether online IDs match. If either instance is missing an online ID, this will return false. - public static bool MatchesOnlineID(this IScoreInfo? instance, IScoreInfo? other) => matchesOnlineID(instance, other); + /// + /// Whether online IDs match. + /// Both and are checked, in that order. + /// If either instance is missing an online ID, this will return false. + /// + public static bool MatchesOnlineID(this IScoreInfo? instance, IScoreInfo? other) + { + if (matchesOnlineID(instance, other)) + return true; + + if (instance == null || other == null) + return false; + + if (instance.LegacyOnlineID < 0 || other.LegacyOnlineID < 0) + return false; + + return instance.LegacyOnlineID.Equals(other.LegacyOnlineID); + } private static bool matchesOnlineID(this IHasOnlineID? instance, IHasOnlineID? other) { diff --git a/osu.Game/Online/ScoreDownloadTracker.cs b/osu.Game/Online/ScoreDownloadTracker.cs index de42292372..dfdac24d19 100644 --- a/osu.Game/Online/ScoreDownloadTracker.cs +++ b/osu.Game/Online/ScoreDownloadTracker.cs @@ -39,7 +39,8 @@ namespace osu.Game.Online var scoreInfo = new ScoreInfo { ID = TrackedItem.ID, - OnlineID = TrackedItem.OnlineID + OnlineID = TrackedItem.OnlineID, + LegacyOnlineID = TrackedItem.LegacyOnlineID }; Downloader.DownloadBegan += downloadBegan; @@ -47,6 +48,7 @@ namespace osu.Game.Online realmSubscription = realm.RegisterForNotifications(r => r.All().Where(s => ((s.OnlineID > 0 && s.OnlineID == TrackedItem.OnlineID) + || (s.LegacyOnlineID > 0 && s.LegacyOnlineID == TrackedItem.LegacyOnlineID) || (!string.IsNullOrEmpty(s.Hash) && s.Hash == TrackedItem.Hash)) && !s.DeletePending), (items, _) => { diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 885077a8e8..2f11964f6a 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -678,6 +678,9 @@ namespace osu.Game if (score.OnlineID > 0) databasedScoreInfo = ScoreManager.Query(s => s.OnlineID == score.OnlineID); + if (score.LegacyOnlineID > 0) + databasedScoreInfo ??= ScoreManager.Query(s => s.LegacyOnlineID == score.LegacyOnlineID); + if (score is ScoreInfo scoreInfo) databasedScoreInfo ??= ScoreManager.Query(s => s.Hash == scoreInfo.Hash); diff --git a/osu.Game/Scoring/IScoreInfo.cs b/osu.Game/Scoring/IScoreInfo.cs index d17558f800..4083d57fa0 100644 --- a/osu.Game/Scoring/IScoreInfo.cs +++ b/osu.Game/Scoring/IScoreInfo.cs @@ -24,6 +24,8 @@ namespace osu.Game.Scoring bool HasReplay { get; } + long LegacyOnlineID { get; } + DateTimeOffset Date { get; } double? PP { get; } diff --git a/osu.Game/Scoring/ScoreManager.cs b/osu.Game/Scoring/ScoreManager.cs index 31b5bd8365..02d9e0a280 100644 --- a/osu.Game/Scoring/ScoreManager.cs +++ b/osu.Game/Scoring/ScoreManager.cs @@ -150,7 +150,11 @@ namespace osu.Game.Scoring public Task Import(ImportTask[] imports, ImportParameters parameters = default) => scoreImporter.Import(imports, parameters); - public override bool IsAvailableLocally(ScoreInfo model) => Realm.Run(realm => realm.All().Any(s => s.OnlineID == model.OnlineID)); + public override bool IsAvailableLocally(ScoreInfo model) + => Realm.Run(realm => realm.All() + // this basically inlines `ModelExtension.MatchesOnlineID(IScoreInfo, IScoreInfo)`, + // because that method can't be used here, as realm can't translate it to its query language. + .Any(s => s.OnlineID == model.OnlineID || s.LegacyOnlineID == model.LegacyOnlineID)); public IEnumerable HandledExtensions => scoreImporter.HandledExtensions;