Browse Source

Try to pull DM channels from cache on CHANNEL_CREATE

This resoles #741

Since Discord now dispatches a CHANNEL_CREATE for every message sent to
a bot, we check to see if a channel has already been added to the state
before creating a new one.
pull/751/head
Christopher F 8 years ago
parent
commit
de0c303c23
1 changed files with 4 additions and 1 deletions
  1. +4
    -1
      src/Discord.Net.WebSocket/DiscordSocketClient.cs

+ 4
- 1
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -1631,7 +1631,10 @@ namespace Discord.WebSocket

internal ISocketPrivateChannel AddPrivateChannel(API.Channel model, ClientState state)
{
var channel = SocketChannel.CreatePrivate(this, state, model);
ISocketPrivateChannel channel;
if ((channel = state.GetChannel(model.Id) as ISocketPrivateChannel) != null)
return channel;
channel = SocketChannel.CreatePrivate(this, state, model);
state.AddChannel(channel as SocketChannel);
if (channel is SocketDMChannel dm)
dm.Recipient.GlobalUser.DMChannel = dm;


Loading…
Cancel
Save