Browse Source

ForumChannels returns only threads it is parent of

pull/2436/head
Fokusnikh 2 years ago
parent
commit
dc015f9779
4 changed files with 35 additions and 3 deletions
  1. +27
    -0
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  2. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs
  3. +5
    -0
      src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
  4. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs

+ 27
- 0
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -595,6 +595,33 @@ namespace Discord.API
return await SendAsync<ChannelThreads>("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options);
}

public async Task<ChannelThreads> GetActiveThreadsInChannelAsync(ulong guildId, ulong parentChannel, RequestOptions options = null)
{
Preconditions.NotEqual(guildId, 0, nameof(guildId));

options = RequestOptions.CreateOrClone(options);

var bucket = new BucketIds(guildId: guildId);

ChannelThreads allChannelThreads = await SendAsync<ChannelThreads>("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options);
ChannelThreads filteredThreads = new ChannelThreads();

filteredThreads.Threads = allChannelThreads.Threads.Where(x => x.CategoryId == parentChannel).ToArray();

List<ThreadMember> members = new List<ThreadMember>();

foreach (ThreadMember m in allChannelThreads.Members)
{
if (filteredThreads.Threads.Where(x => x.Id == (ulong)m.Id).Count() == 0)
continue;
members.Add(m);
}

filteredThreads.Members = members.ToArray();

return filteredThreads;
}

public async Task<ChannelThreads> GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null)
{
Preconditions.NotEqual(channelId, 0, nameof(channelId));


+ 1
- 1
src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs View File

@@ -92,7 +92,7 @@ namespace Discord.Rest

/// <inheritdoc cref="IForumChannel.GetActiveThreadsAsync(RequestOptions)"/>
public Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> ThreadHelper.GetActiveThreadsAsync(Guild, Discord, options);
=> ThreadHelper.GetActiveThreadsInChannelAsync(Guild, this, Discord, options);

/// <inheritdoc cref="IForumChannel.GetJoinedPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
public Task<IReadOnlyCollection<RestThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)


+ 5
- 0
src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs View File

@@ -67,6 +67,11 @@ namespace Discord.Rest
var result = await client.ApiClient.GetActiveThreadsAsync(guild.Id, options).ConfigureAwait(false);
return result.Threads.Select(x => RestThreadChannel.Create(client, guild, x)).ToImmutableArray();
}
public static async Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsInChannelAsync(IGuild guild, IGuildChannel parentChannel, BaseDiscordClient client, RequestOptions options)
{
var result = await client.ApiClient.GetActiveThreadsInChannelAsync(guild.Id, parentChannel.Id, options).ConfigureAwait(false);
return result.Threads.Select(x => RestThreadChannel.Create(client, guild, x)).ToImmutableArray();
}

public static async Task<IReadOnlyCollection<RestThreadChannel>> GetPublicArchivedThreadsAsync(IGuildChannel channel, BaseDiscordClient client, int? limit = null,
DateTimeOffset? before = null, RequestOptions options = null)


+ 2
- 2
src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs View File

@@ -89,7 +89,7 @@ namespace Discord.WebSocket

/// <inheritdoc cref="IForumChannel.GetActiveThreadsAsync(RequestOptions)"/>
public Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> ThreadHelper.GetActiveThreadsAsync(Guild, Discord, options);
=> ThreadHelper.GetActiveThreadsInChannelAsync(Guild, this, Discord, options);

/// <inheritdoc cref="IForumChannel.GetJoinedPrivateArchivedThreadsAsync(int?, DateTimeOffset?, RequestOptions)"/>
public Task<IReadOnlyCollection<RestThreadChannel>> GetJoinedPrivateArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)
@@ -105,7 +105,7 @@ namespace Discord.WebSocket

#region IForumChannel
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetActiveThreadsAsync(RequestOptions options)
=> await GetActiveThreadsAsync(options).ConfigureAwait(false);
=> await GetActiveThreadsInChannelAsync(options).ConfigureAwait(false);
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetPublicArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)
=> await GetPublicArchivedThreadsAsync(limit, before, options).ConfigureAwait(false);
async Task<IReadOnlyCollection<IThreadChannel>> IForumChannel.GetPrivateArchivedThreadsAsync(int? limit, DateTimeOffset? before, RequestOptions options)


Loading…
Cancel
Save