Add support for group DMs in invite embeds

pull/1003/head
Tyrrrz 2 years ago
parent ac7f08ff3e
commit 2a1998b81c

@ -8,7 +8,7 @@ namespace DiscordChatExporter.Core.Discord.Data;
// https://discord.com/developers/docs/resources/invite#invite-object
public record Invite(
string Code,
Guild? Guild,
Guild Guild,
Channel? Channel)
{
public static string? TryGetCodeFromUrl(string url) =>
@ -17,7 +17,7 @@ public record Invite(
public static Invite Parse(JsonElement json)
{
var code = json.GetProperty("code").GetNonWhiteSpaceString();
var guild = json.GetPropertyOrNull("guild")?.Pipe(Guild.Parse);
var guild = json.GetPropertyOrNull("guild")?.Pipe(Guild.Parse) ?? Guild.DirectMessages;
var channel = json.GetPropertyOrNull("channel")?.Pipe(c => Channel.Parse(c));
return new Invite(code, guild, channel);

@ -329,15 +329,15 @@
<div class="chatlog__embed">
<div class="chatlog__embed-invite-container">
<div class="chatlog__embed-invite-title">Invite to join a server</div>
<div class="chatlog__embed-invite-title">@(invite.Channel?.Kind.IsDirect() == true ? "Invite to join a group DM" : "Invite to join a server")</div>
<div class="chatlog__embed-invite">
<div class="chatlog__embed-invite-guild-icon-container">
<img class="chatlog__embed-invite-guild-icon" src="@await ResolveAssetUrlAsync(invite.Guild?.IconUrl ?? Guild.DirectMessages.IconUrl)" alt="Guild icon" loading="lazy">
<img class="chatlog__embed-invite-guild-icon" src="@await ResolveAssetUrlAsync(invite.Channel?.IconUrl ?? invite.Guild.IconUrl)" alt="Guild icon" loading="lazy">
</div>
<div class="chatlog__embed-invite-info">
<div class="chatlog__embed-invite-guild-name">
<a href="https://discord.gg/@invite.Code">
@(invite.Guild?.Name ?? "Unknown Guild")
@(invite.Guild.Name)
</a>
</div>
<div class="chatlog__embed-invite-channel-name">

Loading…
Cancel
Save