mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 14:02:55 +08:00
Merge pull request #10 from angelaz1/jcramos/ctrl_shift_t
Fixes based on reviewer pull request feedback
This commit is contained in:
commit
50db5daa24
@ -219,16 +219,16 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
// Want to close channel 2
|
||||
AddStep("Select channel 2", () => clickDrawable(chatOverlay.TabMap[channel2]));
|
||||
AddStep("Press Ctrl + W", pressControlW);
|
||||
|
||||
pressControlW();
|
||||
// Channel 2 should be closed
|
||||
AddAssert("channel 1 open", () => channelManager.JoinedChannels.Contains(channel1));
|
||||
AddAssert("channel 2 closed", () => !channelManager.JoinedChannels.Contains(channel2));
|
||||
AddAssert("Channel 1 open", () => channelManager.JoinedChannels.Contains(channel1));
|
||||
AddAssert("Channel 2 closed", () => !channelManager.JoinedChannels.Contains(channel2));
|
||||
|
||||
// Want to close channel 1
|
||||
AddStep("Select channel 1", () => clickDrawable(chatOverlay.TabMap[channel1]));
|
||||
|
||||
pressControlW();
|
||||
AddStep("Press Ctrl + W", pressControlW);
|
||||
// Channel 1 and channel 2 should be closed
|
||||
AddAssert("All channels closed", () => !channelManager.JoinedChannels.Any());
|
||||
}
|
||||
@ -243,7 +243,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
});
|
||||
|
||||
// Want to join another channel
|
||||
pressControlT();
|
||||
AddStep("Press Ctrl + T", pressControlT);
|
||||
|
||||
// Selector should be visible
|
||||
AddAssert("Selector is visible", () => chatOverlay.SelectionOverlayState == Visibility.Visible);
|
||||
}
|
||||
@ -258,16 +259,16 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
private void pressControlW()
|
||||
{
|
||||
AddStep("Press and hold Control", () => InputManager.PressKey(Key.ControlLeft));
|
||||
AddStep("Press W", () => InputManager.Key(Key.W));
|
||||
AddStep("Release Control", () => InputManager.ReleaseKey(Key.ControlLeft));
|
||||
InputManager.PressKey(Key.ControlLeft);
|
||||
InputManager.Key(Key.W);
|
||||
InputManager.ReleaseKey(Key.ControlLeft);
|
||||
}
|
||||
|
||||
private void pressControlT()
|
||||
{
|
||||
AddStep("Press and hold Control", () => InputManager.PressKey(Key.ControlLeft));
|
||||
AddStep("Press T", () => InputManager.Key(Key.T));
|
||||
AddStep("Release Control", () => InputManager.ReleaseKey(Key.ControlLeft));
|
||||
InputManager.PressKey(Key.ControlLeft);
|
||||
InputManager.Key(Key.T);
|
||||
InputManager.ReleaseKey(Key.ControlLeft);
|
||||
}
|
||||
|
||||
private void clickDrawable(Drawable d)
|
||||
|
@ -33,8 +33,11 @@ namespace osu.Game.Online.Chat
|
||||
private readonly BindableList<Channel> availableChannels = 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
|
||||
private readonly BindableList<Channel> closedChannels = new BindableList<Channel>();
|
||||
/// <summary>
|
||||
/// 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.
|
||||
// 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
|
||||
// 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
|
||||
closedChannels.Insert(closedChannels.Count, channel);
|
||||
// For PM channels, we store the user ID; else, we store the channel id
|
||||
closedChannelIds.Add(channel.Type == ChannelType.PM ? channel.Users.First().Id : channel.Id);
|
||||
|
||||
if (channel.Joined.Value)
|
||||
{
|
||||
@ -440,24 +443,45 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public void JoinLastClosedChannel()
|
||||
{
|
||||
if (closedChannels.Count <= 0)
|
||||
if (closedChannelIds.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Channel lastClosedChannel = closedChannels.Last();
|
||||
|
||||
closedChannels.Remove(lastClosedChannel);
|
||||
|
||||
// If the user already joined the channel, try the next
|
||||
// channel in the list
|
||||
if (joinedChannels.IndexOf(lastClosedChannel) >= 0)
|
||||
// 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.
|
||||
// However, this would require adding an O(|closeChannels|) work operation
|
||||
// every time the user joins a channel, which would make joining a channel
|
||||
// slower. I wanted to centralize all major slowdowns so they
|
||||
// can only occur if the user actually decides to use this feature.
|
||||
while (closedChannelIds.Count != 0)
|
||||
{
|
||||
JoinLastClosedChannel();
|
||||
}
|
||||
else
|
||||
{
|
||||
JoinChannel(lastClosedChannel);
|
||||
long lastClosedChannelId = closedChannelIds.Last();
|
||||
closedChannelIds.RemoveAt(closedChannelIds.Count - 1);
|
||||
|
||||
bool lookupCondition(Channel ch) => ch.Type == ChannelType.PM
|
||||
? 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user