Browse Source

Fix `GetActiveThreadsAsync` & add it to `ITextChannel` (#2526)

* fix `GetActiveThreadsAsync` being sadge

* ah, forgot about mocked channel
tags/3.9.0
Misha133 GitHub 2 years ago
parent
commit
bd2f719774
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 51 additions and 8 deletions
  1. +10
    -0
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  2. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/RestForumChannel.cs
  3. +8
    -0
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  4. +4
    -0
      src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs
  5. +4
    -0
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  6. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/ThreadHelper.cs
  7. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketForumChannel.cs
  8. +9
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  9. +4
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs
  10. +4
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
  11. +2
    -1
      test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs

+ 10
- 0
src/Discord.Net.Core/Entities/Channels/ITextChannel.cs View File

@@ -160,5 +160,15 @@ namespace Discord
/// </returns>
Task<IThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay,
IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null);

/// <summary>
/// Gets a collection of active threads within this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A task that represents an asynchronous get operation for retrieving the threads. The task result contains
/// a collection of active threads.
/// </returns>
Task<IReadOnlyCollection<IThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null);
}
}

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

@@ -134,9 +134,9 @@ namespace Discord.Rest
MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null)
=> ThreadHelper.CreatePostAsync(this, Discord, title, attachments, archiveDuration, slowmode, text, embed, options, allowedMentions, components, stickers, embeds, flags, tags?.Select(tag => tag.Id).ToArray());

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

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


+ 8
- 0
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -288,6 +288,10 @@ namespace Discord.Rest
/// <inheritdoc />
public Task SyncPermissionsAsync(RequestOptions options = null)
=> ChannelHelper.SyncPermissionsAsync(this, Discord, options);

/// <inheritdoc cref="ITextChannel.GetActiveThreadsAsync(RequestOptions)"/>
public virtual Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> ThreadHelper.GetActiveThreadsAsync(Guild, Id, Discord, options);
#endregion

#region Invites
@@ -321,6 +325,10 @@ namespace Discord.Rest

async Task<IThreadChannel> ITextChannel.CreateThreadAsync(string name, ThreadType type, ThreadArchiveDuration autoArchiveDuration, IMessage message, bool? invitable, int? slowmode, RequestOptions options)
=> await CreateThreadAsync(name, type, autoArchiveDuration, message, invitable, slowmode, options);

/// <inheritdoc />
async Task<IReadOnlyCollection<IThreadChannel>> ITextChannel.GetActiveThreadsAsync(RequestOptions options)
=> await GetActiveThreadsAsync(options);
#endregion

#region IMessageChannel


+ 4
- 0
src/Discord.Net.Rest/Entities/Channels/RestThreadChannel.cs View File

@@ -241,5 +241,9 @@ namespace Discord.Rest
/// <inheritdoc/>
public Task RemoveUserAsync(IGuildUser user, RequestOptions options = null)
=> Discord.ApiClient.RemoveThreadMemberAsync(Id, user.Id, options);

/// <inheritdoc/> <exception cref="NotSupportedException">This method is not supported in threads.</exception>
public override Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> throw new NotSupportedException("This method is not supported in threads.");
}
}

+ 4
- 0
src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs View File

@@ -234,6 +234,10 @@ namespace Discord.Rest
return base.TriggerTypingAsync(options);
}

/// <inheritdoc/> <exception cref="NotSupportedException">Threads are not supported in voice channels</exception>
public override Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> throw new NotSupportedException("Threads are not supported in voice channels");

#endregion




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

@@ -68,10 +68,10 @@ namespace Discord.Rest
return await client.ApiClient.ModifyThreadAsync(channel.Id, apiArgs, options).ConfigureAwait(false);
}

public static async Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(IGuild guild, BaseDiscordClient client, RequestOptions options)
public static async Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(IGuild guild, ulong channelId, BaseDiscordClient client, RequestOptions options)
{
var result = await client.ApiClient.GetActiveThreadsAsync(guild.Id, options).ConfigureAwait(false);
return result.Threads.Select(x => RestThreadChannel.Create(client, guild, x)).ToImmutableArray();
return result.Threads.Where(x => x.CategoryId == channelId).Select(x => RestThreadChannel.Create(client, guild, x)).ToImmutableArray();
}

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


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

