2020-12-18 23:15:41 +08:00
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-12-18 23:15:41 +08:00
|
|
|
using System.Threading.Tasks;
|
2020-12-25 12:38:11 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2020-12-18 23:15:41 +08:00
|
|
|
|
2020-12-25 23:50:00 +08:00
|
|
|
namespace osu.Game.Screens.OnlinePlay.Components
|
2020-12-18 23:15:41 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// A <see cref="RoomPollingComponent"/> that polls for the currently-selected room.
|
|
|
|
/// </summary>
|
|
|
|
public class SelectionPollingComponent : RoomPollingComponent
|
|
|
|
{
|
2021-08-19 15:40:39 +08:00
|
|
|
private readonly Room room;
|
|
|
|
|
|
|
|
public SelectionPollingComponent(Room room)
|
2020-12-18 23:15:41 +08:00
|
|
|
{
|
2021-08-19 15:40:39 +08:00
|
|
|
this.room = room;
|
2020-12-18 23:15:41 +08:00
|
|
|
}
|
|
|
|
|
2022-01-28 12:43:53 +08:00
|
|
|
private GetRoomRequest lastPollRequest;
|
2020-12-18 23:15:41 +08:00
|
|
|
|
|
|
|
protected override Task Poll()
|
|
|
|
{
|
|
|
|
if (!API.IsLoggedIn)
|
|
|
|
return base.Poll();
|
|
|
|
|
2021-08-19 15:40:39 +08:00
|
|
|
if (room.RoomID.Value == null)
|
2020-12-18 23:15:41 +08:00
|
|
|
return base.Poll();
|
|
|
|
|
|
|
|
var tcs = new TaskCompletionSource<bool>();
|
|
|
|
|
2022-01-28 12:43:53 +08:00
|
|
|
lastPollRequest?.Cancel();
|
2020-12-18 23:15:41 +08:00
|
|
|
|
2022-01-28 12:43:53 +08:00
|
|
|
var req = new GetRoomRequest(room.RoomID.Value.Value);
|
|
|
|
|
|
|
|
req.Success += result =>
|
2020-12-18 23:15:41 +08:00
|
|
|
{
|
2021-09-15 16:03:26 +08:00
|
|
|
result.RemoveExpiredPlaylistItems();
|
2021-08-13 16:39:09 +08:00
|
|
|
RoomManager.AddOrUpdateRoom(result);
|
2020-12-18 23:15:41 +08:00
|
|
|
tcs.SetResult(true);
|
|
|
|
};
|
|
|
|
|
2022-01-28 12:43:53 +08:00
|
|
|
req.Failure += _ => tcs.SetResult(false);
|
|
|
|
|
|
|
|
API.Queue(req);
|
2020-12-18 23:15:41 +08:00
|
|
|
|
2022-01-28 12:43:53 +08:00
|
|
|
lastPollRequest = req;
|
2020-12-18 23:15:41 +08:00
|
|
|
|
|
|
|
return tcs.Task;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|