Merge pull request #18612 from frenzibyte/message-notifier-unresolved-channel

Fix message notifier not handling unresolved PM channels
This commit is contained in:
Dean Herbert 2022-06-08 13:05:56 +09:00 committed by GitHub
commit 347b90c096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 1 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
@ -178,6 +179,36 @@ namespace osu.Game.Tests.Visual.Online
AddAssert("1 notification fired", () => testContainer.NotificationOverlay.UnreadCount.Value == 1);
}
/// <summary>
/// Ensures that <see cref="MessageNotifier"/> handles channels which have not been or could not be resolved (i.e. <see cref="Channel.Id"/> = 0).
/// </summary>
[Test]
public void TestSendInUnresolvedChannel()
{
int i = 1;
Channel unresolved = null;
AddRepeatStep("join unresolved channels", () => testContainer.ChannelManager.JoinChannel(unresolved = new Channel(new APIUser
{
Id = 100 + i,
Username = $"Foreign #{i++}",
})), 5);
AddStep("send message in unresolved channel", () =>
{
Debug.Assert(unresolved.Id == 0);
unresolved.AddLocalEcho(new LocalEchoMessage
{
Sender = API.LocalUser.Value,
ChannelId = unresolved.Id,
Content = "Some message",
});
});
AddAssert("no notifications fired", () => testContainer.NotificationOverlay.UnreadCount.Value == 0);
}
private void receiveMessage(APIUser sender, Channel channel, string content) => channel.AddNewMessages(createMessage(sender, channel, content));
private Message createMessage(APIUser sender, Channel channel, string content) => new Message(messageIdCounter++)

View File

@ -77,7 +77,7 @@ namespace osu.Game.Online.Chat
if (!messages.Any())
return;
var channel = channelManager.JoinedChannels.SingleOrDefault(c => c.Id == messages.First().ChannelId);
var channel = channelManager.JoinedChannels.SingleOrDefault(c => c.Id > 0 && c.Id == messages.First().ChannelId);
if (channel == null)
return;