Add various optimizations and cleanups (#1114)
* Change all Select(... as ...) to OfType
* Add changes according to 194a8aa427
This commit is contained in:
@@ -97,7 +97,7 @@ namespace Discord.WebSocket
|
||||
if (id == Recipient.Id)
|
||||
return Recipient;
|
||||
else if (id == Discord.CurrentUser.Id)
|
||||
return Discord.CurrentUser as SocketSelfUser;
|
||||
return Discord.CurrentUser;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ namespace Discord.WebSocket
|
||||
public class SocketGroupChannel : SocketChannel, IGroupChannel, ISocketPrivateChannel, ISocketMessageChannel, ISocketAudioChannel
|
||||
{
|
||||
private readonly MessageCache _messages;
|
||||
private readonly ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates;
|
||||
|
||||
private string _iconId;
|
||||
private ConcurrentDictionary<ulong, SocketGroupUser> _users;
|
||||
private ConcurrentDictionary<ulong, SocketVoiceState> _voiceStates;
|
||||
|
||||
public string Name { get; private set; }
|
||||
|
||||
@@ -129,7 +129,7 @@ namespace Discord.WebSocket
|
||||
internal SocketGroupUser GetOrAddUser(UserModel model)
|
||||
{
|
||||
if (_users.TryGetValue(model.Id, out SocketGroupUser user))
|
||||
return user as SocketGroupUser;
|
||||
return user;
|
||||
else
|
||||
{
|
||||
var privateUser = SocketGroupUser.Create(this, Discord.State, model);
|
||||
@@ -143,7 +143,7 @@ namespace Discord.WebSocket
|
||||
if (_users.TryRemove(id, out SocketGroupUser user))
|
||||
{
|
||||
user.GlobalUser.RemoveRef(Discord);
|
||||
return user as SocketGroupUser;
|
||||
return user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -91,11 +91,11 @@ namespace Discord.WebSocket
|
||||
}
|
||||
}
|
||||
public IReadOnlyCollection<SocketTextChannel> TextChannels
|
||||
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray();
|
||||
=> Channels.OfType<SocketTextChannel>().ToImmutableArray();
|
||||
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels
|
||||
=> Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray();
|
||||
=> Channels.OfType<SocketVoiceChannel>().ToImmutableArray();
|
||||
public IReadOnlyCollection<SocketCategoryChannel> CategoryChannels
|
||||
=> Channels.Select(x => x as SocketCategoryChannel).Where(x => x != null).ToImmutableArray();
|
||||
=> Channels.OfType<SocketCategoryChannel>().ToImmutableArray();
|
||||
public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null;
|
||||
public SocketRole EveryoneRole => GetRole(Id);
|
||||
public IReadOnlyCollection<SocketGuildChannel> Channels
|
||||
@@ -563,7 +563,7 @@ namespace Discord.WebSocket
|
||||
|
||||
await Discord.ApiClient.SendVoiceStateUpdateAsync(Id, channelId, selfDeaf, selfMute).ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
await DisconnectAudioInternalAsync().ConfigureAwait(false);
|
||||
throw;
|
||||
@@ -580,7 +580,7 @@ namespace Discord.WebSocket
|
||||
throw new TimeoutException();
|
||||
return await promise.Task.ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception)
|
||||
catch
|
||||
{
|
||||
await DisconnectAudioAsync().ConfigureAwait(false);
|
||||
throw;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
@@ -28,7 +28,7 @@ namespace Discord.WebSocket
|
||||
_orderedMessages.Enqueue(message.Id);
|
||||
|
||||
while (_orderedMessages.Count > _size && _orderedMessages.TryDequeue(out ulong msgId))
|
||||
_messages.TryRemove(msgId, out SocketMessage msg);
|
||||
_messages.TryRemove(msgId, out _);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace Discord.WebSocket
|
||||
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
||||
public class SocketUserMessage : SocketMessage, IUserMessage
|
||||
{
|
||||
private readonly List<SocketReaction> _reactions = new List<SocketReaction>();
|
||||
private bool _isMentioningEveryone, _isTTS, _isPinned;
|
||||
private long? _editedTimestampTicks;
|
||||
private ImmutableArray<Attachment> _attachments;
|
||||
private ImmutableArray<Embed> _embeds;
|
||||
private ImmutableArray<ITag> _tags;
|
||||
private List<SocketReaction> _reactions = new List<SocketReaction>();
|
||||
|
||||
public override bool IsTTS => _isTTS;
|
||||
public override bool IsPinned => _isPinned;
|
||||
|
||||
Reference in New Issue
Block a user