From 5abe74894c0c10fc996f7138b629148cd5e9dafe Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:36:29 +0300 Subject: [PATCH] Remove `Channel.ParentNameWithFallback` --- .../Commands/Base/ExportCommandBase.cs | 9 ++-- .../Commands/ExportAllCommand.cs | 14 ++--- .../Commands/ExportGuildCommand.cs | 4 +- .../Commands/GetChannelsCommand.cs | 10 ++-- .../Commands/GetDirectChannelsCommand.cs | 7 +-- .../Discord/Data/Channel.cs | 51 ++++++++++--------- .../Discord/Data/ChannelKind.cs | 17 ------- .../Discord/Data/Guild.cs | 7 ++- .../Discord/Data/Message.cs | 8 ++- .../Discord/Data/MessageKind.cs | 5 -- .../Discord/DiscordClient.cs | 5 +- .../Exporting/CsvMessageWriter.cs | 2 +- .../Exporting/ExportRequest.cs | 30 ++++++++--- .../Exporting/HtmlMarkdownVisitor.cs | 2 +- .../Exporting/HtmlMessageWriter.cs | 10 ++-- .../Exporting/JsonMessageWriter.cs | 7 ++- .../Exporting/MessageGroupTemplate.cshtml | 4 +- .../Exporting/PlainTextMarkdownVisitor.cs | 2 +- .../Exporting/PlainTextMessageWriter.cs | 6 +-- .../Exporting/PreambleTemplate.cshtml | 2 +- .../Converters/ChannelToGroupKeyConverter.cs | 6 +-- .../Components/DashboardViewModel.cs | 4 +- .../Views/Components/DashboardView.xaml | 4 +- .../Views/Dialogs/ExportSetupView.xaml | 6 ++- 24 files changed, 112 insertions(+), 110 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs index 79c5c67..5ec0a53 100644 --- a/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/ExportCommandBase.cs @@ -200,7 +200,7 @@ public abstract class ExportCommandBase : DiscordCommandBase try { await progressContext.StartTaskAsync( - $"{channel.ParentNameWithFallback} / {channel.Name}", + channel.GetHierarchicalName(), async progress => { var guild = await Discord.GetGuildAsync( @@ -263,10 +263,7 @@ public abstract class ExportCommandBase : DiscordCommandBase foreach (var (channel, error) in errorsByChannel) { - await console.Error.WriteAsync( - $"{channel.ParentNameWithFallback} / {channel.Name}: " - ); - + await console.Error.WriteAsync($"{channel.GetHierarchicalName()}: "); using (console.WithForegroundColor(ConsoleColor.Red)) await console.Error.WriteLineAsync(error); } @@ -294,7 +291,7 @@ public abstract class ExportCommandBase : DiscordCommandBase var channel = await Discord.GetChannelAsync(channelId, cancellationToken); // Unwrap categories - if (channel.Kind == ChannelKind.GuildCategory) + if (channel.IsCategory) { var guildChannels = channelsByGuild.GetValueOrDefault(channel.GuildId) diff --git a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs index 5dd4d30..416a69f 100644 --- a/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportAllCommand.cs @@ -60,10 +60,10 @@ public class ExportAllCommand : ExportCommandBase var channel in Discord.GetGuildChannelsAsync(guild.Id, cancellationToken) ) { - if (channel.Kind == ChannelKind.GuildCategory) + if (channel.IsCategory) continue; - if (!IncludeVoiceChannels && channel.Kind.IsVoice()) + if (!IncludeVoiceChannels && channel.IsVoice) continue; channels.Add(channel); @@ -129,15 +129,15 @@ public class ExportAllCommand : ExportCommandBase // Filter out unwanted channels if (!IncludeDirectChannels) - channels.RemoveAll(c => c.Kind.IsDirect()); + channels.RemoveAll(c => c.IsDirect); if (!IncludeGuildChannels) - channels.RemoveAll(c => c.Kind.IsGuild()); + channels.RemoveAll(c => c.IsGuild); if (!IncludeVoiceChannels) - channels.RemoveAll(c => c.Kind.IsVoice()); + channels.RemoveAll(c => c.IsVoice); if (ThreadInclusionMode == ThreadInclusionMode.None) - channels.RemoveAll(c => c.Kind.IsThread()); + channels.RemoveAll(c => c.IsThread); if (ThreadInclusionMode != ThreadInclusionMode.All) - channels.RemoveAll(c => c.Kind.IsThread() && c.IsArchived); + channels.RemoveAll(c => c is { IsThread: true, IsArchived: true }); await ExportAsync(console, channels); } diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index afc955f..c49079a 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -38,10 +38,10 @@ public class ExportGuildCommand : ExportCommandBase // Regular channels await foreach (var channel in Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) { - if (channel.Kind == ChannelKind.GuildCategory) + if (channel.IsCategory) continue; - if (!IncludeVoiceChannels && channel.Kind.IsVoice()) + if (!IncludeVoiceChannels && channel.IsVoice) continue; channels.Add(channel); diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 20b8bba..6dca94f 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -35,8 +35,8 @@ public class GetChannelsCommand : DiscordCommandBase var cancellationToken = console.RegisterCancellationHandler(); var channels = (await Discord.GetGuildChannelsAsync(GuildId, cancellationToken)) - .Where(c => c.Kind != ChannelKind.GuildCategory) - .Where(c => IncludeVoiceChannels || !c.Kind.IsVoice()) + .Where(c => !c.IsCategory) + .Where(c => IncludeVoiceChannels || !c.IsVoice) .OrderBy(c => c.Parent?.Position) .ThenBy(c => c.Name) .ToArray(); @@ -72,11 +72,9 @@ public class GetChannelsCommand : DiscordCommandBase using (console.WithForegroundColor(ConsoleColor.DarkGray)) await console.Output.WriteAsync(" | "); - // Channel category / name + // Channel name using (console.WithForegroundColor(ConsoleColor.White)) - await console.Output.WriteLineAsync( - $"{channel.ParentNameWithFallback} / {channel.Name}" - ); + await console.Output.WriteLineAsync(channel.GetHierarchicalName()); 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 4ceb1bd..daedf09 100644 --- a/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetDirectChannelsCommand.cs @@ -21,7 +21,6 @@ public class GetDirectChannelsCommand : DiscordCommandBase var channels = ( await Discord.GetGuildChannelsAsync(Guild.DirectMessages.Id, cancellationToken) ) - .Where(c => c.Kind != ChannelKind.GuildCategory) .OrderByDescending(c => c.LastMessageId) .ThenBy(c => c.Name) .ToArray(); @@ -42,11 +41,9 @@ public class GetDirectChannelsCommand : DiscordCommandBase using (console.WithForegroundColor(ConsoleColor.DarkGray)) await console.Output.WriteAsync(" | "); - // Channel category / name + // Channel name using (console.WithForegroundColor(ConsoleColor.White)) - await console.Output.WriteLineAsync( - $"{channel.ParentNameWithFallback} / {channel.Name}" - ); + await console.Output.WriteLineAsync(channel.GetHierarchicalName()); } } } diff --git a/DiscordChatExporter.Core/Discord/Data/Channel.cs b/DiscordChatExporter.Core/Discord/Data/Channel.cs index f411c40..b11b6f4 100644 --- a/DiscordChatExporter.Core/Discord/Data/Channel.cs +++ b/DiscordChatExporter.Core/Discord/Data/Channel.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System.Collections.Generic; +using System.Linq; using System.Text.Json; using DiscordChatExporter.Core.Discord.Data.Common; using DiscordChatExporter.Core.Utils.Extensions; @@ -20,32 +21,36 @@ public partial record Channel( Snowflake? LastMessageId ) : IHasId { - // Used for visual backwards-compatibility with old exports, where - // 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 ParentNameWithFallback => - Parent?.Name - ?? Kind switch - { - ChannelKind.GuildCategory => "Category", - ChannelKind.GuildTextChat => "Text", - ChannelKind.DirectTextChat => "Private", - ChannelKind.DirectGroupTextChat => "Group", - ChannelKind.GuildPrivateThread => "Private Thread", - ChannelKind.GuildPublicThread => "Public Thread", - ChannelKind.GuildNews => "News", - ChannelKind.GuildNewsThread => "News Thread", - _ => "Default" - }; + public bool IsDirect => Kind is ChannelKind.DirectTextChat or ChannelKind.DirectGroupTextChat; + + public bool IsGuild => !IsDirect; + + public bool IsCategory => Kind == ChannelKind.GuildCategory; + + public bool IsVoice => Kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice; + + public bool IsThread => + Kind + is ChannelKind.GuildNewsThread + or ChannelKind.GuildPublicThread + or ChannelKind.GuildPrivateThread; public bool IsEmpty => LastMessageId is null; - // Only needed for WPF data binding. Don't use anywhere else. - public bool IsVoice => Kind.IsVoice(); + public IEnumerable GetParents() + { + var current = Parent; + while (current is not null) + { + yield return current; + current = current.Parent; + } + } + + public Channel? TryGetRootParent() => GetParents().LastOrDefault(); - // Only needed for WPF data binding. Don't use anywhere else. - public bool IsThread => Kind.IsThread(); + public string GetHierarchicalName() => + string.Join(" / ", GetParents().Reverse().Select(c => c.Name).Append(Name)); public bool MayHaveMessagesAfter(Snowflake messageId) => !IsEmpty && messageId < LastMessageId; diff --git a/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs b/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs index 9da0c45..6e36b51 100644 --- a/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs +++ b/DiscordChatExporter.Core/Discord/Data/ChannelKind.cs @@ -16,20 +16,3 @@ public enum ChannelKind GuildDirectory = 14, GuildForum = 15 } - -public static class ChannelKindExtensions -{ - public static bool IsDirect(this ChannelKind kind) => - kind is ChannelKind.DirectTextChat or ChannelKind.DirectGroupTextChat; - - public static bool IsGuild(this ChannelKind kind) => !kind.IsDirect(); - - public static bool IsVoice(this ChannelKind kind) => - kind is ChannelKind.GuildVoiceChat or ChannelKind.GuildStageVoice; - - public static bool IsThread(this ChannelKind kind) => - kind - is ChannelKind.GuildNewsThread - or ChannelKind.GuildPublicThread - or ChannelKind.GuildPrivateThread; -} diff --git a/DiscordChatExporter.Core/Discord/Data/Guild.cs b/DiscordChatExporter.Core/Discord/Data/Guild.cs index 0caa1e6..71a1236 100644 --- a/DiscordChatExporter.Core/Discord/Data/Guild.cs +++ b/DiscordChatExporter.Core/Discord/Data/Guild.cs @@ -6,7 +6,12 @@ using JsonExtensions.Reading; namespace DiscordChatExporter.Core.Discord.Data; // https://discord.com/developers/docs/resources/guild#guild-object -public record Guild(Snowflake Id, string Name, string IconUrl) : IHasId +public partial record Guild(Snowflake Id, string Name, string IconUrl) : IHasId +{ + public bool IsDirect => Id == DirectMessages.Id; +} + +public partial record Guild { // Direct messages are encapsulated within a special pseudo-guild for consistency public static Guild DirectMessages { get; } = diff --git a/DiscordChatExporter.Core/Discord/Data/Message.cs b/DiscordChatExporter.Core/Discord/Data/Message.cs index 4e2506e..5a97116 100644 --- a/DiscordChatExporter.Core/Discord/Data/Message.cs +++ b/DiscordChatExporter.Core/Discord/Data/Message.cs @@ -30,7 +30,13 @@ public partial record Message( Interaction? Interaction ) : IHasId { - public bool IsReplyLike => Kind == MessageKind.Reply || Interaction is not null; + public bool IsSystemNotification => + Kind is >= MessageKind.RecipientAdd and <= MessageKind.ThreadCreated; + + public bool IsReply => Kind == MessageKind.Reply; + + // App interactions are rendered as replies in the Discord client, but they are not actually replies + public bool IsReplyLike => IsReply || Interaction is not null; public IEnumerable GetReferencedUsers() { diff --git a/DiscordChatExporter.Core/Discord/Data/MessageKind.cs b/DiscordChatExporter.Core/Discord/Data/MessageKind.cs index 8956f81..411238b 100644 --- a/DiscordChatExporter.Core/Discord/Data/MessageKind.cs +++ b/DiscordChatExporter.Core/Discord/Data/MessageKind.cs @@ -14,8 +14,3 @@ public enum MessageKind ThreadCreated = 18, Reply = 19 } - -public static class MessageKindExtensions -{ - public static bool IsSystemNotification(this MessageKind kind) => (int)kind is >= 1 and <= 18; -} diff --git a/DiscordChatExporter.Core/Discord/DiscordClient.cs b/DiscordChatExporter.Core/Discord/DiscordClient.cs index 7fdc7d5..9e94369 100644 --- a/DiscordChatExporter.Core/Discord/DiscordClient.cs +++ b/DiscordChatExporter.Core/Discord/DiscordClient.cs @@ -286,11 +286,12 @@ public class DiscordClient yield break; var tokenKind = _resolvedTokenKind ??= await GetTokenKindAsync(cancellationToken); + var channels = (await GetGuildChannelsAsync(guildId, cancellationToken)) // Categories cannot have threads - .Where(c => c.Kind != ChannelKind.GuildCategory) + .Where(c => !c.IsCategory) // Voice channels cannot have threads - .Where(c => !c.Kind.IsVoice()) + .Where(c => !c.IsVoice) // Empty channels cannot have threads .Where(c => !c.IsEmpty) // If the 'before' boundary is specified, skip channels that don't have messages diff --git a/DiscordChatExporter.Core/Exporting/CsvMessageWriter.cs b/DiscordChatExporter.Core/Exporting/CsvMessageWriter.cs index b1f60a3..704ad9c 100644 --- a/DiscordChatExporter.Core/Exporting/CsvMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/CsvMessageWriter.cs @@ -92,7 +92,7 @@ internal partial class CsvMessageWriter : MessageWriter await _writer.WriteAsync(','); // Message content - if (message.Kind.IsSystemNotification()) + if (message.IsSystemNotification) { await _writer.WriteAsync(CsvEncode(message.GetFallbackContent())); } diff --git a/DiscordChatExporter.Core/Exporting/ExportRequest.cs b/DiscordChatExporter.Core/Exporting/ExportRequest.cs index 62e6e55..8ddab72 100644 --- a/DiscordChatExporter.Core/Exporting/ExportRequest.cs +++ b/DiscordChatExporter.Core/Exporting/ExportRequest.cs @@ -99,10 +99,21 @@ public partial class ExportRequest { var buffer = new StringBuilder(); - // Guild and channel names - buffer.Append( - $"{guild.Name} - {channel.ParentNameWithFallback} - {channel.Name} [{channel.Id}]" - ); + // Guild name + buffer.Append(guild.Name); + + // Parent name + if (channel.Parent is not null) + buffer.Append(" - ").Append(channel.Parent.Name); + + // Channel name and ID + buffer + .Append(" - ") + .Append(channel.Name) + .Append(' ') + .Append('[') + .Append(channel.Id) + .Append(']'); // Date range if (after is not null || before is not null) @@ -142,9 +153,8 @@ public partial class ExportRequest Channel channel, Snowflake? after, Snowflake? before - ) - { - return Regex.Replace( + ) => + Regex.Replace( path, "%.", m => @@ -153,14 +163,18 @@ public partial class ExportRequest { "%g" => guild.Id.ToString(), "%G" => guild.Name, + "%t" => channel.Parent?.Id.ToString() ?? "", "%T" => channel.Parent?.Name ?? "", + "%c" => channel.Id.ToString(), "%C" => channel.Name, + "%p" => channel.Position?.ToString(CultureInfo.InvariantCulture) ?? "0", "%P" => channel.Parent?.Position?.ToString(CultureInfo.InvariantCulture) ?? "0", + "%a" => after?.ToDate().ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) ?? "", @@ -172,12 +186,12 @@ public partial class ExportRequest "yyyy-MM-dd", CultureInfo.InvariantCulture ), + "%%" => "%", _ => m.Value } ) ); - } private static string GetOutputBaseFilePath( Guild guild, diff --git a/DiscordChatExporter.Core/Exporting/HtmlMarkdownVisitor.cs b/DiscordChatExporter.Core/Exporting/HtmlMarkdownVisitor.cs index ee9e724..9d294e8 100644 --- a/DiscordChatExporter.Core/Exporting/HtmlMarkdownVisitor.cs +++ b/DiscordChatExporter.Core/Exporting/HtmlMarkdownVisitor.cs @@ -280,7 +280,7 @@ internal partial class HtmlMarkdownVisitor : MarkdownVisitor else if (mention.Kind == MentionKind.Channel) { var channel = mention.TargetId?.Pipe(_context.TryGetChannel); - var symbol = channel?.Kind.IsVoice() == true ? "🔊" : "#"; + var symbol = channel?.IsVoice == true ? "🔊" : "#"; var name = channel?.Name ?? "deleted-channel"; _buffer.Append( diff --git a/DiscordChatExporter.Core/Exporting/HtmlMessageWriter.cs b/DiscordChatExporter.Core/Exporting/HtmlMessageWriter.cs index 7c79a6a..e741c2f 100644 --- a/DiscordChatExporter.Core/Exporting/HtmlMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/HtmlMessageWriter.cs @@ -30,22 +30,22 @@ internal class HtmlMessageWriter : MessageWriter if (_messageGroup.LastOrDefault() is not { } lastMessage) return true; - // Reply messages cannot join existing groups because they need to appear first - if (message.Kind == MessageKind.Reply) + // Reply-like messages cannot join existing groups because they need to appear first + if (message.IsReplyLike) return false; // Grouping for system notifications - if (message.Kind.IsSystemNotification()) + if (message.IsSystemNotification) { // Can only be grouped with other system notifications - if (!lastMessage.Kind.IsSystemNotification()) + if (!lastMessage.IsSystemNotification) return false; } // Grouping for normal messages else { // Can only be grouped with other normal messages - if (lastMessage.Kind.IsSystemNotification()) + if (lastMessage.IsSystemNotification) return false; // Messages must be within 7 minutes of each other diff --git a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs index e8c59bc..0c59e3e 100644 --- a/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/JsonMessageWriter.cs @@ -273,8 +273,11 @@ internal class JsonMessageWriter : MessageWriter _writer.WriteStartObject("channel"); _writer.WriteString("id", Context.Request.Channel.Id.ToString()); _writer.WriteString("type", Context.Request.Channel.Kind.ToString()); + + // Original schema did not account for threads, so 'category' actually refers to the parent channel _writer.WriteString("categoryId", Context.Request.Channel.Parent?.Id.ToString()); - _writer.WriteString("category", Context.Request.Channel.ParentNameWithFallback); + _writer.WriteString("category", Context.Request.Channel.Parent?.Name); + _writer.WriteString("name", Context.Request.Channel.Name); _writer.WriteString("topic", Context.Request.Channel.Topic); @@ -329,7 +332,7 @@ internal class JsonMessageWriter : MessageWriter _writer.WriteBoolean("isPinned", message.IsPinned); // Content - if (message.Kind.IsSystemNotification()) + if (message.IsSystemNotification) { _writer.WriteString("content", message.GetFallbackContent()); } diff --git a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml index 4a9a125..01e98f7 100644 --- a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml @@ -47,7 +47,7 @@
@* System notification *@ - @if (message.Kind.IsSystemNotification()) + @if (message.IsSystemNotification) {
@@ -329,7 +329,7 @@
-
@(invite.Channel?.Kind.IsDirect() == true ? "Invite to join a group DM" : "Invite to join a server")
+
@(invite.Channel?.IsDirect == true ? "Invite to join a group DM" : "Invite to join a server")
Guild icon diff --git a/DiscordChatExporter.Core/Exporting/PlainTextMarkdownVisitor.cs b/DiscordChatExporter.Core/Exporting/PlainTextMarkdownVisitor.cs index eafd06e..84f4135 100644 --- a/DiscordChatExporter.Core/Exporting/PlainTextMarkdownVisitor.cs +++ b/DiscordChatExporter.Core/Exporting/PlainTextMarkdownVisitor.cs @@ -72,7 +72,7 @@ internal partial class PlainTextMarkdownVisitor : MarkdownVisitor _buffer.Append($"#{name}"); // Voice channel marker - if (channel?.Kind.IsVoice() == true) + if (channel?.IsVoice == true) _buffer.Append(" [voice]"); } else if (mention.Kind == MentionKind.Role) diff --git a/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs b/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs index 77f7d32..bdb3f15 100644 --- a/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/PlainTextMessageWriter.cs @@ -200,9 +200,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.ParentNameWithFallback} / {Context.Request.Channel.Name}" - ); + await _writer.WriteLineAsync($"Channel: {Context.Request.Channel.GetHierarchicalName()}"); if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic)) { @@ -238,7 +236,7 @@ internal class PlainTextMessageWriter : MessageWriter await WriteMessageHeaderAsync(message); // Content - if (message.Kind.IsSystemNotification()) + if (message.IsSystemNotification) { await _writer.WriteLineAsync(message.GetFallbackContent()); } diff --git a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml index 0530589..a71fd83 100644 --- a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml @@ -1004,7 +1004,7 @@
@Context.Request.Guild.Name
-
@Context.Request.Channel.ParentNameWithFallback / @Context.Request.Channel.Name
+
@Context.Request.Channel.GetHierarchicalName()
@if (!string.IsNullOrWhiteSpace(Context.Request.Channel.Topic)) { diff --git a/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs b/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs index 237cc18..f959f9f 100644 --- a/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs +++ b/DiscordChatExporter.Gui/Converters/ChannelToGroupKeyConverter.cs @@ -13,10 +13,10 @@ public class ChannelToGroupKeyConverter : IValueConverter public object? Convert(object value, Type targetType, object parameter, CultureInfo culture) => value switch { - Channel channel when channel.Kind.IsThread() - => $"Threads in #{channel.ParentNameWithFallback}", + Channel { IsThread: true, Parent: not null } channel + => $"Threads in #{channel.Parent.Name}", - Channel channel => channel.ParentNameWithFallback, + Channel channel => channel.Parent?.Name ?? "???", _ => null }; diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index 2b99a3a..830b0b7 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -43,8 +43,6 @@ public class DashboardViewModel : PropertyChangedBase public Guild? SelectedGuild { get; set; } - public bool IsDirectMessageGuildSelected => SelectedGuild?.Id == Guild.DirectMessages.Id; - public IReadOnlyList? AvailableChannels { get; private set; } public IReadOnlyList? SelectedChannels { get; set; } @@ -164,7 +162,7 @@ public class DashboardViewModel : PropertyChangedBase // Regular channels await foreach (var channel in _discord.GetGuildChannelsAsync(SelectedGuild.Id)) { - if (channel.Kind == ChannelKind.GuildCategory) + if (channel.IsCategory) continue; channels.Add(channel); diff --git a/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml b/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml index 0e06b74..88e86b5 100644 --- a/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml +++ b/DiscordChatExporter.Gui/Views/Components/DashboardView.xaml @@ -313,10 +313,10 @@