Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Highlight mentions in chat #29314

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions osu.Game.Tests/Visual/Online/TestSceneDrawableChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ public void SetUpSteps()
});
}

[Test]
public void TestMention()
{
AddStep("add normal message", () => channel.AddNewMessages(
new Message(1)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = "Hello how are you today?",
Timestamp = new DateTimeOffset(2021, 12, 11, 13, 33, 24, TimeSpan.Zero)
}));

AddStep("add mention", () => channel.AddNewMessages(
new Message(2)
{
Sender = new APIUser
{
Id = 2,
Username = "TestUser2"
},
Content = $"Hello {API.LocalUser.Value.Username} how are you today?",
Timestamp = new DateTimeOffset(2021, 12, 11, 13, 33, 25, TimeSpan.Zero)
}));
}

[Test]
public void TestDaySeparators()
{
Expand Down
20 changes: 17 additions & 3 deletions osu.Game/Overlays/Chat/ChatLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat;
using osuTK;
Expand Down Expand Up @@ -104,6 +105,8 @@ public bool AlternatingBackground
}
}

private bool isMention;

/// <summary>
/// The colour used to paint the author's username.
/// </summary>
Expand Down Expand Up @@ -255,12 +258,21 @@ public void Highlight()
private void styleMessageContent(SpriteText text)
{
text.Shadow = false;
text.Font = text.Font.With(size: FontSize, italics: Message.IsAction);
text.Font = text.Font.With(size: FontSize, italics: Message.IsAction, weight: isMention ? FontWeight.SemiBold : FontWeight.Medium);

Color4 messageColour = colourProvider?.Content1 ?? Colour4.White;

if (isMention)
messageColour = colourProvider?.Highlight1 ?? Color4.Orange;
else if (Message.IsAction && !string.IsNullOrEmpty(message.Sender.Colour))
messageColour = Color4Extensions.FromHex(message.Sender.Colour);

bool messageHasColour = Message.IsAction && !string.IsNullOrEmpty(message.Sender.Colour);
text.Colour = messageHasColour ? Color4Extensions.FromHex(message.Sender.Colour) : colourProvider?.Content1 ?? Colour4.White;
text.Colour = messageColour;
}

[Resolved]
private IAPIProvider api { get; set; } = null!;

private void updateMessageContent()
{
this.FadeTo(message is LocalEchoMessage ? 0.4f : 1.0f, 500, Easing.OutQuint);
Expand All @@ -280,6 +292,8 @@ private void updateMessageContent()
// remove non-existent channels from the link list
message.Links.RemoveAll(link => link.Action == LinkAction.OpenChannel && chatManager?.AvailableChannels.Any(c => c.Name == link.Argument.ToString()) != true);

isMention = MessageNotifier.CheckContainsUsername(message.DisplayContent, api.LocalUser.Value.Username);

drawableContentFlow.Clear();
drawableContentFlow.AddLinks(message.DisplayContent, message.Links);
}
Expand Down
Loading