Proof of concept realm subscriptions via Register

This commit is contained in:
Dean Herbert
2022-01-23 19:42:26 +09:00
parent f39ff1eacb
commit 61cef42be9
4 changed files with 112 additions and 20 deletions

View File

@ -17,6 +17,7 @@ using osu.Game.Online.Spectator;
using osu.Game.Replays;
using osu.Game.Rulesets;
using osu.Game.Scoring;
using Realms;
namespace osu.Game.Screens.Spectate
{
@ -79,23 +80,21 @@ namespace osu.Game.Screens.Spectate
playingUserStates.BindTo(spectatorClient.PlayingUserStates);
playingUserStates.BindCollectionChanged(onPlayingUserStatesChanged, true);
realmSubscription = realmContextFactory.Register(realm =>
realm.All<BeatmapSetInfo>()
.Where(s => !s.DeletePending)
.QueryAsyncWithNotifications((items, changes, ___) =>
{
if (changes?.InsertedIndices == null)
return;
foreach (int c in changes.InsertedIndices)
beatmapUpdated(items[c]);
}));
realmSubscription = realmContextFactory.Register(
realm => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending), beatmapsChanged);
foreach ((int id, var _) in userMap)
spectatorClient.WatchUser(id);
}));
}
private void beatmapsChanged(IRealmCollection<BeatmapSetInfo> items, ChangeSet changes, Exception ___)
{
if (changes?.InsertedIndices == null) return;
foreach (int c in changes.InsertedIndices) beatmapUpdated(items[c]);
}
private void beatmapUpdated(BeatmapSetInfo beatmapSet)
{
foreach ((int userId, _) in userMap)