Fix usage of CacheMode.AllowDownload in channels (#2154)
Co-Authored-By: ✨ <25006819+sabihoshi@users.noreply.github.com> Co-authored-by: ✨ <25006819+sabihoshi@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,7 +352,7 @@ namespace Discord.WebSocket
|
||||
Task IAudioChannel.ModifyAsync(Action<AudioChannelProperties> func, RequestOptions options) { throw new NotSupportedException(); }
|
||||
#endregion
|
||||
|
||||
#region IChannel
|
||||
#region IChannel
|
||||
/// <inheritdoc />
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IUser>(GetUser(id));
|
||||
|
||||
@@ -214,10 +214,10 @@ namespace Discord.WebSocket
|
||||
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
|
||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable(); //Overridden in Text/Voice
|
||||
/// <inheritdoc />
|
||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IGuildUser>(GetUser(id));
|
||||
=> Task.FromResult<IGuildUser>(GetUser(id)); //Overridden in Text/Voice
|
||||
#endregion
|
||||
|
||||
#region IChannel
|
||||
|
||||
@@ -103,7 +103,7 @@ namespace Discord.WebSocket
|
||||
/// The duration on which this thread archives after.
|
||||
/// <para>
|
||||
/// <b>Note: </b> Options <see cref="ThreadArchiveDuration.OneWeek"/> and <see cref="ThreadArchiveDuration.ThreeDays"/>
|
||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the
|
||||
/// are only available for guilds that are boosted. You can check in the <see cref="IGuild.Features"/> to see if the
|
||||
/// guild has the <b>THREE_DAY_THREAD_ARCHIVE</b> and <b>SEVEN_DAY_THREAD_ARCHIVE</b>.
|
||||
/// </para>
|
||||
/// </param>
|
||||
@@ -355,11 +355,22 @@ namespace Discord.WebSocket
|
||||
|
||||
#region IGuildChannel
|
||||
/// <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);
|
||||
}
|
||||
/// <inheritdoc />
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
|
||||
{
|
||||
return mode == CacheMode.AllowDownload
|
||||
? ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options)
|
||||
: ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IMessageChannel
|
||||
|
||||
Reference in New Issue
Block a user