mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 02:32:59 +08:00
Load api room before displaying notification
This commit is contained in:
parent
3879775219
commit
8e73dbc894
@ -46,8 +46,9 @@ namespace osu.Game.Online.Multiplayer
|
||||
/// Signals that a user has been invited into a multiplayer room.
|
||||
/// </summary>
|
||||
/// <param name="invitedBy">Id of user that invited the player.</param>
|
||||
/// <param name="room">The room the user got invited to.</param>
|
||||
Task Invited(int invitedBy, MultiplayerRoom room);
|
||||
/// <param name="roomID">Id of the room the user got invited to.</param>
|
||||
/// <param name="password">Password to join the room.</param>
|
||||
Task Invited(int invitedBy, long roomID, string password);
|
||||
|
||||
/// <summary>
|
||||
/// Signal that the host of the room has changed.
|
||||
|
@ -11,6 +11,7 @@ using Newtonsoft.Json;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Development;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Database;
|
||||
@ -30,6 +31,8 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
public Action<Notification>? PostNotification { protected get; set; }
|
||||
|
||||
public Action<Room, string>? InviteAccepted { protected get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when any change occurs to the multiplayer room.
|
||||
/// </summary>
|
||||
@ -442,20 +445,50 @@ namespace osu.Game.Online.Multiplayer
|
||||
return handleUserLeft(user, UserKicked);
|
||||
}
|
||||
|
||||
async Task IMultiplayerClient.Invited(int invitedBy, MultiplayerRoom room)
|
||||
async Task IMultiplayerClient.Invited(int invitedBy, long roomID, string password)
|
||||
{
|
||||
var user = await userLookupCache.GetUserAsync(invitedBy).ConfigureAwait(false);
|
||||
var loadUserTask = userLookupCache.GetUserAsync(invitedBy);
|
||||
var loadRoomTask = loadRoom(roomID);
|
||||
|
||||
if (user == null) return;
|
||||
await Task.WhenAll(loadUserTask, loadRoomTask).ConfigureAwait(false);
|
||||
|
||||
APIUser? apiUser = loadUserTask.GetResultSafely();
|
||||
Room? apiRoom = loadRoomTask.GetResultSafely();
|
||||
|
||||
if (apiUser == null || apiRoom == null) return;
|
||||
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
PostNotification?.Invoke(
|
||||
new UserAvatarNotification(user, $"{user.Username} invited you to a multiplayer match:\"{room.Settings.Name}\"!")
|
||||
new UserAvatarNotification(apiUser, $"{apiUser.Username} invited you to a multiplayer match:\"{apiRoom.Name}\"!")
|
||||
{
|
||||
Activated = () =>
|
||||
{
|
||||
InviteAccepted?.Invoke(apiRoom, password);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private Task<Room?> loadRoom(long id)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
var t = new TaskCompletionSource<Room?>();
|
||||
var request = new GetRoomRequest(id);
|
||||
|
||||
request.Success += room => t.TrySetResult(room);
|
||||
|
||||
request.Failure += e => t.TrySetResult(null);
|
||||
|
||||
API.Queue(request);
|
||||
|
||||
return t.Task;
|
||||
});
|
||||
}
|
||||
|
||||
private void addUserToAPIRoom(MultiplayerRoomUser user)
|
||||
{
|
||||
Debug.Assert(APIRoom != null);
|
||||
|
@ -50,7 +50,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
|
||||
connection.On<MultiplayerRoomUser>(nameof(IMultiplayerClient.UserKicked), ((IMultiplayerClient)this).UserKicked);
|
||||
connection.On<int, MultiplayerRoom>(nameof(IMultiplayerClient.Invited), ((IMultiplayerClient)this).Invited);
|
||||
connection.On<int, long, string>(nameof(IMultiplayerClient.Invited), ((IMultiplayerClient)this).Invited);
|
||||
connection.On<int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
|
||||
connection.On<MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
|
||||
connection.On<int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
|
||||
|
Loading…
Reference in New Issue
Block a user