1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 17:32:54 +08:00

Merge pull request #15487 from peppy/user-lookup-by-username-cleanup

Support open profile overlay from username in more places
This commit is contained in:
Dan Balasescu 2021-11-08 14:21:07 +09:00 committed by GitHub
commit f776ff3d8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 35 deletions

View File

@ -71,13 +71,13 @@ namespace osu.Game.Tests.Visual.Online
{
base.LoadComplete();
AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER, false));
AddStep("Show offline dummy", () => profile.ShowUser(TEST_USER));
AddStep("Show null dummy", () => profile.ShowUser(new APIUser
{
Username = @"Null",
Id = 1,
}, false));
}));
AddStep("Show ppy", () => profile.ShowUser(new APIUser
{
@ -86,7 +86,7 @@ namespace osu.Game.Tests.Visual.Online
IsSupporter = true,
Country = new Country { FullName = @"Australia", FlagName = @"AU" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg"
}, api.IsLoggedIn));
}));
AddStep("Show flyte", () => profile.ShowUser(new APIUser
{
@ -94,7 +94,7 @@ namespace osu.Game.Tests.Visual.Online
Id = 3103765,
Country = new Country { FullName = @"Japan", FlagName = @"JP" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg"
}, api.IsLoggedIn));
}));
AddStep("Show bancho", () => profile.ShowUser(new APIUser
{
@ -103,10 +103,10 @@ namespace osu.Game.Tests.Visual.Online
IsBot = true,
Country = new Country { FullName = @"Saint Helena", FlagName = @"SH" },
CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c4.jpg"
}, api.IsLoggedIn));
}));
AddStep("Show ppy from username", () => profile.ShowUser(@"peppy"));
AddStep("Show flyte from username", () => profile.ShowUser(@"flyte"));
AddStep("Show ppy from username", () => profile.ShowUser(new APIUser { Username = @"peppy" }));
AddStep("Show flyte from username", () => profile.ShowUser(new APIUser { Username = @"flyte" }));
AddStep("Hide", profile.Hide);
AddStep("Show without reload", profile.Show);

View File

@ -53,8 +53,10 @@ using osu.Game.Database;
using osu.Game.Extensions;
using osu.Game.IO;
using osu.Game.Localisation;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Performance;
using osu.Game.Skinning.Editor;
using osu.Game.Users;
namespace osu.Game
{
@ -323,10 +325,9 @@ namespace osu.Game
break;
case LinkAction.OpenUserProfile:
if (int.TryParse(link.Argument, out int userId))
ShowUser(userId);
else
ShowUser(link.Argument);
ShowUser(int.TryParse(link.Argument, out int userId)
? new APIUser { Id = userId }
: new APIUser { Username = link.Argument });
break;
@ -383,14 +384,8 @@ namespace osu.Game
/// <summary>
/// Show a user's profile as an overlay.
/// </summary>
/// <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));
/// <param name="user">The user to display.</param>
public void ShowUser(IUser user) => waitForReady(() => userProfile, _ => userProfile.ShowUser(user));
/// <summary>
/// Show a beatmap's set as an overlay, displaying the given beatmap.

View File

@ -14,6 +14,7 @@ using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.Profile;
using osu.Game.Overlays.Profile.Sections;
using osu.Game.Users;
using osuTK;
using osuTK.Graphics;
@ -38,18 +39,14 @@ namespace osu.Game.Overlays
protected override Color4 BackgroundColour => ColourProvider.Background6;
public void ShowUser(int userId) => ShowUser(new APIUser { Id = userId });
public void ShowUser(string username) => ShowUser(new APIUser { Username = username });
public void ShowUser(APIUser user, bool fetchOnline = true)
public void ShowUser(IUser user)
{
if (user == APIUser.SYSTEM_USER)
return;
Show();
if (user.Id == Header?.User.Value?.Id)
if (user.OnlineID == Header?.User.Value?.Id)
return;
if (sectionsContainer != null)
@ -116,19 +113,20 @@ namespace osu.Game.Overlays
}
};
if (fetchOnline)
{
userReq = user.Id > 1 ? new GetUserRequest(user.Id) : new GetUserRequest(user.Username);
userReq.Success += userLoadComplete;
API.Queue(userReq);
}
else
sectionsContainer.ScrollToTop();
// Check arbitrarily whether this user has already been populated.
// This is only generally used by tests, but should be quite safe unless we want to force a refresh on loading a previous user in the future.
if (user is APIUser apiUser && apiUser.JoinDate != default)
{
userReq = null;
userLoadComplete(user);
userLoadComplete(apiUser);
return;
}
sectionsContainer.ScrollToTop();
userReq = user.OnlineID > 1 ? new GetUserRequest(user.OnlineID) : new GetUserRequest(user.Username);
userReq.Success += userLoadComplete;
API.Queue(userReq);
}
private void userLoadComplete(APIUser user)

View File

@ -66,7 +66,7 @@ namespace osu.Game.Users.Drawables
private void openProfile()
{
if (user?.Id > 1)
game?.ShowUser(user.Id);
game?.ShowUser(user);
}
private class ClickableArea : OsuClickableContainer