Merge pull request #656 from AntiTcb/fix/GetDMChannelAsync
Remove IUser.CreateDMChannelAsync / Fix SocketGlobalUser.DMChannel
This commit is contained in:
@@ -1634,6 +1634,9 @@ namespace Discord.WebSocket
|
||||
{
|
||||
var channel = SocketChannel.CreatePrivate(this, state, model);
|
||||
state.AddChannel(channel as SocketChannel);
|
||||
if (channel is SocketDMChannel dm)
|
||||
dm.Recipient.GlobalUser.DMChannel = dm;
|
||||
|
||||
return channel;
|
||||
}
|
||||
internal ISocketPrivateChannel RemovePrivateChannel(ulong id)
|
||||
@@ -1641,6 +1644,9 @@ namespace Discord.WebSocket
|
||||
var channel = State.RemoveChannel(id) as ISocketPrivateChannel;
|
||||
if (channel != null)
|
||||
{
|
||||
if (channel is SocketDMChannel dmChannel)
|
||||
dmChannel.Recipient.GlobalUser.DMChannel = null;
|
||||
|
||||
foreach (var recipient in channel.Recipients)
|
||||
recipient.GlobalUser.RemoveRef(this);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model = Discord.API.User;
|
||||
using PresenceModel = Discord.API.Presence;
|
||||
|
||||
@@ -51,6 +52,7 @@ namespace Discord.WebSocket
|
||||
internal void Update(ClientState state, PresenceModel model)
|
||||
{
|
||||
Presence = SocketPresence.Create(model);
|
||||
DMChannel = state.DMChannels.FirstOrDefault(x => x.Recipient.Id == Id);
|
||||
}
|
||||
|
||||
internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser;
|
||||
|
||||
@@ -146,11 +146,7 @@ namespace Discord.WebSocket
|
||||
IGuild IGuildUser.Guild => Guild;
|
||||
ulong IGuildUser.GuildId => Guild.Id;
|
||||
IReadOnlyCollection<ulong> IGuildUser.RoleIds => _roleIds;
|
||||
|
||||
//IUser
|
||||
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IDMChannel>(GlobalUser.DMChannel);
|
||||
|
||||
|
||||
//IVoiceState
|
||||
IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel;
|
||||
}
|
||||
|
||||
@@ -53,10 +53,10 @@ namespace Discord.WebSocket
|
||||
hasChanges = true;
|
||||
}
|
||||
return hasChanges;
|
||||
}
|
||||
}
|
||||
|
||||
public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null)
|
||||
=> UserHelper.CreateDMChannelAsync(this, Discord, options);
|
||||
public async Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
|
||||
=> GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options) as IDMChannel;
|
||||
|
||||
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
|
||||
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);
|
||||
@@ -64,11 +64,5 @@ namespace Discord.WebSocket
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
internal SocketUser Clone() => MemberwiseClone() as SocketUser;
|
||||
|
||||
//IUser
|
||||
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IDMChannel>(GlobalUser.DMChannel);
|
||||
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
|
||||
=> await CreateDMChannelAsync(options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user