|
|
@@ -4,6 +4,7 @@ using System.Collections.Immutable; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Discord.Rest; |
|
|
|
using Model = Discord.API.Channel; |
|
|
|
|
|
|
|
namespace Discord.WebSocket |
|
|
@@ -64,21 +65,44 @@ namespace Discord.WebSocket |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region IGuildChannel |
|
|
|
|
|
|
|
/// <inheritdoc /> |
|
|
|
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options) |
|
|
|
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); |
|
|
|
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, |
|
|
|
RequestOptions options) |
|
|
|
{ |
|
|
|
return mode == CacheMode.AllowDownload |
|
|
|
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options) |
|
|
|
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); |
|
|
|
} |
|
|
|
/// <inheritdoc /> |
|
|
|
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
=> Task.FromResult<IGuildUser>(GetUser(id)); |
|
|
|
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
{ |
|
|
|
var user = GetUser(id); |
|
|
|
if (user is not null || mode == CacheMode.CacheOnly) |
|
|
|
return user; |
|
|
|
|
|
|
|
return await ChannelHelper.GetUserAsync(this, Guild, Discord, id, options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
|
|
|
|
#region IChannel |
|
|
|
|
|
|
|
/// <inheritdoc /> |
|
|
|
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options) |
|
|
|
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable(); |
|
|
|
{ |
|
|
|
return mode == CacheMode.AllowDownload |
|
|
|
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options) |
|
|
|
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); |
|
|
|
} |
|
|
|
/// <inheritdoc /> |
|
|
|
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
=> Task.FromResult<IUser>(GetUser(id)); |
|
|
|
async Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) |
|
|
|
{ |
|
|
|
var user = GetUser(id); |
|
|
|
if (user is not null || mode == CacheMode.CacheOnly) |
|
|
|
return user; |
|
|
|
|
|
|
|
return await ChannelHelper.GetUserAsync(this, Guild, Discord, id, options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
#endregion |
|
|
|
} |
|
|
|
} |