1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:07:52 +08:00

Change OpenUserProfile argument type to always use IUser

This commit is contained in:
Salman Ahmed 2023-06-24 18:11:34 +03:00
parent ff17685bc3
commit 9a5f033a0f
4 changed files with 14 additions and 17 deletions

View File

@ -74,13 +74,7 @@ namespace osu.Game.Graphics.Containers
}
public void AddUserLink(IUser user, Action<SpriteText> creationParameters = null)
{
string argument = user.OnlineID > 1
? user.OnlineID.ToString()
: user.Username;
createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, argument), "view profile");
}
=> createLink(CreateChunkFor(user.Username, true, CreateSpriteText, creationParameters), new LinkDetails(LinkAction.OpenUserProfile, user), "view profile");
private void createLink(ITextPart textPart, LinkDetails link, LocalisableString tooltipText, Action action = null)
{

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using osu.Game.Online.API.Requests.Responses;
namespace osu.Game.Online.Chat
{
@ -172,7 +173,7 @@ namespace osu.Game.Online.Chat
case "u":
case "users":
return new LinkDetails(LinkAction.OpenUserProfile, mainArg);
return getUserLink(mainArg);
case "wiki":
return new LinkDetails(LinkAction.OpenWiki, string.Join('/', args.Skip(3)));
@ -230,8 +231,7 @@ namespace osu.Game.Online.Chat
break;
case "u":
linkType = LinkAction.OpenUserProfile;
break;
return getUserLink(args[2]);
default:
return new LinkDetails(LinkAction.External, url);
@ -246,6 +246,14 @@ namespace osu.Game.Online.Chat
return new LinkDetails(LinkAction.External, url);
}
private static LinkDetails getUserLink(string argument)
{
if (int.TryParse(argument, out int userId))
return new LinkDetails(LinkAction.OpenUserProfile, new APIUser { Id = userId });
return new LinkDetails(LinkAction.OpenUserProfile, new APIUser { Username = argument });
}
private static MessageFormatterResult format(string toFormat, int startIndex = 0, int space = 3)
{
var result = new MessageFormatterResult(toFormat);

View File

@ -45,7 +45,6 @@ using osu.Game.Input.Bindings;
using osu.Game.IO;
using osu.Game.Localisation;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
@ -446,11 +445,7 @@ namespace osu.Game
break;
case LinkAction.OpenUserProfile:
var user = int.TryParse(argString, out int userId)
? new APIUser { Id = userId }
: new APIUser { Username = argString };
ShowUser(user);
ShowUser((IUser)link.Argument);
break;
case LinkAction.OpenWiki:

View File

@ -223,7 +223,7 @@ namespace osu.Game.Overlays.Profile.Sections.Recent
private void addBeatmapsetLink()
=> content.AddLink(activity.Beatmapset.AsNonNull().Title, LinkAction.OpenBeatmapSet, getLinkArgument(activity.Beatmapset.AsNonNull().Url), creationParameters: t => t.Font = getLinkFont());
private string getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.WebsiteRootUrl}{url}").Argument.ToString().AsNonNull();
private object getLinkArgument(string url) => MessageFormatter.GetLinkDetails($"{api.WebsiteRootUrl}{url}").Argument.AsNonNull();
private FontUsage getLinkFont(FontWeight fontWeight = FontWeight.Regular)
=> OsuFont.GetFont(size: font_size, weight: fontWeight, italics: true);