fedimbed: get real instance of linked post

This commit is contained in:
Cynthia Foxwell 2022-12-06 21:17:12 -07:00
parent 5ab26c461f
commit 23ae1519c3

View file

@ -63,9 +63,9 @@ async function resolvePlatform(url) {
async function processUrl(msg, url) { async function processUrl(msg, url) {
let urlObj = new URL(url); let urlObj = new URL(url);
const platform = await resolvePlatform(url); let platform = await resolvePlatform(url);
const color = PLATFORM_COLORS[platform]; let color = PLATFORM_COLORS[platform];
const platformName = platform let platformName = platform
.replace("gotosocial", "GoToSocial") .replace("gotosocial", "GoToSocial")
.replace(/^(.)/, (_, c) => c.toUpperCase()); .replace(/^(.)/, (_, c) => c.toUpperCase());
@ -214,6 +214,17 @@ async function processUrl(msg, url) {
} }
} }
} else { } 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 = content =
postData._misskey_content ?? postData.source?.content ?? postData.content; postData._misskey_content ?? postData.source?.content ?? postData.content;
cw = postData.summary; cw = postData.summary;
@ -253,9 +264,10 @@ async function processUrl(msg, url) {
}); });
if (authorData) { if (authorData) {
const authorUrlObj = new URL(authorData.url);
author = { author = {
name: authorData.name, name: authorData.name,
handle: `${authorData.preferredUsername}@${urlObj.hostname}`, handle: `${authorData.preferredUsername}@${authorUrlObj.hostname}`,
url: authorData.url, url: authorData.url,
avatar: authorData.icon.url, avatar: authorData.icon.url,
}; };