Remove IUser.CreateDMChannelAsync / Fix SocketGlobalUser.DMChanneltags/1.0
| @@ -20,8 +20,6 @@ namespace Discord | |||||
| string Username { get; } | string Username { get; } | ||||
| /// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | /// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | ||||
| Task<IDMChannel> GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||||
| /// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary> | |||||
| Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null); | |||||
| Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null); | |||||
| } | } | ||||
| } | } | ||||
| @@ -54,7 +54,7 @@ namespace Discord.Rest | |||||
| Update(model); | Update(model); | ||||
| } | } | ||||
| public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null) | |||||
| public Task<RestDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null) | |||||
| => UserHelper.CreateDMChannelAsync(this, Discord, options); | => UserHelper.CreateDMChannelAsync(this, Discord, options); | ||||
| public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| @@ -64,9 +64,7 @@ namespace Discord.Rest | |||||
| private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | ||||
| //IUser | //IUser | ||||
| Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) | |||||
| => Task.FromResult<IDMChannel>(null); | |||||
| async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options) | |||||
| => await CreateDMChannelAsync(options).ConfigureAwait(false); | |||||
| async Task<IDMChannel> IUser.GetOrCreateDMChannelAsync(RequestOptions options) | |||||
| => await GetOrCreateDMChannelAsync(options); | |||||
| } | } | ||||
| } | } | ||||
| @@ -49,7 +49,7 @@ namespace Discord.Rpc | |||||
| Username = model.Username.Value; | Username = model.Username.Value; | ||||
| } | } | ||||
| public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null) | |||||
| public Task<RestDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null) | |||||
| => UserHelper.CreateDMChannelAsync(this, Discord, options); | => UserHelper.CreateDMChannelAsync(this, Discord, options); | ||||
| public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| @@ -59,9 +59,7 @@ namespace Discord.Rpc | |||||
| private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | ||||
| //IUser | //IUser | ||||
| Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) | |||||
| => Task.FromResult<IDMChannel>(null); | |||||
| async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options) | |||||
| => await CreateDMChannelAsync(options).ConfigureAwait(false); | |||||
| async Task<IDMChannel> IUser.GetOrCreateDMChannelAsync(RequestOptions options) | |||||
| => await GetOrCreateDMChannelAsync(options); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1634,6 +1634,9 @@ namespace Discord.WebSocket | |||||
| { | { | ||||
| var channel = SocketChannel.CreatePrivate(this, state, model); | var channel = SocketChannel.CreatePrivate(this, state, model); | ||||
| state.AddChannel(channel as SocketChannel); | state.AddChannel(channel as SocketChannel); | ||||
| if (channel is SocketDMChannel dm) | |||||
| dm.Recipient.GlobalUser.DMChannel = dm; | |||||
| return channel; | return channel; | ||||
| } | } | ||||
| internal ISocketPrivateChannel RemovePrivateChannel(ulong id) | internal ISocketPrivateChannel RemovePrivateChannel(ulong id) | ||||
| @@ -1641,6 +1644,9 @@ namespace Discord.WebSocket | |||||
| var channel = State.RemoveChannel(id) as ISocketPrivateChannel; | var channel = State.RemoveChannel(id) as ISocketPrivateChannel; | ||||
| if (channel != null) | if (channel != null) | ||||
| { | { | ||||
| if (channel is SocketDMChannel dmChannel) | |||||
| dmChannel.Recipient.GlobalUser.DMChannel = null; | |||||
| foreach (var recipient in channel.Recipients) | foreach (var recipient in channel.Recipients) | ||||
| recipient.GlobalUser.RemoveRef(this); | recipient.GlobalUser.RemoveRef(this); | ||||
| } | } | ||||
| @@ -1,4 +1,5 @@ | |||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Linq; | |||||
| using Model = Discord.API.User; | using Model = Discord.API.User; | ||||
| using PresenceModel = Discord.API.Presence; | using PresenceModel = Discord.API.Presence; | ||||
| @@ -51,6 +52,7 @@ namespace Discord.WebSocket | |||||
| internal void Update(ClientState state, PresenceModel model) | internal void Update(ClientState state, PresenceModel model) | ||||
| { | { | ||||
| Presence = SocketPresence.Create(model); | Presence = SocketPresence.Create(model); | ||||
| DMChannel = state.DMChannels.FirstOrDefault(x => x.Recipient.Id == Id); | |||||
| } | } | ||||
| internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser; | internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser; | ||||
| @@ -146,11 +146,7 @@ namespace Discord.WebSocket | |||||
| IGuild IGuildUser.Guild => Guild; | IGuild IGuildUser.Guild => Guild; | ||||
| ulong IGuildUser.GuildId => Guild.Id; | ulong IGuildUser.GuildId => Guild.Id; | ||||
| IReadOnlyCollection<ulong> IGuildUser.RoleIds => _roleIds; | IReadOnlyCollection<ulong> IGuildUser.RoleIds => _roleIds; | ||||
| //IUser | |||||
| Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) | |||||
| => Task.FromResult<IDMChannel>(GlobalUser.DMChannel); | |||||
| //IVoiceState | //IVoiceState | ||||
| IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel; | IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel; | ||||
| } | } | ||||
| @@ -53,10 +53,10 @@ namespace Discord.WebSocket | |||||
| hasChanges = true; | hasChanges = true; | ||||
| } | } | ||||
| return hasChanges; | 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) | public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128) | ||||
| => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | => CDN.GetUserAvatarUrl(Id, AvatarId, size, format); | ||||
| @@ -64,11 +64,5 @@ namespace Discord.WebSocket | |||||
| public override string ToString() => $"{Username}#{Discriminator}"; | public override string ToString() => $"{Username}#{Discriminator}"; | ||||
| private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; | ||||
| internal SocketUser Clone() => MemberwiseClone() as SocketUser; | 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); | |||||
| } | } | ||||
| } | } | ||||