Skip to content

Commit

Permalink
Merge pull request ppy#7675 from smoogipoo/fix-possible-chat-crash
Browse files Browse the repository at this point in the history
Fix possible crash when searching with no channel topic
  • Loading branch information
peppy authored Jan 30, 2020
2 parents 947ee7a + 2fb640f commit 8193991
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
17 changes: 14 additions & 3 deletions osu.Game.Tests/Visual/Online/TestSceneChatOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@

using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Testing;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Chat;
using osu.Game.Overlays;
using osu.Game.Overlays.Chat;
Expand All @@ -35,8 +38,9 @@ public class TestSceneChatOverlay : ManualInputManagerTestScene
private TestChatOverlay chatOverlay;
private ChannelManager channelManager;

private readonly Channel channel1 = new Channel(new User()) { Name = "test really long username" };
private readonly Channel channel2 = new Channel(new User()) { Name = "test2" };
private readonly Channel channel1 = new Channel(new User()) { Name = "test really long username", Topic = "Topic for channel 1" };
private readonly Channel channel2 = new Channel(new User()) { Name = "test2", Topic = "Topic for channel 2" };
private readonly Channel channel3 = new Channel(new User()) { Name = "channel with no topic" };

[SetUp]
public void Setup()
Expand All @@ -45,7 +49,7 @@ public void Setup()
{
ChannelManagerContainer container;

Child = container = new ChannelManagerContainer(new List<Channel> { channel1, channel2 })
Child = container = new ChannelManagerContainer(new List<Channel> { channel1, channel2, channel3 })
{
RelativeSizeAxes = Axes.Both,
};
Expand Down Expand Up @@ -96,6 +100,13 @@ public void TestCloseChannelWhileSelectorClosed()
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
}

[Test]
public void TestSearchInSelector()
{
AddStep("search for 'test2'", () => chatOverlay.ChildrenOfType<SearchTextBox>().First().Text = "test2");
AddUntilStep("only channel 2 visible", () => chatOverlay.ChildrenOfType<ChannelListItem>().Single(c => c.IsPresent).Channel == channel2);
}

private void clickDrawable(Drawable d)
{
InputManager.MoveMouseTo(d);
Expand Down
12 changes: 6 additions & 6 deletions osu.Game/Overlays/Chat/Selection/ChannelListItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ChannelListItem : OsuClickableContainer, IFilterable
private const float text_size = 15;
private const float transition_duration = 100;

private readonly Channel channel;
public readonly Channel Channel;

private readonly Bindable<bool> joinedBind = new Bindable<bool>();
private readonly OsuSpriteText name;
Expand All @@ -36,7 +36,7 @@ public class ChannelListItem : OsuClickableContainer, IFilterable
private Color4 topicColour;
private Color4 hoverColour;

public IEnumerable<string> FilterTerms => new[] { channel.Name, channel.Topic };
public IEnumerable<string> FilterTerms => new[] { Channel.Name, Channel.Topic ?? string.Empty };

public bool MatchingFilter
{
Expand All @@ -50,7 +50,7 @@ public bool MatchingFilter

public ChannelListItem(Channel channel)
{
this.channel = channel;
Channel = channel;

RelativeSizeAxes = Axes.X;
AutoSizeAxes = Axes.Y;
Expand Down Expand Up @@ -148,23 +148,23 @@ private void load(OsuColour colours)
hoverColour = colours.Yellow;

joinedBind.ValueChanged += joined => updateColour(joined.NewValue);
joinedBind.BindTo(channel.Joined);
joinedBind.BindTo(Channel.Joined);

joinedBind.TriggerChange();
FinishTransforms(true);
}

protected override bool OnHover(HoverEvent e)
{
if (!channel.Joined.Value)
if (!Channel.Joined.Value)
name.FadeColour(hoverColour, 50, Easing.OutQuint);

return base.OnHover(e);
}

protected override void OnHoverLost(HoverLostEvent e)
{
if (!channel.Joined.Value)
if (!Channel.Joined.Value)
name.FadeColour(Color4.White, transition_duration);
}

Expand Down

0 comments on commit 8193991

Please sign in to comment.