From 049338009e35ab1b8a388fd0258c5a61ec978c5c Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 9 Feb 2023 18:44:24 +0200 Subject: [PATCH] Render server cross-posts properly Closes #633 --- .../Fixtures/ExportWrapperCollection.cs | 8 +++++ .../Specs/CsvContentSpecs.cs | 3 +- .../Specs/DateRangeSpecs.cs | 1 + .../Specs/FilterSpecs.cs | 1 + .../Specs/HtmlAttachmentSpecs.cs | 3 +- .../Specs/HtmlContentSpecs.cs | 21 +++++++++++- .../Specs/HtmlEmbedSpecs.cs | 3 +- .../Specs/HtmlGroupingSpecs.cs | 1 + .../Specs/HtmlMentionSpecs.cs | 3 +- .../Specs/HtmlReplySpecs.cs | 9 ++--- .../Specs/HtmlStickerSpecs.cs | 3 +- .../Specs/JsonAttachmentSpecs.cs | 3 +- .../Specs/JsonContentSpecs.cs | 3 +- .../Specs/JsonEmbedSpecs.cs | 3 +- .../Specs/JsonMentionSpecs.cs | 3 +- .../Specs/JsonStickerSpecs.cs | 3 +- .../Specs/PartitioningSpecs.cs | 1 + .../Specs/PlainTextContentSpecs.cs | 3 +- .../Specs/SelfContainedSpecs.cs | 1 + .../xunit.runner.json | 3 +- .../Exporting/MessageGroupTemplate.cshtml | 34 ++++++++++++------- .../Exporting/PreambleTemplate.cshtml | 26 +++++++------- 22 files changed, 96 insertions(+), 43 deletions(-) create mode 100644 DiscordChatExporter.Cli.Tests/Fixtures/ExportWrapperCollection.cs diff --git a/DiscordChatExporter.Cli.Tests/Fixtures/ExportWrapperCollection.cs b/DiscordChatExporter.Cli.Tests/Fixtures/ExportWrapperCollection.cs new file mode 100644 index 00000000..0a399896 --- /dev/null +++ b/DiscordChatExporter.Cli.Tests/Fixtures/ExportWrapperCollection.cs @@ -0,0 +1,8 @@ +using Xunit; + +namespace DiscordChatExporter.Cli.Tests.Fixtures; + +[CollectionDefinition(nameof(ExportWrapperCollection))] +public class ExportWrapperCollection : ICollectionFixture +{ +} \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/Specs/CsvContentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/CsvContentSpecs.cs index a7bfba41..8cbcfb0a 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/CsvContentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/CsvContentSpecs.cs @@ -6,7 +6,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class CsvContentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class CsvContentSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/DateRangeSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/DateRangeSpecs.cs index 661e1a60..82cce1b2 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/DateRangeSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/DateRangeSpecs.cs @@ -15,6 +15,7 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; +[Collection(nameof(ExportWrapperCollection))] public class DateRangeSpecs : IClassFixture { private readonly TempOutputFixture _tempOutput; diff --git a/DiscordChatExporter.Cli.Tests/Specs/FilterSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/FilterSpecs.cs index e6e23057..5e00f988 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/FilterSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/FilterSpecs.cs @@ -14,6 +14,7 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; +[Collection(nameof(ExportWrapperCollection))] public class FilterSpecs : IClassFixture { private readonly TempOutputFixture _tempOutput; diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlAttachmentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlAttachmentSpecs.cs index b6b00ba2..565bf705 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlAttachmentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlAttachmentSpecs.cs @@ -9,7 +9,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlAttachmentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlAttachmentSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlContentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlContentSpecs.cs index b0070fbf..df030eae 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlContentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlContentSpecs.cs @@ -3,12 +3,14 @@ using System.Threading.Tasks; using AngleSharp.Dom; using DiscordChatExporter.Cli.Tests.Fixtures; using DiscordChatExporter.Cli.Tests.TestData; +using DiscordChatExporter.Core.Discord; using FluentAssertions; using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlContentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlContentSpecs { private readonly ExportWrapperFixture _exportWrapper; @@ -46,4 +48,21 @@ public class HtmlContentSpecs : IClassFixture "Yeet" ); } + + [Fact] + public async Task Messages_cross_posted_from_other_guilds_are_rendered_with_the_server_tag() + { + // https://github.com/Tyrrrz/DiscordChatExporter/issues/633 + + // Act + var message = await _exportWrapper.GetMessageAsHtmlAsync( + ChannelIds.ReplyTestCases, + Snowflake.Parse("1072165330853576876") + ); + + // Assert + message.Text().Should().Contain("This is a test message from an announcement channel on another server"); + message.Text().Should().Contain("SERVER"); + message.QuerySelector(".chatlog__reply-link").Should().BeNull(); + } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlEmbedSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlEmbedSpecs.cs index e115d97d..9563b4c4 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlEmbedSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlEmbedSpecs.cs @@ -9,7 +9,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlEmbedSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlEmbedSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlGroupingSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlGroupingSpecs.cs index 7db20003..3109d5a3 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlGroupingSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlGroupingSpecs.cs @@ -13,6 +13,7 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; +[Collection(nameof(ExportWrapperCollection))] public class HtmlGroupingSpecs : IClassFixture { private readonly TempOutputFixture _tempOutput; diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlMentionSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlMentionSpecs.cs index d845da5d..8688e143 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlMentionSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlMentionSpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlMentionSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlMentionSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlReplySpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlReplySpecs.cs index effd9d9e..689136d6 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlReplySpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlReplySpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlReplySpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlReplySpecs { private readonly ExportWrapperFixture _exportWrapper; @@ -28,7 +29,7 @@ public class HtmlReplySpecs : IClassFixture // Assert message.Text().Should().Contain("reply to original"); - message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("original"); + message.QuerySelector(".chatlog__reply-link")?.Text().Should().Contain("original"); } [Fact] @@ -44,7 +45,7 @@ public class HtmlReplySpecs : IClassFixture // Assert message.Text().Should().Contain("reply to deleted"); - message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain( + message.QuerySelector(".chatlog__reply-link")?.Text().Should().Contain( "Original message was deleted or could not be loaded." ); } @@ -62,6 +63,6 @@ public class HtmlReplySpecs : IClassFixture // Assert message.Text().Should().Contain("reply to attachment"); - message.QuerySelector(".chatlog__reference-link")?.Text().Should().Contain("Click to see attachment"); + message.QuerySelector(".chatlog__reply-link")?.Text().Should().Contain("Click to see attachment"); } } \ No newline at end of file diff --git a/DiscordChatExporter.Cli.Tests/Specs/HtmlStickerSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/HtmlStickerSpecs.cs index 3a93d033..c2277061 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/HtmlStickerSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/HtmlStickerSpecs.cs @@ -7,7 +7,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class HtmlStickerSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class HtmlStickerSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/JsonAttachmentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/JsonAttachmentSpecs.cs index 4ed849a0..2b2696bd 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/JsonAttachmentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/JsonAttachmentSpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class JsonAttachmentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class JsonAttachmentSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/JsonContentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/JsonContentSpecs.cs index 42d981a0..c2885ee0 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/JsonContentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/JsonContentSpecs.cs @@ -7,7 +7,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class JsonContentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class JsonContentSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/JsonEmbedSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/JsonEmbedSpecs.cs index 41a2b353..311e7814 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/JsonEmbedSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/JsonEmbedSpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class JsonEmbedSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class JsonEmbedSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/JsonMentionSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/JsonMentionSpecs.cs index 00cff6ae..6e2912bd 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/JsonMentionSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/JsonMentionSpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class JsonMentionSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class JsonMentionSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/JsonStickerSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/JsonStickerSpecs.cs index ce2fc4a1..3e0c937f 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/JsonStickerSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/JsonStickerSpecs.cs @@ -8,7 +8,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class JsonStickerSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class JsonStickerSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/PartitioningSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/PartitioningSpecs.cs index a02190db..c8cd9c21 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/PartitioningSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/PartitioningSpecs.cs @@ -12,6 +12,7 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; +[Collection(nameof(ExportWrapperCollection))] public class PartitioningSpecs : IClassFixture { private readonly TempOutputFixture _tempOutput; diff --git a/DiscordChatExporter.Cli.Tests/Specs/PlainTextContentSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/PlainTextContentSpecs.cs index f64071d9..23e9b6b9 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/PlainTextContentSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/PlainTextContentSpecs.cs @@ -6,7 +6,8 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; -public class PlainTextContentSpecs : IClassFixture +[Collection(nameof(ExportWrapperCollection))] +public class PlainTextContentSpecs { private readonly ExportWrapperFixture _exportWrapper; diff --git a/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs b/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs index fd2aaf21..1661a912 100644 --- a/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs +++ b/DiscordChatExporter.Cli.Tests/Specs/SelfContainedSpecs.cs @@ -13,6 +13,7 @@ using Xunit; namespace DiscordChatExporter.Cli.Tests.Specs; +[Collection(nameof(ExportWrapperCollection))] public class SelfContainedSpecs : IClassFixture { private readonly TempOutputFixture _tempOutput; diff --git a/DiscordChatExporter.Cli.Tests/xunit.runner.json b/DiscordChatExporter.Cli.Tests/xunit.runner.json index 186540e3..51fa2b30 100644 --- a/DiscordChatExporter.Cli.Tests/xunit.runner.json +++ b/DiscordChatExporter.Cli.Tests/xunit.runner.json @@ -1,5 +1,6 @@ { "$schema": "https://xunit.net/schema/current/xunit.runner.schema.json", "methodDisplayOptions": "all", - "methodDisplay": "method" + "methodDisplay": "method", + "parallelizeTestCollections": true } \ No newline at end of file diff --git a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml index bda2a70d..47b44028 100644 --- a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml @@ -104,10 +104,10 @@
@if (isFirst) { - // Reference symbol - if (message.Reference is not null) + // Reply symbol + if (message.Kind == MessageKind.Reply) { -
+
} // Avatar @@ -122,16 +122,16 @@
@if (isFirst) { - // Reference - if (message.Reference is not null) + // Reply + if (message.Kind == MessageKind.Reply && message.Reference is not null) { -
+
@if (message.ReferencedMessage is not null) { - Avatar -
@referencedUserNick
-
- + Avatar +
@referencedUserNick
+
+ @if (!string.IsNullOrWhiteSpace(message.ReferencedMessage.Content) && !message.ReferencedMessage.IsContentHidden()) { @Html.Raw(await FormatEmbedMarkdownAsync(message.ReferencedMessage.Content)) @@ -149,13 +149,13 @@ @if (message.ReferencedMessage.EditedTimestamp is not null) { - (edited) + (edited) }
} else { -
+
Original message was deleted or could not be loaded.
} @@ -170,7 +170,15 @@ @{/* Bot label */} @if (message.Author.IsBot) { - BOT + // For cross-posts, the BOT tag is replaced with the SERVER tag + if (message.Kind != MessageKind.Reply && message.Reference is not null && message.Reference.GuildId != ExportContext.Request.Guild.Id) + { + SERVER + } + else + { + BOT + } } @{/* Timestamp */} diff --git a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml index 5670c08f..7eaba158 100644 --- a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml @@ -173,7 +173,7 @@ text-align: center; } - .chatlog__reference-symbol { + .chatlog__reply-symbol { height: 10px; margin: 6px 4px 4px 36px; border-left: 2px solid @Themed("#4f545c", "#c7ccd1"); @@ -201,7 +201,7 @@ min-width: 0; } - .chatlog__reference { + .chatlog__reply { display: flex; margin-bottom: 0.15rem; align-items: center; @@ -212,49 +212,49 @@ text-overflow: ellipsis; } - .chatlog__reference-avatar { + .chatlog__reply-avatar { width: 16px; height: 16px; margin-right: 0.25rem; border-radius: 50%; } - .chatlog__reference-author { + .chatlog__reply-author { margin-right: 0.3rem; font-weight: 600; } - .chatlog__reference-content { + .chatlog__reply-content { overflow: hidden; text-overflow: ellipsis; } - .chatlog__reference-link { + .chatlog__reply-link { cursor: pointer; } - .chatlog__reference-link * { + .chatlog__reply-link * { display: inline; pointer-events: none; } - .chatlog__reference-link .chatlog__markdown-quote { + .chatlog__reply-link .chatlog__markdown-quote { display: inline; } - .chatlog__reference-link .chatlog__markdown-pre { + .chatlog__reply-link .chatlog__markdown-pre { display: inline; } - .chatlog__reference-link:hover { + .chatlog__reply-link:hover { color: @Themed("#ffffff", "#2f3136"); } - .chatlog__reference-link:hover *:not(.chatlog__markdown-spoiler) { + .chatlog__reply-link:hover *:not(.chatlog__markdown-spoiler) { color: inherit; } - .chatlog__reference-edited-timestamp { + .chatlog__reply-edited-timestamp { margin-left: 0.25rem; color: @Themed("#a3a6aa", "#5e6772"); font-size: 0.75rem; @@ -304,7 +304,7 @@ color: @Themed("#ffffff", "#2f3136"); } - .chatlog__bot-label { + .chatlog__author-tag { position: relative; top: -0.1rem; margin-left: 0.3rem;