osu/osu.Game/Database/UserLookupCache.cs

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

36 lines
1.7 KiB
C#
Raw Normal View History

2020-11-06 07:38:57 +00: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.
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
2020-11-06 07:38:57 +00:00
namespace osu.Game.Database
{
public partial class UserLookupCache : OnlineLookupCache<int, APIUser, LookupUsersRequest>
2020-11-06 07:38:57 +00:00
{
/// <summary>
/// Perform an API lookup on the specified user, populating a <see cref="APIUser"/> model.
/// </summary>
/// <param name="userId">The user to lookup.</param>
/// <param name="token">An optional cancellation token.</param>
/// <returns>The populated user, or null if the user does not exist or the request could not be satisfied.</returns>
public Task<APIUser?> GetUserAsync(int userId, CancellationToken token = default) => LookupAsync(userId, token);
2020-11-06 07:38:57 +00:00
/// <summary>
/// Perform an API lookup on the specified users, populating a <see cref="APIUser"/> model.
/// </summary>
/// <param name="userIds">The users to lookup.</param>
/// <param name="token">An optional cancellation token.</param>
/// <returns>The populated users. May include null results for failed retrievals.</returns>
public Task<APIUser?[]> GetUsersAsync(int[] userIds, CancellationToken token = default) => LookupAsync(userIds, token);
2020-11-17 01:57:11 +00:00
protected override LookupUsersRequest CreateRequest(IEnumerable<int> ids) => new LookupUsersRequest(ids.ToArray());
protected override IEnumerable<APIUser>? RetrieveResults(LookupUsersRequest request) => request.Response?.Users;
2020-11-06 07:38:57 +00:00
}
}