Hide !mp commands from tournament streaming chat

This commit is contained in:
Dean Herbert 2024-12-16 17:36:40 +09:00
parent d72a0b04b8
commit 09fc30e377
No known key found for this signature in database
4 changed files with 35 additions and 16 deletions

View File

@ -152,6 +152,12 @@ namespace osu.Game.Tournament.Tests.Components
AddStep("change channel to 2", () => chatDisplay.Channel.Value = testChannel2);
AddStep("change channel to 1", () => chatDisplay.Channel.Value = testChannel);
AddStep("!mp message (shouldn't display)", () => testChannel.AddNewMessages(new Message(nextMessageId())
{
Sender = redUser.ToAPIUser(),
Content = "!mp wangs"
}));
}
private int messageId;

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -72,7 +73,13 @@ namespace osu.Game.Tournament.Components
public void Contract() => this.FadeOut(200);
protected override ChatLine CreateMessage(Message message) => new MatchMessage(message, ladderInfo);
protected override ChatLine? CreateMessage(Message message)
{
if (message.Content.StartsWith("!mp", StringComparison.Ordinal))
return null;
return new MatchMessage(message, ladderInfo);
}
protected override StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => new MatchChannel(channel);

View File

@ -1,9 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -21,18 +20,18 @@ using osuTK.Input;
namespace osu.Game.Online.Chat
{
/// <summary>
/// Display a chat channel in an insolated region.
/// Display a chat channel in an isolated region.
/// </summary>
public partial class StandAloneChatDisplay : CompositeDrawable
{
[Cached]
public readonly Bindable<Channel> Channel = new Bindable<Channel>();
public readonly Bindable<Channel?> Channel = new Bindable<Channel?>();
protected readonly ChatTextBox TextBox;
protected readonly ChatTextBox? TextBox;
private ChannelManager channelManager;
private ChannelManager? channelManager;
private StandAloneDrawableChannel drawableChannel;
private StandAloneDrawableChannel? drawableChannel;
private readonly bool postingTextBox;
@ -93,6 +92,8 @@ namespace osu.Game.Online.Chat
private void postMessage(TextBox sender, bool newText)
{
Debug.Assert(TextBox != null);
string text = TextBox.Text.Trim();
if (string.IsNullOrWhiteSpace(text))
@ -106,9 +107,9 @@ namespace osu.Game.Online.Chat
TextBox.Text = string.Empty;
}
protected virtual ChatLine CreateMessage(Message message) => new StandAloneMessage(message);
protected virtual ChatLine? CreateMessage(Message message) => new StandAloneMessage(message);
private void channelChanged(ValueChangedEvent<Channel> e)
private void channelChanged(ValueChangedEvent<Channel?> e)
{
drawableChannel?.Expire();
@ -128,8 +129,8 @@ namespace osu.Game.Online.Chat
public partial class ChatTextBox : HistoryTextBox
{
public Action Focus;
public Action FocusLost;
public Action? Focus;
public Action? FocusLost;
protected override bool OnKeyDown(KeyDownEvent e)
{
@ -171,14 +172,14 @@ namespace osu.Game.Online.Chat
public partial class StandAloneDrawableChannel : DrawableChannel
{
public Func<Message, ChatLine> CreateChatLineAction;
public Func<Message, ChatLine?>? CreateChatLineAction;
public StandAloneDrawableChannel(Channel channel)
: base(channel)
{
}
protected override ChatLine CreateChatLine(Message m) => CreateChatLineAction(m);
protected override ChatLine? CreateChatLine(Message m) => CreateChatLineAction?.Invoke(m) ?? null;
protected override DaySeparator CreateDaySeparator(DateTimeOffset time) => new StandAloneDaySeparator(time);
}

View File

@ -155,9 +155,14 @@ namespace osu.Game.Overlays.Chat
{
addDaySeparatorIfRequired(lastMessage, message);
ChatLineFlow.Add(CreateChatLine(message));
var chatLine = CreateChatLine(message);
if (chatLine != null)
{
ChatLineFlow.Add(chatLine);
lastMessage = message;
}
}
var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();