1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 04:02:59 +08:00

add methods to get a user from their username

This commit is contained in:
Davran Dilshat 2021-08-29 19:19:55 +01:00
parent 7122f48568
commit 90c313e2ad
3 changed files with 23 additions and 6 deletions

View File

@ -8,15 +8,25 @@ namespace osu.Game.Online.API.Requests
{
public class GetUserRequest : APIRequest<User>
{
private readonly long? userId;
private readonly string userIdentifier;
public readonly RulesetInfo Ruleset;
public GetUserRequest()
{
}
public GetUserRequest(long? userId = null, RulesetInfo ruleset = null)
{
this.userId = userId;
this.userIdentifier = userId.ToString();
Ruleset = ruleset;
}
protected override string Target => userId.HasValue ? $@"users/{userId}/{Ruleset?.ShortName}" : $@"me/{Ruleset?.ShortName}";
public GetUserRequest(string username = null, RulesetInfo ruleset = null)
{
this.userIdentifier = username;
Ruleset = ruleset;
}
protected override string Target => (userIdentifier != null) ? $@"users/{userIdentifier}/{Ruleset?.ShortName}" : $@"me/{Ruleset?.ShortName}";
}
}

View File

@ -329,8 +329,7 @@ namespace osu.Game
break;
case LinkAction.OpenUserProfile:
if (int.TryParse(link.Argument, out int userId))
ShowUser(userId);
ShowUser(link.Argument);
break;
case LinkAction.OpenWiki:
@ -378,6 +377,12 @@ namespace osu.Game
/// <param name="userId">The user to display.</param>
public void ShowUser(int userId) => waitForReady(() => userProfile, _ => userProfile.ShowUser(userId));
/// <summary>
/// Show a user's profile as an overlay.
/// </summary>
/// <param name="username">The user to display.</param>
public void ShowUser(string username) => waitForReady(() => userProfile, _ => userProfile.ShowUser(username));
/// <summary>
/// Show a beatmap's set as an overlay, displaying the given beatmap.
/// </summary>

View File

@ -40,6 +40,8 @@ namespace osu.Game.Overlays
public void ShowUser(int userId) => ShowUser(new User { Id = userId });
public void ShowUser(string username) => ShowUser(new User { Username = username });
public void ShowUser(User user, bool fetchOnline = true)
{
if (user == User.SYSTEM_USER)
@ -116,7 +118,7 @@ namespace osu.Game.Overlays
if (fetchOnline)
{
userReq = new GetUserRequest(user.Id);
userReq = user.Username != null ? new GetUserRequest(user.Username) : new GetUserRequest(user.Id);
userReq.Success += userLoadComplete;
API.Queue(userReq);
}