mirror of
https://github.com/ppy/osu
synced 2025-02-20 20:47:09 +00:00
Making style changes + supports reopening PM chats
This commit is contained in:
parent
b37a983fbf
commit
71a082110a
@ -33,8 +33,12 @@ 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 channel identifiers
|
||||
private readonly BindableList<string> closedChannels = new BindableList<string>();
|
||||
|
||||
/// <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 +422,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.Name);
|
||||
// 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,7 +444,7 @@ namespace osu.Game.Online.Chat
|
||||
/// </summary>
|
||||
public void JoinLastClosedChannel()
|
||||
{
|
||||
if (closedChannels.Count <= 0)
|
||||
if (closedChannelIds.Count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -451,32 +455,32 @@ namespace osu.Game.Online.Chat
|
||||
// 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.
|
||||
for (int i = closedChannels.Count - 1; i >= 0; i--)
|
||||
while (closedChannelIds.Count != 0)
|
||||
{
|
||||
string lastClosedChannelName = closedChannels.Last();
|
||||
closedChannels.RemoveAt(closedChannels.Count - 1);
|
||||
bool alreadyJoined = false;
|
||||
long lastClosedChannelId = closedChannelIds.Last();
|
||||
closedChannelIds.RemoveAt(closedChannelIds.Count - 1);
|
||||
|
||||
// If the user already joined the channel, do not
|
||||
// try to join it
|
||||
for (int j = 0; j < joinedChannels.Count; j++)
|
||||
{
|
||||
if (joinedChannels[j].Name == lastClosedChannelName)
|
||||
{
|
||||
alreadyJoined = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool lookupCondition(Channel ch) =>
|
||||
ch.Type == ChannelType.PM ? ch.Users.Any(u => u.Id == lastClosedChannelId)
|
||||
: ch.Id == lastClosedChannelId;
|
||||
|
||||
if (alreadyJoined == false)
|
||||
// If the user hasn't already joined the channel, try to join it
|
||||
if (joinedChannels.FirstOrDefault(lookupCondition) == null)
|
||||
{
|
||||
Channel lastClosedChannel = AvailableChannels.FirstOrDefault(c => c.Name == lastClosedChannelName);
|
||||
Channel lastClosedChannel = AvailableChannels.FirstOrDefault(lookupCondition);
|
||||
|
||||
if (lastClosedChannel != null)
|
||||
{
|
||||
JoinChannel(lastClosedChannel);
|
||||
return;
|
||||
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