Optimize thread inclusion UX across GUI and CLI

Related to #1119
This commit is contained in:
Tyrrrz
2023-08-28 22:08:51 +03:00
parent d430f77ae1
commit 3740d64601
9 changed files with 49 additions and 79 deletions

View File

@@ -29,15 +29,11 @@ public class ExportAllCommand : ExportCommandBase
[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;
private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;
private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);
[CommandOption(
"data-package",
Description = "Path to the personal data package (ZIP file) requested from Discord. "
@@ -74,12 +70,12 @@ public class ExportAllCommand : ExportCommandBase
}
// Threads
if (IncludeThreads)
if (ThreadInclusion != ThreadInclusion.None)
{
await foreach (
var thread in Discord.GetGuildThreadsAsync(
guild.Id,
IncludeArchivedThreads,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)
@@ -136,9 +132,9 @@ public class ExportAllCommand : ExportCommandBase
channels.RemoveAll(c => c.Kind.IsGuild());
if (!IncludeVoiceChannels)
channels.RemoveAll(c => c.Kind.IsVoice());
if (!IncludeThreads)
if (ThreadInclusion == ThreadInclusion.None)
channels.RemoveAll(c => c.Kind.IsThread());
if (!IncludeArchivedThreads)
if (ThreadInclusion != ThreadInclusion.All)
channels.RemoveAll(c => c.Kind.IsThread() && c.IsArchived);
await ExportAsync(console, channels);

View File

@@ -21,15 +21,11 @@ public class ExportGuildCommand : ExportCommandBase
[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;
private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;
private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);
public override async ValueTask ExecuteAsync(IConsole console)
{
await base.ExecuteAsync(console);
@@ -52,12 +48,12 @@ public class ExportGuildCommand : ExportCommandBase
}
// Threads
if (IncludeThreads)
if (ThreadInclusion != ThreadInclusion.None)
{
await foreach (
var thread in Discord.GetGuildThreadsAsync(
GuildId,
IncludeArchivedThreads,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)

View File

@@ -23,15 +23,11 @@ public class GetChannelsCommand : DiscordCommandBase
[CommandOption(
"include-threads",
Description = "Specifies which types of threads should be included.",
Description = "Which types of threads should be included.",
Converter = typeof(ThreadInclusionBindingConverter)
)]
public ThreadInclusion ThreadInclusion { get; init; } = ThreadInclusion.None;
private bool IncludeThreads => ThreadInclusion != ThreadInclusion.None;
private bool IncludeArchivedThreads => ThreadInclusion.HasFlag(ThreadInclusion.Archived);
public override async ValueTask ExecuteAsync(IConsole console)
{
await base.ExecuteAsync(console);
@@ -50,17 +46,18 @@ public class GetChannelsCommand : DiscordCommandBase
.OrderDescending()
.FirstOrDefault();
var threads = IncludeThreads
? (
await Discord.GetGuildThreadsAsync(
GuildId,
IncludeArchivedThreads,
cancellationToken
var threads =
ThreadInclusion != ThreadInclusion.None
? (
await Discord.GetGuildThreadsAsync(
GuildId,
ThreadInclusion == ThreadInclusion.All,
cancellationToken
)
)
)
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<Channel>();
.OrderBy(c => c.Name)
.ToArray()
: Array.Empty<Channel>();
foreach (var channel in channels)
{

View File

@@ -1,12 +1,8 @@
using System;
namespace DiscordChatExporter.Cli.Commands.Shared;
namespace DiscordChatExporter.Cli.Commands.Shared;
[Flags]
public enum ThreadInclusion
{
None = 0,
Active = 1,
Archived = 2,
All = Active | Archived
None,
Active,
All
}