Browse Source

Removes fromUserId; cleans up model creation; replaces function with individual parameters

pull/1022/head
HelpfulStranger999 7 years ago
parent
commit
424259f423
3 changed files with 9 additions and 17 deletions
  1. +7
    -15
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  2. +1
    -1
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  3. +1
    -1
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs

+ 7
- 15
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -47,32 +47,25 @@ namespace Discord.Rest
}

public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options)
int? limit, BaseDiscordClient client, RequestOptions options)
{
Preconditions.NotNull(emote, nameof(emote));
var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name);

var arguments = new GetReactionUsersParams();
func(arguments);

return new PagedAsyncEnumerable<IUser>(
DiscordConfig.MaxUserReactionsPerBatch,
async (info, ct) =>
{
var args = new GetReactionUsersParams();
func(args);
args.Limit = info.PageSize;
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);
var builder = ImmutableArray.CreateBuilder<IUser>();

foreach (var model in models)
builder.Add(RestUser.Create(client, model));

return builder.ToImmutable();
return models.Select(x => RestUser.Create(client, x)).ToImmutableArray();
},
nextPage: (info, lastPage) =>
{
@@ -82,8 +75,7 @@ namespace Discord.Rest
info.Position = lastPage.Max(x => x.Id);
return true;
},
start: arguments.AfterUserId.IsSpecified ? arguments.AfterUserId.Value : (ulong?)null,
count: arguments.Limit.GetValueOrDefault(DiscordConfig.MaxUserReactionsPerBatch)
count: limit
);

}


+ 1
- 1
src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs View File

@@ -137,7 +137,7 @@ namespace Discord.Rest
public Task RemoveAllReactionsAsync(RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; }, Discord, options);
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);


public Task PinAsync(RequestOptions options = null)


+ 1
- 1
src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs View File

@@ -131,7 +131,7 @@ namespace Discord.WebSocket
public Task RemoveAllReactionsAsync(RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
public IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit, RequestOptions options = null)
=> MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; }, Discord, options);
=> MessageHelper.GetReactionUsersAsync(this, emote, limit, Discord, options);

public Task PinAsync(RequestOptions options = null)
=> MessageHelper.PinAsync(this, Discord, options);


Loading…
Cancel
Save