1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-13 02:27:20 +08:00
osu-lazer/osu.Game/Screens/OnlinePlay/Lounge/LoungeListingPoller.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
1.6 KiB
C#
Raw Normal View History

2020-12-19 00:15:41 +09: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.
2025-02-12 18:35:35 +09:00
using System;
using System.Linq;
2020-12-19 00:15:41 +09:00
using System.Threading.Tasks;
using osu.Framework.Allocation;
2020-12-19 00:15:41 +09:00
using osu.Framework.Bindables;
using osu.Game.Online;
using osu.Game.Online.API;
2020-12-25 13:38:11 +09:00
using osu.Game.Online.Rooms;
using osu.Game.Screens.OnlinePlay.Lounge.Components;
2020-12-19 00:15:41 +09:00
namespace osu.Game.Screens.OnlinePlay.Lounge
2020-12-19 00:15:41 +09:00
{
/// <summary>
/// Polls for rooms for the main lounge listing.
2020-12-19 00:15:41 +09:00
/// </summary>
public partial class LoungeListingPoller : PollingComponent
2020-12-19 00:15:41 +09:00
{
[Resolved]
private IAPIProvider api { get; set; } = null!;
2025-02-12 18:35:35 +09:00
public required Action<Room[]> RoomsReceived { get; init; }
public readonly IBindable<FilterCriteria?> Filter = new Bindable<FilterCriteria?>();
2020-12-19 00:15:41 +09:00
2024-11-13 17:15:50 +09:00
private GetRoomsRequest? lastPollRequest;
2020-12-19 00:15:41 +09:00
protected override Task Poll()
{
if (!api.IsLoggedIn)
2020-12-19 00:15:41 +09:00
return base.Poll();
2021-08-17 09:36:43 +09:00
if (Filter.Value == null)
return base.Poll();
lastPollRequest?.Cancel();
2020-12-19 00:15:41 +09:00
2025-02-12 18:35:35 +09:00
var tcs = new TaskCompletionSource<bool>();
var req = new GetRoomsRequest(Filter.Value);
req.Success += result =>
2020-12-19 00:15:41 +09:00
{
2025-02-12 18:35:35 +09:00
RoomsReceived(result.Where(r => r.Category != RoomCategory.DailyChallenge).ToArray());
2020-12-19 00:15:41 +09:00
tcs.SetResult(true);
};
req.Failure += _ => tcs.SetResult(false);
2020-12-19 00:15:41 +09:00
api.Queue(req);
2020-12-19 00:15:41 +09:00
lastPollRequest = req;
2025-02-12 18:35:35 +09:00
2020-12-19 00:15:41 +09:00
return tcs.Task;
}
}
}