fedimbed: link emotes

This commit is contained in:
Cynthia Foxwell 2023-08-14 22:42:12 -06:00
parent ffa23ed68f
commit 945c9e7335
1 changed files with 15 additions and 3 deletions

View File

@ -112,7 +112,11 @@ async function processUrl(msg, url, spoiler = false) {
const images = [];
const videos = [];
const audios = [];
let content, cw, author, timestamp;
let content,
cw,
author,
timestamp,
emotes = [];
// Fetch post
let rawPostData;
@ -296,6 +300,9 @@ async function processUrl(msg, url, spoiler = false) {
if (!spoiler && postData2.sensitive) {
spoiler = true;
}
emotes = postData2.emojis
.filter((x) => !x.name.endsWith("@."))
.map((x) => ({name: `:${x.name}:`, url: x.url}));
const attachments = postData2.media_attachments ?? postData2.files;
if (attachments) {
@ -347,8 +354,6 @@ async function processUrl(msg, url, spoiler = false) {
}
}
// if (platform == "gotosocial") console.log(postData);
content =
postData._misskey_content ?? postData.source?.content ?? postData.content;
cw = postData.summary;
@ -356,6 +361,9 @@ async function processUrl(msg, url, spoiler = false) {
if (!spoiler && postData.sensitive) {
spoiler = true;
}
emotes = postData.tag
.filter((x) => !!x.icon)
.map((x) => ({name: x.name, url: x.icon.url}));
// NB: gts doesnt send singular attachments as areay
const attachments = Array.isArray(postData.attachment)
@ -428,6 +436,10 @@ async function processUrl(msg, url, spoiler = false) {
content = content.replace(/(<([^>]+)>)/gi, "");
content = parseHtmlEntities(content);
for (const emote of emotes) {
content = content.replaceAll(emote.name, `[${emote.name}](${emote.url})`);
}
cw = cw.replace(/(<([^>]+)>)/gi, "");
cw = parseHtmlEntities(cw);