Browse Source

Paginating reactions

pull/1022/head
HelpfulStranger999 8 years ago
parent
commit
57c55a7154
6 changed files with 34 additions and 9 deletions
  1. +0
    -1
      src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs
  2. +2
    -2
      src/Discord.Net.Core/Entities/Messages/IUserMessage.cs
  3. +1
    -1
      src/Discord.Net.Rest/API/Rest/GetReactionUsersParams.cs
  4. +29
    -3
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  5. +1
    -1
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  6. +1
    -1
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs

+ 0
- 1
src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs View File

@@ -231,7 +231,6 @@ namespace Discord
{ {
private string _name; private string _name;
private string _value; private string _value;
private EmbedField _field;
public const int MaxFieldNameLength = 256; public const int MaxFieldNameLength = 256;
public const int MaxFieldValueLength = 1024; public const int MaxFieldValueLength = 1024;




+ 2
- 2
src/Discord.Net.Core/Entities/Messages/IUserMessage.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;


@@ -23,7 +23,7 @@ namespace Discord
/// <summary> Removes all reactions from this message. </summary> /// <summary> Removes all reactions from this message. </summary>
Task RemoveAllReactionsAsync(RequestOptions options = null); Task RemoveAllReactionsAsync(RequestOptions options = null);
/// <summary> Gets all users that reacted to a message with a given emote </summary> /// <summary> Gets all users that reacted to a message with a given emote </summary>
Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit = 100, ulong? afterUserId = null, RequestOptions options = null);
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emoji, int limit = 100, ulong? afterUserId = null, RequestOptions options = null);


/// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary> /// <summary> Transforms this message's text into a human readable form by resolving its tags. </summary>
string Resolve( string Resolve(


+ 1
- 1
src/Discord.Net.Rest/API/Rest/GetReactionUsersParams.cs View File

@@ -1,4 +1,4 @@
namespace Discord.API.Rest
namespace Discord.API.Rest
{ {
internal class GetReactionUsersParams internal class GetReactionUsersParams
{ {


+ 29
- 3
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -46,13 +46,39 @@ namespace Discord.Rest
await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options); await client.ApiClient.RemoveAllReactionsAsync(msg.Channel.Id, msg.Id, options);
} }


public static async Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
public static IAsyncEnumerable<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IMessage msg, IEmote emote,
Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options) Action<GetReactionUsersParams> func, BaseDiscordClient client, RequestOptions options)
{ {
var args = new GetReactionUsersParams(); var args = new GetReactionUsersParams();
func(args); 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();

var emoji = (emote is Emote e ? $"{e.Name}:{e.Id}" : emote.Name);
return new PagedAsyncEnumerable<IUser>(
DiscordConfig.MaxUsersPerBatch,
async (info, ct) =>
{
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();
},
nextPage: (info, lastPage) =>
{
if (lastPage.Count != DiscordConfig.MaxUsersPerBatch)
return false;

info.Position = lastPage.OrderBy(u => u.Id).First().Id;
return true;
},
count: args.Limit.Value
);

} }


public static async Task PinAsync(IMessage msg, BaseDiscordClient client, public static async Task PinAsync(IMessage msg, BaseDiscordClient client,


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

@@ -136,7 +136,7 @@ namespace Discord.Rest
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); => MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options);
public Task RemoveAllReactionsAsync(RequestOptions options = null) public Task RemoveAllReactionsAsync(RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options); => MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null)
public IAsyncEnumerable<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); => MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options);






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

@@ -130,7 +130,7 @@ namespace Discord.WebSocket
=> MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options); => MessageHelper.RemoveReactionAsync(this, user, emote, Discord, options);
public Task RemoveAllReactionsAsync(RequestOptions options = null) public Task RemoveAllReactionsAsync(RequestOptions options = null)
=> MessageHelper.RemoveAllReactionsAsync(this, Discord, options); => MessageHelper.RemoveAllReactionsAsync(this, Discord, options);
public Task<IReadOnlyCollection<IUser>> GetReactionUsersAsync(IEmote emote, int limit = 100, ulong? afterUserId = null, RequestOptions options = null)
public IAsyncEnumerable<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); => MessageHelper.GetReactionUsersAsync(this, emote, x => { x.Limit = limit; x.AfterUserId = afterUserId ?? Optional.Create<ulong>(); }, Discord, options);


public Task PinAsync(RequestOptions options = null) public Task PinAsync(RequestOptions options = null)


Loading…
Cancel
Save