Add and consume multi-lookup API endpoint

This commit is contained in:
Dean Herbert 2020-11-06 12:54:08 +09:00
parent aa252d562a
commit db039da668
4 changed files with 42 additions and 8 deletions

View 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)}";
}
}

View 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;
}
}

View File

@ -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:

View File

@ -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: