From 23ae1519c3f24fa26611ca5d0a1d39d05f019a85 Mon Sep 17 00:00:00 2001 From: Cynthia Date: Tue, 6 Dec 2022 21:17:12 -0700 Subject: [PATCH] fedimbed: get real instance of linked post --- src/modules/fedimbed.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 9f8cbfa..be3cd4e 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -63,9 +63,9 @@ async function resolvePlatform(url) { async function processUrl(msg, url) { let urlObj = new URL(url); - const platform = await resolvePlatform(url); - const color = PLATFORM_COLORS[platform]; - const platformName = platform + let platform = await resolvePlatform(url); + let color = PLATFORM_COLORS[platform]; + let platformName = platform .replace("gotosocial", "GoToSocial") .replace(/^(.)/, (_, c) => c.toUpperCase()); @@ -214,6 +214,17 @@ async function processUrl(msg, url) { } } } else { + if (postData.id) { + const realUrlObj = new URL(postData.id); + if (realUrlObj.origin != urlObj.origin) { + platform = await resolvePlatform(postData.id); + color = PLATFORM_COLORS[platform]; + platformName = platform + .replace("gotosocial", "GoToSocial") + .replace(/^(.)/, (_, c) => c.toUpperCase()); + } + } + content = postData._misskey_content ?? postData.source?.content ?? postData.content; cw = postData.summary; @@ -253,9 +264,10 @@ async function processUrl(msg, url) { }); if (authorData) { + const authorUrlObj = new URL(authorData.url); author = { name: authorData.name, - handle: `${authorData.preferredUsername}@${urlObj.hostname}`, + handle: `${authorData.preferredUsername}@${authorUrlObj.hostname}`, url: authorData.url, avatar: authorData.icon.url, };