1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 21:43:04 +08:00

Improve channel switching flow in HighlightMessage

This commit is contained in:
Salman Ahmed 2022-03-10 22:54:47 +03:00
parent 8086f73451
commit a31611bdec
3 changed files with 25 additions and 25 deletions

View File

@ -435,7 +435,7 @@ namespace osu.Game.Tests.Visual.Online
});
});
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message));
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel1));
}
[Test]
@ -462,7 +462,7 @@ namespace osu.Game.Tests.Visual.Online
});
});
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message));
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel2));
AddAssert("Switched to channel 2", () => channelManager.CurrentChannel.Value == channel2);
}
@ -491,7 +491,7 @@ namespace osu.Game.Tests.Visual.Online
});
AddStep("Leave channel 2", () => channelManager.LeaveChannel(channel2));
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message));
AddStep("Highlight message", () => chatOverlay.HighlightMessage(message, channel2));
AddAssert("Switched to channel 2", () => channelManager.CurrentChannel.Value == channel2);
}
@ -522,7 +522,7 @@ namespace osu.Game.Tests.Visual.Online
AddStep("Highlight message and show chat", () =>
{
chatOverlay.HighlightMessage(message);
chatOverlay.HighlightMessage(message, channel1);
chatOverlay.Show();
});
}

View File

@ -99,7 +99,7 @@ namespace osu.Game.Online.Chat
if (checkForPMs(channel, message))
continue;
checkForMentions(message);
checkForMentions(channel, message);
}
}
@ -114,15 +114,15 @@ namespace osu.Game.Online.Chat
if (!notifyOnPrivateMessage.Value || channel.Type != ChannelType.PM)
return false;
notifications.Post(new PrivateMessageNotification(message));
notifications.Post(new PrivateMessageNotification(message, channel));
return true;
}
private void checkForMentions(Message message)
private void checkForMentions(Channel channel, Message message)
{
if (!notifyOnUsername.Value || !CheckContainsUsername(message.Content, localUser.Value.Username)) return;
notifications.Post(new MentionNotification(message));
notifications.Post(new MentionNotification(message, channel));
}
/// <summary>
@ -138,8 +138,8 @@ namespace osu.Game.Online.Chat
public class PrivateMessageNotification : HighlightMessageNotification
{
public PrivateMessageNotification(Message message)
: base(message)
public PrivateMessageNotification(Message message, Channel channel)
: base(message, channel)
{
Icon = FontAwesome.Solid.Envelope;
Text = $"You received a private message from '{message.Sender.Username}'. Click to read it!";
@ -148,8 +148,8 @@ namespace osu.Game.Online.Chat
public class MentionNotification : HighlightMessageNotification
{
public MentionNotification(Message message)
: base(message)
public MentionNotification(Message message, Channel channel)
: base(message, channel)
{
Icon = FontAwesome.Solid.At;
Text = $"Your name was mentioned in chat by '{message.Sender.Username}'. Click to find out why!";
@ -158,12 +158,14 @@ namespace osu.Game.Online.Chat
public abstract class HighlightMessageNotification : SimpleNotification
{
protected HighlightMessageNotification(Message message)
protected HighlightMessageNotification(Message message, Channel channel)
{
this.message = message;
this.channel = channel;
}
private readonly Message message;
private readonly Channel channel;
public override bool IsImportant => false;
@ -175,7 +177,7 @@ namespace osu.Game.Online.Chat
Activated = delegate
{
notificationOverlay.Hide();
chatOverlay.HighlightMessage(message);
chatOverlay.HighlightMessage(message, channel);
chatOverlay.Show();
return true;

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using osuTK;
using osuTK.Graphics;
@ -307,23 +308,20 @@ namespace osu.Game.Overlays
/// Highlights a certain message in the specified channel.
/// </summary>
/// <param name="message">The message to highlight.</param>
public void HighlightMessage(Message message)
/// <param name="channel">The channel containing the message.</param>
public void HighlightMessage(Message message, Channel channel)
{
Channel targetChannel;
Debug.Assert(channel.Id == message.ChannelId);
if (channelManager.CurrentChannel.Value.Id == message.ChannelId)
targetChannel = channelManager.CurrentChannel.Value;
else
if (currentChannel.Value.Id != channel.Id)
{
targetChannel = channelManager.JoinedChannels.SingleOrDefault(c => c.Id == message.ChannelId);
if (!channel.Joined.Value)
channel = channelManager.JoinChannel(channel);
if (targetChannel != null)
channelManager.CurrentChannel.Value = targetChannel;
else
targetChannel = channelManager.JoinChannel(channelManager.AvailableChannels.SingleOrDefault(c => c.Id == message.ChannelId), true);
channelManager.CurrentChannel.Value = channel;
}
targetChannel.HighlightedMessage.Value = message;
channel.HighlightedMessage.Value = message;
}
private float startDragChatHeight;