diff --git a/DiscordChatExporter.Core/Discord/Data/Message.cs b/DiscordChatExporter.Core/Discord/Data/Message.cs index 29465ab5..9af6d5ab 100644 --- a/DiscordChatExporter.Core/Discord/Data/Message.cs +++ b/DiscordChatExporter.Core/Discord/Data/Message.cs @@ -28,14 +28,16 @@ public partial record Message( MessageReference? Reference, Message? ReferencedMessage, MessageSnapshot? ForwardedMessage, - Interaction? Interaction + Interaction? Interaction, + JsonElement? Poll ) : IHasId { public bool IsEmpty { get; } = string.IsNullOrWhiteSpace(Content) && !Attachments.Any() && !Embeds.Any() - && !Stickers.Any(); + && !Stickers.Any() + && Poll is null; public bool IsSystemNotification { get; } = Kind is >= MessageKind.RecipientAdd and <= MessageKind.ThreadCreated; @@ -187,6 +189,8 @@ public partial record Message var interaction = json.GetPropertyOrNull("interaction")?.Pipe(Interaction.Parse); + var poll = json.GetPropertyOrNull("poll"); + return new Message( id, kind, @@ -205,7 +209,8 @@ public partial record Message messageReference, referencedMessage, forwardedMessage, - interaction + interaction, + poll ); } } diff --git a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml index f0dba0de..7b3f0261 100644 --- a/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/MessageGroupTemplate.cshtml @@ -400,6 +400,35 @@ } + @* Poll *@ + @if (message.Poll is not null) + { + var pollQuestion = message.Poll.Value + .GetPropertyOrNull("question")? + .GetPropertyOrNull("text")? + .GetStringOrNull(); + +
+ @if (!string.IsNullOrWhiteSpace(pollQuestion)) + { +
@Html.Raw(await FormatMarkdownAsync(pollQuestion))
+ } + + @foreach (var answer in message.Poll.Value.GetPropertyOrNull("answers")?.EnumerateArrayOrNull() ?? []) + { + var answerText = answer + .GetPropertyOrNull("poll_media")? + .GetPropertyOrNull("text")? + .GetStringOrNull(); + + if (!string.IsNullOrWhiteSpace(answerText)) + { +
@Html.Raw(await FormatMarkdownAsync(answerText))
+ } + } +
+ } + @* Invites *@ @{ var inviteCodes = MarkdownParser diff --git a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml index aa42294d..34870d0c 100644 --- a/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/PreambleTemplate.cshtml @@ -430,6 +430,27 @@ font-weight: 500; } + .chatlog__poll { + max-width: 520px; + margin-top: 0.3rem; + padding: 0.75rem; + border: 1px solid @Themed("#4f545c", "#d4d7dc"); + border-radius: 8px; + background-color: @Themed("#2f3136", "#f2f3f5"); + } + + .chatlog__poll-question { + margin-bottom: 0.5rem; + font-weight: 600; + } + + .chatlog__poll-answer { + margin-top: 0.35rem; + padding: 0.45rem 0.6rem; + border-radius: 4px; + background-color: @Themed("#36393f", "#ffffff"); + } + .chatlog__attachment { position: relative; width: fit-content;