fix: Create DM channel with id and author alone (#1850)
* Create DM channel with id and author alone * Unneeded cast
This commit is contained in:
@@ -1236,8 +1236,8 @@ namespace Discord.WebSocket
|
||||
await _gatewayLogger.DebugAsync("Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false);
|
||||
|
||||
var data = (payload as JToken).ToObject<API.Message>(_serializer);
|
||||
if (State.GetChannel(data.ChannelId) is ISocketMessageChannel channel)
|
||||
{
|
||||
var channel = State.GetChannel(data.ChannelId) as ISocketMessageChannel;
|
||||
|
||||
var guild = (channel as SocketGuildChannel)?.Guild;
|
||||
if (guild != null && !guild.IsSynced)
|
||||
{
|
||||
@@ -1254,7 +1254,7 @@ namespace Discord.WebSocket
|
||||
author = guild.GetUser(data.Author.Value.Id);
|
||||
}
|
||||
else
|
||||
author = (channel as SocketChannel).GetUser(data.Author.Value.Id);
|
||||
author = (channel as SocketChannel)?.GetUser(data.Author.Value.Id);
|
||||
|
||||
if (author == null)
|
||||
{
|
||||
@@ -1268,11 +1268,24 @@ namespace Discord.WebSocket
|
||||
else
|
||||
author = guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data
|
||||
}
|
||||
else if (channel is SocketGroupChannel)
|
||||
author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value);
|
||||
else if (channel is SocketGroupChannel groupChannel)
|
||||
author = groupChannel.GetOrAddUser(data.Author.Value);
|
||||
else
|
||||
author = State.GetOrAddUser(data.Author.Value.Id, x => SocketGlobalUser.Create(this, State, data.Author.Value));
|
||||
}
|
||||
|
||||
if (channel == null)
|
||||
{
|
||||
if (!data.GuildId.IsSpecified) // assume it is a DM
|
||||
{
|
||||
var dm = SocketDMChannel.Create(this, State, data.ChannelId, data.Author.Value);
|
||||
channel = dm;
|
||||
State.AddChannel(dm);
|
||||
dm.Recipient.GlobalUser.DMChannel = dm;
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownChannelUserAsync(type, data.Author.Value.Id, channel.Id).ConfigureAwait(false);
|
||||
await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1281,12 +1294,6 @@ namespace Discord.WebSocket
|
||||
SocketChannelHelper.AddMessage(channel, this, msg);
|
||||
await TimedInvokeAsync(_messageReceivedEvent, nameof(MessageReceived), msg).ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
await UnknownChannelAsync(type, data.ChannelId).ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "MESSAGE_UPDATE":
|
||||
{
|
||||
|
||||
@@ -49,6 +49,16 @@ namespace Discord.WebSocket
|
||||
{
|
||||
Recipient.Update(state, model.Recipients.Value[0]);
|
||||
}
|
||||
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, ulong channelId, API.User recipient)
|
||||
{
|
||||
var entity = new SocketDMChannel(discord, channelId, discord.GetOrCreateUser(state, recipient));
|
||||
entity.Update(state, recipient);
|
||||
return entity;
|
||||
}
|
||||
internal void Update(ClientState state, API.User recipient)
|
||||
{
|
||||
Recipient.Update(state, recipient);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task CloseAsync(RequestOptions options = null)
|
||||
|
||||
Reference in New Issue
Block a user