mirror of
https://github.com/osukey/osukey.git
synced 2025-08-06 16:13:57 +09:00
Making style changes + supports reopening PM chats
This commit is contained in:
@ -33,8 +33,12 @@ 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 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.
|
// 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 +422,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.Name);
|
closedChannelIds.Add(channel.Type == ChannelType.PM ? channel.Users.First().Id : channel.Id);
|
||||||
|
|
||||||
if (channel.Joined.Value)
|
if (channel.Joined.Value)
|
||||||
{
|
{
|
||||||
@ -440,7 +444,7 @@ namespace osu.Game.Online.Chat
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void JoinLastClosedChannel()
|
public void JoinLastClosedChannel()
|
||||||
{
|
{
|
||||||
if (closedChannels.Count <= 0)
|
if (closedChannelIds.Count <= 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -451,32 +455,32 @@ namespace osu.Game.Online.Chat
|
|||||||
// every time the user joins a channel, which would make joining a channel
|
// every time the user joins a channel, which would make joining a channel
|
||||||
// slower. I wanted to centralize all major slowdowns so they
|
// slower. I wanted to centralize all major slowdowns so they
|
||||||
// can only occur if the user actually decides to use this feature.
|
// 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();
|
long lastClosedChannelId = closedChannelIds.Last();
|
||||||
closedChannels.RemoveAt(closedChannels.Count - 1);
|
closedChannelIds.RemoveAt(closedChannelIds.Count - 1);
|
||||||
bool alreadyJoined = false;
|
|
||||||
|
|
||||||
// If the user already joined the channel, do not
|
bool lookupCondition(Channel ch) =>
|
||||||
// try to join it
|
ch.Type == ChannelType.PM ? ch.Users.Any(u => u.Id == lastClosedChannelId)
|
||||||
for (int j = 0; j < joinedChannels.Count; j++)
|
: ch.Id == lastClosedChannelId;
|
||||||
{
|
|
||||||
if (joinedChannels[j].Name == lastClosedChannelName)
|
|
||||||
{
|
|
||||||
alreadyJoined = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
if (lastClosedChannel != null)
|
||||||
{
|
{
|
||||||
JoinChannel(lastClosedChannel);
|
CurrentChannel.Value = JoinChannel(lastClosedChannel);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user