From 5f6e51f6fbee72ff233e4bce7fb52ca30b35c43b Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Mon, 28 Aug 2023 21:31:51 +0300 Subject: [PATCH] Show threads in GUI at the bottom of the list, in specialized groups Related to #1119 --- .../Commands/Base/ExportCommandBase.cs | 4 +-- .../Commands/GetChannelsCommand.cs | 2 +- .../Commands/GetDirectChannelsCommand.cs | 2 +- .../Discord/Data/Channel.cs | 5 +++- .../Exporting/ExportRequest.cs | 4 ++- .../Exporting/JsonMessageWriter.cs | 2 +- .../Exporting/PlainTextMessageWriter.cs | 2 +- .../Exporting/PreambleTemplate.cshtml | 2 +- .../Converters/ChannelToGroupKeyConverter.cs | 30 +++++++++++++++++++ .../Views/Components/DashboardView.xaml | 7 +++-- .../Views/Dialogs/ExportSetupView.xaml | 2 +- 11 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index 1019f86..bbd6961 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -184,7 +184,7 @@ public abstract class ExportCommandBase : DiscordCommandBase try { await progressContext.StartTaskAsync( - $"{channel.Category} / {channel.Name}", + $"{channel.ParentNameWithFallback} / {channel.Name}", async progress => { var guild = await Discord.GetGuildAsync( @@ -246,7 +246,7 @@ public abstract class ExportCommandBase : DiscordCommandBase foreach (var (channel, error) in errorsByChannel) { - await console.Error.WriteAsync($"{channel.Category} / {channel.Name}: "); + await console.Error.WriteAsync($"{channel.ParentNameWithFallback} / {channel.Name}: "); using (console.WithForegroundColor(ConsoleColor.Red)) await console.Error.WriteLineAsync(error); diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 8fa47f3..917efdb 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -77,7 +77,7 @@ public class GetChannelsCommand : DiscordCommandBase // Channel category / name using (console.WithForegroundColor(ConsoleColor.White)) - await console.Output.WriteLineAsync($"{channel.Category} / {channel.Name}"); + await console.Output.WriteLineAsync($"{channel.ParentNameWithFallback} / {channel.Name}"); var channelThreads = threads.Where(t => t.Parent?.Id == channel.Id).ToArray(); var channelThreadIdMaxLength = channelThreads diff --git a/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs index 74123de..8a118b7 100644 --- a/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs @@ -44,7 +44,7 @@ public class GetDirectChannelsCommand : DiscordCommandBase // Channel category / name using (console.WithForegroundColor(ConsoleColor.White)) - await console.Output.WriteLineAsync($"{channel.Category} / {channel.Name}"); + await console.Output.WriteLineAsync($"{channel.ParentNameWithFallback} / {channel.Name}"); } } } diff --git a/DiscordChatExporter.Core/Discord/Data/Channel.cs b/DiscordChatExporter.Core/Discord/Data/Channel.cs index 981841d..431f675 100644 --- a/DiscordChatExporter.Core/Discord/Data/Channel.cs +++ b/DiscordChatExporter.Core/Discord/Data/Channel.cs @@ -24,7 +24,7 @@ public partial record Channel( // channels without a parent (i.e. mostly DM channels) or channels // with an inaccessible parent (i.e. inside private categories) had // a fallback category created for them. - public string Category => + public string ParentNameWithFallback => Parent?.Name ?? Kind switch { @@ -41,6 +41,9 @@ public partial record Channel( // Only needed for WPF data binding. Don't use anywhere else. public bool IsVoice => Kind.IsVoice(); + + // Only needed for WPF data binding. Don't use anywhere else. + public bool IsThread => Kind.IsThread(); } public partial record Channel diff --git a/DiscordChatExporter.Core/Exporting/ExportRequest.cs b/DiscordChatExporter.Core/Exporting/ExportRequest.cs index deb122a..26c5a54 100644 --- a/DiscordChatExporter.Core/Exporting/ExportRequest.cs +++ b/DiscordChatExporter.Core/Exporting/ExportRequest.cs @@ -92,7 +92,9 @@ public partial class ExportRequest var buffer = new StringBuilder(); // Guild and channel names - buffer.Append($"{guild.Name} - {channel.Category} - {channel.Name} [{channel.Id}]"); + buffer.Append( + $"{guild.Name} - {channel.ParentNameWithFallback} - {channel.Name} [{channel.Id}]" + ); // Date range if (after is not null || before is not null) diff --git a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs index 435997f..b230336 100644 --- a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs @@ -273,7 +273,7 @@ internal class JsonMessageWriter : MessageWriter _writer.WriteString("id", Context.Request.Channel.Id.ToString()); _writer.WriteString("type", Context.Request.Channel.Kind.ToString()); _writer.WriteString("categoryId", Context.Request.Channel.Parent?.Id.ToString()); - _writer.WriteString("category", Context.Request.Channel.Category); + _writer.WriteString("category", Context.Request.Channel.ParentNameWithFallback); _writer.WriteString("name", Context.Request.Channel.Name); _writer.WriteString("topic", Context.Request.Channel.Topic); diff --git a/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs b/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs index 04ea408..77f7d32 100644 --- a/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs @@ -201,7 +201,7 @@ internal class PlainTextMessageWriter : MessageWriter await _writer.WriteLineAsync(new string('=', 62)); await _writer.WriteLineAsync($"Guild: {Context.Request.Guild.Name}"); await _writer.WriteLineAsync( - $"Channel: {Context.Request.Channel.Category} / {Context.Request.Channel.Name}" + $"Channel: {Context.Request.Channel.ParentNameWithFallback} / {Context.Request.Channel.Name}" ); if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic)) diff --git a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml index b7b2353..b1742f7 100644 --- a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml @@ -1004,7 +1004,7 @@
@Context.Request.Guild.Name
-
@Context.Request.Channel.Category / @Context.Request.Channel.Name
+
@Context.Request.Channel.ParentNameWithFallback / @Context.Request.Channel.Name
@if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic)) { diff --git a/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs b/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs new file mode 100644 index 0000000..237cc18 --- /dev/null +++ b/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs @@ -0,0 +1,30 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using DiscordChatExporter.Core.Discord.Data; + +namespace DiscordChatExporter.Gui.Converters; + +[ValueConversion(typeof(Channel), typeof(string))] +public class ChannelToGroupKeyConverter : IValueConverter +{ + public static ChannelToGroupKeyConverter Instance { get; } = new(); + + public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) => + value switch + { + Channel channel when channel.Kind.IsThread() + => $"Threads in #{channel.ParentNameWithFallback}", + + Channel channel => channel.ParentNameWithFallback, + + _ => null + }; + + public object ConvertBack( + object value, + Type targetType, + object parameter, + CultureInfo culture + ) => throw new NotSupportedException(); +} diff --git a/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml b/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml index 2175d8a..253f6c1 100644 --- a/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml +++ b/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml @@ -19,19 +19,20 @@ Loaded="{s:Action OnViewLoaded}" mc:Ignorable="d"> - + - + - + + diff --git a/DiscordChatExporter.Gui/Views/Dialogs/ExportSetupView.xaml b/DiscordChatExporter.Gui/Views/Dialogs/ExportSetupView.xaml index 38241f6..7d9c4d8 100644 --- a/DiscordChatExporter.Gui/Views/Dialogs/ExportSetupView.xaml +++ b/DiscordChatExporter.Gui/Views/Dialogs/ExportSetupView.xaml @@ -60,7 +60,7 @@ FontWeight="Light" TextTrimming="CharacterEllipsis" Visibility="{Binding IsSingleChannel, Converter={x:Static s:BoolToVisibilityConverter.Instance}}"> - +