* Cleaned up and refactored slightly * Resolves #971 * Adds support for default avatars and resolves #971 * Amendment * Final amendment * Paginating reactions * Amendments based on feedback * Further amendment based on review * Final(?) amendment * Removes default limit and after user id * Removes fromUserId; cleans up model creation; replaces function with individual parameters
This commit is contained in:
committed by
Christopher F
parent
e764dafe08
commit
79811d0e61
@@ -46,13 +46,38 @@ namespace Discord.Rest
|
||||
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options);
|
||||
}
|
||||
|
||||
public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
|
||||
Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options)
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
|
||||
int? limit, BaseDiscordClient client, RequestOptions options)
|
||||
{
|
||||
var args = new GetReactionUsersParams();
|
||||
func(args);
|
||||
string emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name);
|
||||
return (await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false)).Select(u => RestUser.Create(client, u)).ToImmutableArray();
|
||||
Preconditions.NotNull(emote, nameof(emote));
|
||||
var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name);
|
||||
|
||||
return new PagedAsyncEnumerable<IUser>(
|
||||
DiscordConfig.MaxUserReactionsPerBatch,
|
||||
async (info, ct) =>
|
||||
{
|
||||
var args = new GetReactionUsersParams
|
||||
{
|
||||
Limit = info.PageSize
|
||||
};
|
||||
|
||||
if (info.Position != null)
|
||||
args.AfterUserId = info.Position.Value;
|
||||
|
||||
var models = await client.ApiClient.GetReactionUsersAsync(msg.Channel.Id, msg.Id, emoji, args, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestUser.Create(client, x)).ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
{
|
||||
if (lastPage.Count != DiscordConfig.MaxUsersPerBatch)
|
||||
return false;
|
||||
|
||||
info.Position = lastPage.Max(x => x.Id);
|
||||
return true;
|
||||
},
|
||||
count: limit
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client,
|
||||
|
||||
@@ -136,8 +136,8 @@ namespace Discord.Rest
|
||||
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options);
|
||||
public Task RemoveAllReactionsAsync(RequestOptions options = null)
|
||||
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
|
||||
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null)
|
||||
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
|
||||
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);
|
||||
|
||||
|
||||
public Task PinAsync(RequestOptions options = null)
|
||||
|
||||
Reference in New Issue
Block a user