Skip to content

Commit

Permalink
Fix transitivity
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Jan 7, 2025
1 parent ef4c10a commit 5f0a76f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,47 @@
using Microsoft.AspNetCore.SignalR;
using osu.Game.Online.Friends;

Check failure on line 6 in osu.Server.Spectator/Hubs/Friends/MetadataHubFriendsContext.cs

View workflow job for this annotation

GitHub Actions / Unit testing

The type or namespace name 'Friends' does not exist in the namespace 'osu.Game.Online' (are you missing an assembly reference?)
using osu.Server.Spectator.Database;
using osu.Server.Spectator.Hubs.Metadata;

namespace osu.Server.Spectator.Hubs.Friends
{
public class HubFriendsContext<T>
where T : class, IFriendsClient
public class MetadataHubFriendsContext
{
private readonly IDatabaseFactory databaseFactory;

public HubFriendsContext(Hub<T> hub, IDatabaseFactory databaseFactory)
public MetadataHubFriendsContext(IHubContext<MetadataHub> context, IDatabaseFactory databaseFactory)
{
this.databaseFactory = databaseFactory;

Clients = hub.Clients;
Groups = hub.Groups;
Context = hub.Context;
Clients = context.Clients;
Groups = context.Groups;
}

public async Task OnConnectedAsync(ClientState state)
{
using (var db = databaseFactory.GetInstance())
{
foreach (var friend in await db.GetUserFriendsAsync(state.UserId))
await Groups.AddToGroupAsync(Context.ConnectionId, friend_presence_watchers(friend.zebra_id));
await Groups.AddToGroupAsync(state.ConnectionId, friend_presence_watchers(friend.zebra_id));
}

await Clients.Group(friend_presence_watchers(state.UserId)).FriendConnected(state.UserId);
await Clients.Group(friend_presence_watchers(state.UserId)).SendAsync(nameof(IFriendsClient.FriendConnected), state.UserId);
}

public async Task OnDisconnectedAsync(ClientState state)
{
using (var db = databaseFactory.GetInstance())
{
foreach (var friend in await db.GetUserFriendsAsync(state.UserId))
await Groups.RemoveFromGroupAsync(Context.ConnectionId, friend_presence_watchers(friend.zebra_id));
await Groups.RemoveFromGroupAsync(state.ConnectionId, friend_presence_watchers(friend.zebra_id));
}

await Clients.Group(friend_presence_watchers(state.UserId)).FriendDisconnected(state.UserId);
await Clients.Group(friend_presence_watchers(state.UserId)).SendAsync(nameof(IFriendsClient.FriendDisconnected), state.UserId);
}

private static string friend_presence_watchers(int userId) => $"friends:online-presence-watchers:{userId}";

public IHubCallerClients<T> Clients { get; }
public IHubClients Clients { get; }
public IGroupManager Groups { get; }
public HubCallerContext Context { get; }
}
}
7 changes: 4 additions & 3 deletions osu.Server.Spectator/Hubs/Metadata/MetadataHub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace osu.Server.Spectator.Hubs.Metadata
{
public partial class MetadataHub : StatefulUserHub<IMetadataClient, MetadataClientState>, IMetadataServer
{
private readonly HubFriendsContext<IMetadataClient> friends;
private readonly MetadataHubFriendsContext friends;

private readonly IMemoryCache cache;
private readonly IDatabaseFactory databaseFactory;
Expand All @@ -41,15 +41,16 @@ public MetadataHub(
EntityStore<MetadataClientState> userStates,
IDatabaseFactory databaseFactory,
IDailyChallengeUpdater dailyChallengeUpdater,
IScoreProcessedSubscriber scoreProcessedSubscriber)
IScoreProcessedSubscriber scoreProcessedSubscriber,
IHubContext<MetadataHub> context)
: base(loggerFactory, userStates)
{
this.cache = cache;
this.databaseFactory = databaseFactory;
this.dailyChallengeUpdater = dailyChallengeUpdater;
this.scoreProcessedSubscriber = scoreProcessedSubscriber;

friends = new HubFriendsContext<IMetadataClient>(this, databaseFactory);
friends = new MetadataHubFriendsContext(context, databaseFactory);
}

public override async Task OnConnectedAsync()
Expand Down

0 comments on commit 5f0a76f

Please sign in to comment.