mirror of
https://github.com/ppy/osu
synced 2024-12-25 00:02:48 +00:00
Add test for scroll to end when max history is exceeded
This commit is contained in:
parent
34aa0b14a4
commit
d1c6e3f620
@ -7,6 +7,9 @@ using osu.Game.Online.Chat;
|
||||
using osu.Game.Users;
|
||||
using osuTK;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Overlays.Chat;
|
||||
|
||||
namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
@ -42,14 +45,14 @@ namespace osu.Game.Tests.Visual.Online
|
||||
[Cached]
|
||||
private ChannelManager channelManager = new ChannelManager();
|
||||
|
||||
private readonly StandAloneChatDisplay chatDisplay;
|
||||
private readonly StandAloneChatDisplay chatDisplay2;
|
||||
private readonly TestStandAloneChatDisplay chatDisplay;
|
||||
private readonly TestStandAloneChatDisplay chatDisplay2;
|
||||
|
||||
public TestSceneStandAloneChatDisplay()
|
||||
{
|
||||
Add(channelManager);
|
||||
|
||||
Add(chatDisplay = new StandAloneChatDisplay
|
||||
Add(chatDisplay = new TestStandAloneChatDisplay
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
@ -57,7 +60,7 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Size = new Vector2(400, 80)
|
||||
});
|
||||
|
||||
Add(chatDisplay2 = new StandAloneChatDisplay(true)
|
||||
Add(chatDisplay2 = new TestStandAloneChatDisplay(true)
|
||||
{
|
||||
Anchor = Anchor.CentreRight,
|
||||
Origin = Anchor.CentreRight,
|
||||
@ -119,6 +122,32 @@ namespace osu.Game.Tests.Visual.Online
|
||||
Content = "Message from the future!",
|
||||
Timestamp = DateTimeOffset.Now
|
||||
}));
|
||||
|
||||
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
||||
|
||||
const int messages_per_call = 10;
|
||||
AddRepeatStep("add many messages", () =>
|
||||
{
|
||||
for (int i = 0; i < messages_per_call; i++)
|
||||
testChannel.AddNewMessages(new Message(sequence++)
|
||||
{
|
||||
Sender = longUsernameUser,
|
||||
Content = "Many messages! " + Guid.NewGuid(),
|
||||
Timestamp = DateTimeOffset.Now
|
||||
});
|
||||
}, Channel.MAX_HISTORY / messages_per_call + 5);
|
||||
|
||||
AddUntilStep("ensure still scrolled to bottom", () => chatDisplay.ScrolledToBottom);
|
||||
}
|
||||
|
||||
private class TestStandAloneChatDisplay : StandAloneChatDisplay
|
||||
{
|
||||
public TestStandAloneChatDisplay(bool textbox = false)
|
||||
: base(textbox)
|
||||
{
|
||||
}
|
||||
|
||||
public bool ScrolledToBottom => ((ScrollContainer<Drawable>)((Container)InternalChildren.OfType<DrawableChannel>().First().Child).Child).IsScrolledToEnd(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
public class Channel
|
||||
{
|
||||
public readonly int MaxHistory = 300;
|
||||
public const int MAX_HISTORY = 300;
|
||||
|
||||
/// <summary>
|
||||
/// Contains every joined user except the current logged in user. Currently only returned for PM channels.
|
||||
@ -80,8 +80,6 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public Bindable<bool> Joined = new Bindable<bool>();
|
||||
|
||||
public const int MAX_HISTORY = 300;
|
||||
|
||||
[JsonConstructor]
|
||||
public Channel()
|
||||
{
|
||||
@ -162,8 +160,8 @@ namespace osu.Game.Online.Chat
|
||||
{
|
||||
// never purge local echos
|
||||
int messageCount = Messages.Count - pendingMessages.Count;
|
||||
if (messageCount > MaxHistory)
|
||||
Messages.RemoveRange(0, messageCount - MaxHistory);
|
||||
if (messageCount > MAX_HISTORY)
|
||||
Messages.RemoveRange(0, messageCount - MAX_HISTORY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// 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;
|
||||
@ -107,7 +107,7 @@ namespace osu.Game.Overlays.Chat
|
||||
scrollToEnd();
|
||||
|
||||
var staleMessages = chatLines.Where(c => c.LifetimeEnd == double.MaxValue).ToArray();
|
||||
int count = staleMessages.Length - Channel.MaxHistory;
|
||||
int count = staleMessages.Length - Channel.MAX_HISTORY;
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user