From 70cb22a93b12eb914f7011dc9eb1fcf84ccdfc37 Mon Sep 17 00:00:00 2001 From: Fokusnikh <96922685+Polybroo@users.noreply.github.com> Date: Tue, 23 Aug 2022 21:53:57 +0200 Subject: [PATCH] Revert "Logic and naming changes" This reverts commit 438ca37a1d2c4384f2bf77d86b3bdc3f8eadac74. --- src/Discord.Net.Rest/DiscordRestApiClient.cs | 32 ++++++++++++++----- .../Entities/Channels/RestGuildChannel.cs | 2 +- .../Entities/Channels/ThreadHelper.cs | 14 ++++---- .../Entities/Channels/SocketGuildChannel.cs | 2 +- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 78e2a488c..a6c971842 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -584,7 +584,7 @@ namespace Discord.API return await SendAsync("GET", () => $"channels/{channelId}/thread-members/{userId}", bucket, options: options).ConfigureAwait(false); } - public async Task GetActiveThreadsInGuildAsync(ulong guildId, RequestOptions options = null) + public async Task GetActiveThreadsAsync(ulong guildId, RequestOptions options = null) { Preconditions.NotEqual(guildId, 0, nameof(guildId)); @@ -595,18 +595,34 @@ namespace Discord.API return await SendAsync("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options); } - public async Task GetActiveThreadsInChannelAsync(ulong channelId, RequestOptions options = null) + public async Task GetActiveThreadsInChannelAsync(ulong guildId, ulong parentChannel, RequestOptions options = null) { - Preconditions.NotEqual(channelId, 0, nameof(channelId)); + Preconditions.NotEqual(guildId, 0, nameof(guildId)); options = RequestOptions.CreateOrClone(options); - var bucket = new BucketIds(channelId: channelId); + var bucket = new BucketIds(guildId: guildId); + + ChannelThreads allChannelThreads = await SendAsync("GET", () => $"guilds/{guildId}/threads/active", bucket, options: options); + ChannelThreads filteredThreads = new ChannelThreads(); + + filteredThreads.Threads = allChannelThreads.Threads.Where(x => x.CategoryId == parentChannel).ToArray(); + + List members = new List(); + + 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 await SendAsync("GET", () => $"channels/{channelId}/threads/active", bucket, options: options); + return filteredThreads; } - public async Task GetPublicArchivedThreadsInChannelAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) + public async Task GetPublicArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -628,7 +644,7 @@ namespace Discord.API return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/public{query}", bucket, options: options); } - public async Task GetPrivateArchivedThreadsInChannelAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + public async Task GetPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); @@ -651,7 +667,7 @@ namespace Discord.API return await SendAsync("GET", () => $"channels/{channelId}/threads/archived/private{query}", bucket, options: options); } - public async Task GetJoinedPrivateArchivedThreadsInChannelAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, + public async Task GetJoinedPrivateArchivedThreadsAsync(ulong channelId, DateTimeOffset? before = null, int? limit = null, RequestOptions options = null) { Preconditions.NotEqual(channelId, 0, nameof(channelId)); diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs index 2caee3da8..7bef98d28 100644 --- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs +++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs @@ -236,7 +236,7 @@ namespace Discord.Rest /// public Task> GetActiveThreadsAsync(RequestOptions options = null) - => ThreadHelper.GetActiveThreadsAsync(this, Discord, options); + => ThreadHelper.GetActiveThreadsInChannelAsync(Guild, this, Discord, options); /// public Task> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null) diff --git a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs index 563d550cd..7e0494e58 100644 --- a/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs +++ b/src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs @@ -64,33 +64,33 @@ namespace Discord.Rest public static async Task> GetActiveThreadsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options) { - var result = await client.ApiClient.GetActiveThreadsInGuildAsync(guild.Id, options).ConfigureAwait(false); + 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> GetActiveThreadsAsync(IGuildChannel channel, BaseDiscordClient client, RequestOptions options) + public static async Task> GetActiveThreadsInChannelAsync(IGuild guild, IGuildChannel parentChannel, BaseDiscordClient client, RequestOptions options) { - var result = await client.ApiClient.GetActiveThreadsInChannelAsync(channel.Id, options).ConfigureAwait(false); - return result.Threads.Select(x => RestThreadChannel.Create(client, channel.Guild, x)).ToImmutableArray(); + 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> GetPublicArchivedThreadsAsync(IGuildChannel channel, BaseDiscordClient client, int? limit = null, DateTimeOffset? before = null, RequestOptions options = null) { - var result = await client.ApiClient.GetPublicArchivedThreadsInChannelAsync(channel.Id, before, limit, options); + var result = await client.ApiClient.GetPublicArchivedThreadsAsync(channel.Id, before, limit, options); return result.Threads.Select(x => RestThreadChannel.Create(client, channel.Guild, x)).ToImmutableArray(); } public static async Task> GetPrivateArchivedThreadsAsync(IGuildChannel channel, BaseDiscordClient client, int? limit = null, DateTimeOffset? before = null, RequestOptions options = null) { - var result = await client.ApiClient.GetPrivateArchivedThreadsInChannelAsync(channel.Id, before, limit, options); + var result = await client.ApiClient.GetPrivateArchivedThreadsAsync(channel.Id, before, limit, options); return result.Threads.Select(x => RestThreadChannel.Create(client, channel.Guild, x)).ToImmutableArray(); } public static async Task> GetJoinedPrivateArchivedThreadsAsync(IGuildChannel channel, BaseDiscordClient client, int? limit = null, DateTimeOffset? before = null, RequestOptions options = null) { - var result = await client.ApiClient.GetJoinedPrivateArchivedThreadsInChannelAsync(channel.Id, before, limit, options); + var result = await client.ApiClient.GetJoinedPrivateArchivedThreadsAsync(channel.Id, before, limit, options); return result.Threads.Select(x => RestThreadChannel.Create(client, channel.Guild, x)).ToImmutableArray(); } diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs index bf13c8326..d3dc1f138 100644 --- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs +++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs @@ -179,7 +179,7 @@ namespace Discord.WebSocket /// public Task> GetActiveThreadsAsync(RequestOptions options = null) - => ThreadHelper.GetActiveThreadsAsync(this, Discord, options); + => ThreadHelper.GetActiveThreadsInChannelAsync(Guild, this, Discord, options); /// public Task> GetPublicArchivedThreadsAsync(int? limit = null, DateTimeOffset? before = null, RequestOptions options = null)