Merge pull request #12526 from peppy/fix-system-message-ordering

Fix system messages always being displayed above standard messages
This commit is contained in:
Dan Balasescu 2021-04-22 18:51:25 +09:00 committed by GitHub
commit b774f5b72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 4 deletions

View File

@ -83,6 +83,28 @@ namespace osu.Game.Tests.Visual.Online
};
});
[Test]
public void TestSystemMessageOrdering()
{
var standardMessage = new Message(messageIdSequence++)
{
Sender = admin,
Content = "I am a wang!"
};
var infoMessage1 = new InfoMessage($"the system is calling {messageIdSequence++}");
var infoMessage2 = new InfoMessage($"the system is calling {messageIdSequence++}");
AddStep("message from admin", () => testChannel.AddNewMessages(standardMessage));
AddStep("message from system", () => testChannel.AddNewMessages(infoMessage1));
AddStep("message from system", () => testChannel.AddNewMessages(infoMessage2));
AddAssert("message order is correct", () => testChannel.Messages.Count == 3
&& testChannel.Messages[0] == standardMessage
&& testChannel.Messages[1] == infoMessage1
&& testChannel.Messages[2] == infoMessage2);
}
[Test]
public void TestManyMessages()
{

View File

@ -8,10 +8,8 @@ namespace osu.Game.Online.Chat
{
public class InfoMessage : LocalMessage
{
private static int infoID = -1;
public InfoMessage(string message)
: base(infoID--)
: base(null)
{
Timestamp = DateTimeOffset.Now;
Content = message;

View File

@ -59,7 +59,7 @@ namespace osu.Game.Online.Chat
return Id.Value.CompareTo(other.Id.Value);
}
public virtual bool Equals(Message other) => Id == other?.Id;
public virtual bool Equals(Message other) => Id.HasValue && Id == other?.Id;
// ReSharper disable once ImpureMethodCallOnReadonlyValueField
public override int GetHashCode() => Id.GetHashCode();