@@ -135,9 +135,9 @@ namespace Discord.WebSocket
MessageComponent components = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None, ForumTag[] tags = null)
=> ThreadHelper.CreatePostAsync(this, Discord, title, attachments, archiveDuration, slowmode, text, embed, options, allowedMentions, components, stickers, embeds, flags, tags?.Select(tag => tag.Id).ToArray());

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

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


+ 9
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs View File

@@ -130,7 +130,12 @@ namespace Discord.WebSocket

return thread;
}
#endregion

/// <inheritdoc cref="ITextChannel.GetActiveThreadsAsync(RequestOptions)"/>
public virtual Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> ThreadHelper.GetActiveThreadsAsync(Guild, Id, Discord, options);

#endregion

#region Messages
/// <inheritdoc />
@@ -378,6 +383,9 @@ namespace Discord.WebSocket
/// <inheritdoc />
async Task<IThreadChannel> ITextChannel.CreateThreadAsync(string name, ThreadType type, ThreadArchiveDuration autoArchiveDuration, IMessage message, bool? invitable, int? slowmode, RequestOptions options)
=> await CreateThreadAsync(name, type, autoArchiveDuration, message, invitable, slowmode, options);
/// <inheritdoc />
async Task<IReadOnlyCollection<IThreadChannel>> ITextChannel.GetActiveThreadsAsync(RequestOptions options)
=> await GetActiveThreadsAsync(options);
#endregion

#region IGuildChannel


+ 4
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketThreadChannel.cs View File

@@ -374,6 +374,10 @@ namespace Discord.WebSocket
public override Task SyncPermissionsAsync(RequestOptions options = null)
=> throw new NotSupportedException("This method is not supported in threads.");

/// <inheritdoc/> <exception cref="NotSupportedException">This method is not supported in threads.</exception>
public override Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> throw new NotSupportedException("This method is not supported in threads.");

string IChannel.Name => Name;
}
}

+ 4
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs View File

@@ -296,6 +296,10 @@ namespace Discord.WebSocket
return base.TriggerTypingAsync(options);
}

/// <inheritdoc/> <exception cref="NotSupportedException">Threads are not supported in voice channels</exception>
public override Task<IReadOnlyCollection<RestThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null)
=> throw new NotSupportedException("Threads are not supported in voice channels");

#endregion

private string DebuggerDisplay => $"{Name} ({Id}, Voice)";


+ 2
- 1
test/Discord.Net.Tests.Unit/MockedEntities/MockedTextChannel.cs View File

@@ -214,11 +214,12 @@ namespace Discord
{
throw new NotImplementedException();
}
public Task<IUserMessage> SendFileAsync(FileAttachment attachment, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) => throw new NotImplementedException();
public Task<IUserMessage> SendFilesAsync(IEnumerable<FileAttachment> attachments, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageReference messageReference = null, MessageComponent component = null, ISticker[] stickers = null, Embed[] embeds = null, MessageFlags flags = MessageFlags.None) => throw new NotImplementedException();
public Task<IThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null, MessageFlags flags = MessageFlags.None) => throw new NotImplementedException();
public Task<IInviteMetadata> CreateInviteToApplicationAsync(DefaultApplications application, int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) => throw new NotImplementedException();
public Task<IThreadChannel> CreateThreadAsync(string name, ThreadType type = ThreadType.PublicThread, ThreadArchiveDuration autoArchiveDuration = ThreadArchiveDuration.OneDay, IMessage message = null, bool? invitable = null, int? slowmode = null, RequestOptions options = null) => throw new NotImplementedException();
public Task<IReadOnlyCollection<IThreadChannel>> GetActiveThreadsAsync(RequestOptions options = null) => throw new NotImplementedException();
}
}

Loading…
Cancel
Save