1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-23 06:13:13 +08:00

Merge pull request #10 from angelaz1/jcramos/ctrl_shift_t

Fixes based on reviewer pull request feedback
This commit is contained in:
Joseph-Ramos-CMU 2020-12-18 12:22:59 -05:00 committed by GitHub
commit 50db5daa24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 30 deletions

View File

@ -219,16 +219,16 @@ namespace osu.Game.Tests.Visual.Online
// Want to close channel 2 // Want to close channel 2
AddStep("Select channel 2", () => clickDrawable(chatOverlay.TabMap[channel2])); AddStep("Select channel 2", () => clickDrawable(chatOverlay.TabMap[channel2]));
AddStep("Press Ctrl + W", pressControlW);
pressControlW();
// Channel 2 should be closed // Channel 2 should be closed
AddAssert("channel 1 open", () => channelManager.JoinedChannels.Contains(channel1)); AddAssert("Channel 1 open", () => channelManager.JoinedChannels.Contains(channel1));
AddAssert("channel 2 closed", () => !channelManager.JoinedChannels.Contains(channel2)); AddAssert("Channel 2 closed", () => !channelManager.JoinedChannels.Contains(channel2));
// Want to close channel 1 // Want to close channel 1
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1])); AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
pressControlW(); AddStep("Press Ctrl + W", pressControlW);
// Channel 1 and channel 2 should be closed // Channel 1 and channel 2 should be closed
AddAssert("All channels closed", () => !channelManager.JoinedChannels.Any()); AddAssert("All channels closed", () => !channelManager.JoinedChannels.Any());
} }
@ -243,7 +243,8 @@ namespace osu.Game.Tests.Visual.Online
}); });
// Want to join another channel // Want to join another channel
pressControlT(); AddStep("Press Ctrl + T", pressControlT);
// Selector should be visible // Selector should be visible
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible); AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
} }
@ -258,16 +259,16 @@ namespace osu.Game.Tests.Visual.Online
private void pressControlW() private void pressControlW()
{ {
AddStep("Press and hold Control", () => InputManager.PressKey(Key.ControlLeft)); InputManager.PressKey(Key.ControlLeft);
AddStep("Press W", () => InputManager.Key(Key.W)); InputManager.Key(Key.W);
AddStep("Release Control", () => InputManager.ReleaseKey(Key.ControlLeft)); InputManager.ReleaseKey(Key.ControlLeft);
} }
private void pressControlT() private void pressControlT()
{ {
AddStep("Press and hold Control", () => InputManager.PressKey(Key.ControlLeft)); InputManager.PressKey(Key.ControlLeft);
AddStep("Press T", () => InputManager.Key(Key.T)); InputManager.Key(Key.T);
AddStep("Release Control", () => InputManager.ReleaseKey(Key.ControlLeft)); InputManager.ReleaseKey(Key.ControlLeft);
} }
private void clickDrawable(Drawable d) private void clickDrawable(Drawable d)

View File

@ -33,8 +33,11 @@ namespace osu.Game.Online.Chat
private readonly BindableList<Channel> availableChannels = new BindableList<Channel>(); private readonly BindableList<Channel> availableChannels = new BindableList<Channel>();
private readonly BindableList<Channel> joinedChannels = new BindableList<Channel>(); private readonly BindableList<Channel> joinedChannels = new BindableList<Channel>();
// Keeps a list of closed channels. More recently closed channels appear at higher indeces /// <summary>
private readonly BindableList<Channel> closedChannels = new BindableList<Channel>(); /// Keeps a list of closed channel identifiers. Stores the channel ID for normal
/// channels, or the user ID for PM channels
/// </summary>
private readonly BindableList<long> closedChannelIds = new BindableList<long>();
// For efficiency purposes, this constant bounds the number of closed channels we store. // For efficiency purposes, this constant bounds the number of closed channels we store.
// This number is somewhat arbitrary; future developers are free to modify it. // This number is somewhat arbitrary; future developers are free to modify it.
@ -418,13 +421,13 @@ namespace osu.Game.Online.Chat
// Prevent the closedChannel list from exceeding the max size // Prevent the closedChannel list from exceeding the max size
// by removing the oldest element // by removing the oldest element
if (closedChannels.Count >= closed_channels_max_size) if (closedChannelIds.Count >= closed_channels_max_size)
{ {
closedChannels.RemoveAt(0); closedChannelIds.RemoveAt(0);
} }
// insert at the end of the closedChannels list // For PM channels, we store the user ID; else, we store the channel id
closedChannels.Insert(closedChannels.Count, channel); closedChannelIds.Add(channel.Type == ChannelType.PM ? channel.Users.First().Id : channel.Id);
if (channel.Joined.Value) if (channel.Joined.Value)
{ {
@ -440,24 +443,45 @@ namespace osu.Game.Online.Chat
/// </summary> /// </summary>
public void JoinLastClosedChannel() public void JoinLastClosedChannel()
{ {
if (closedChannels.Count <= 0) if (closedChannelIds.Count <= 0)
{ {
return; return;
} }
Channel lastClosedChannel = closedChannels.Last(); // This nested loop could be eliminated if a check was added so that
// when the code opens a channel it removes from the closedChannel list.
closedChannels.Remove(lastClosedChannel); // However, this would require adding an O(|closeChannels|) work operation
// every time the user joins a channel, which would make joining a channel
// If the user already joined the channel, try the next // slower. I wanted to centralize all major slowdowns so they
// channel in the list // can only occur if the user actually decides to use this feature.
if (joinedChannels.IndexOf(lastClosedChannel) >= 0) while (closedChannelIds.Count != 0)
{ {
JoinLastClosedChannel(); long lastClosedChannelId = closedChannelIds.Last();
} closedChannelIds.RemoveAt(closedChannelIds.Count - 1);
else
{ bool lookupCondition(Channel ch) => ch.Type == ChannelType.PM
JoinChannel(lastClosedChannel); ? ch.Users.Any(u => u.Id == lastClosedChannelId)
: ch.Id == lastClosedChannelId;
// If the user hasn't already joined the channel, try to join it
if (joinedChannels.FirstOrDefault(lookupCondition) == null)
{
Channel lastClosedChannel = AvailableChannels.FirstOrDefault(lookupCondition);
if (lastClosedChannel != null)
{
CurrentChannel.Value = JoinChannel(lastClosedChannel);
}
else
{
// Try to get User to open PM chat
var req = new GetUserRequest(lastClosedChannelId);
req.Success += user => CurrentChannel.Value = JoinChannel(new Channel(user));
api.Queue(req);
}
return;
}
} }
} }