mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 11:07:52 +08:00
Add and consume multi-lookup API endpoint
This commit is contained in:
parent
aa252d562a
commit
db039da668
19
osu.Game/Online/API/Requests/GetUsersRequest.cs
Normal file
19
osu.Game/Online/API/Requests/GetUsersRequest.cs
Normal file
@ -0,0 +1,19 @@
|
||||
// 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.
|
||||
|
||||
using System.Linq;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUsersRequest : APIRequest<GetUsersResponse>
|
||||
{
|
||||
private readonly int[] userIds;
|
||||
|
||||
public GetUsersRequest(int[] userIds)
|
||||
{
|
||||
this.userIds = userIds;
|
||||
}
|
||||
|
||||
protected override string Target => $@"users/?{userIds.Select(u => $"ids[]={u}&").Aggregate((a, b) => a + b)}";
|
||||
}
|
||||
}
|
15
osu.Game/Online/API/Requests/GetUsersResponse.cs
Normal file
15
osu.Game/Online/API/Requests/GetUsersResponse.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Online.API.Requests
|
||||
{
|
||||
public class GetUsersResponse : ResponseWithCursor
|
||||
{
|
||||
[JsonProperty("users")]
|
||||
public List<User> Users;
|
||||
}
|
||||
}
|
@ -54,17 +54,18 @@ namespace osu.Game.Overlays.Dashboard
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
foreach (var u in e.NewItems.OfType<int>())
|
||||
var request = new GetUsersRequest(e.NewItems.OfType<int>().ToArray());
|
||||
|
||||
request.Success += users => Schedule(() =>
|
||||
{
|
||||
var request = new GetUserRequest(u);
|
||||
request.Success += user => Schedule(() =>
|
||||
foreach (var user in users.Users)
|
||||
{
|
||||
if (playingUsers.Contains(user.Id))
|
||||
userFlow.Add(createUserPanel(user));
|
||||
});
|
||||
api.Queue(request);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
api.Queue(request);
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
|
@ -131,8 +131,7 @@ namespace osu.Game.Overlays
|
||||
break;
|
||||
|
||||
case DashboardOverlayTabs.CurrentlyPlaying:
|
||||
//todo: enable once caching logic is better
|
||||
//loadDisplay(new CurrentlyPlayingDisplay());
|
||||
loadDisplay(new CurrentlyPlayingDisplay());
|
||||
break;
|
||||
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user