From a37cf1815330cf5a4e849952052e9c1c650a517b Mon Sep 17 00:00:00 2001 From: notofoe <43095406+notofoe@users.noreply.github.com> Date: Fri, 6 May 2022 09:03:57 +0000 Subject: [PATCH] refactor (route/mastodon): quick fix on empty reposted toots (#9700) --- lib/routes/mastodon/utils.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/routes/mastodon/utils.js b/lib/routes/mastodon/utils.js index 96f906cc9..18022e3b3 100644 --- a/lib/routes/mastodon/utils.js +++ b/lib/routes/mastodon/utils.js @@ -1,7 +1,13 @@ const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); const parseStatuses = (data) => data.map((item) => { + // docs on: https://docs.joinmastodon.org/entities/status/ + + const accountRepostedBy = item.reblog ? item.account : null; + item = item.reblog ? item.reblog : item; + const content = item.content ? item.content.replace(/|<\/span.*?>/gm, '') : ''; const contentRemovedHtml = content.replace(/<(?:.|\n)*?>/gm, '\n'); @@ -26,25 +32,19 @@ const parseStatuses = (data) => }) .join(''); - let author, link, titleAuthor, media; - if (item.reblog !== null) { - author = `${item.reblog.account.display_name} (@${item.reblog.account.acct})`; - link = item.reblog.url; - titleAuthor = `Re @${item.reblog.account.username}`; - media = mediaParse(item.reblog.media_attachments); - } else { - author = `${item.account.display_name} (@${item.account.acct})`; - link = item.url; - titleAuthor = `@${item.account.username}`; - media = mediaParse(item.media_attachments); - } + const author = `${item.account.display_name} (@${item.account.acct})`; + const link = item.url; + const media = mediaParse(item.media_attachments); + + const titleAuthor = accountRepostedBy ? `Re @${accountRepostedBy.username}` : `@${item.account.username}`; const titleText = item.sensitive === true ? `(CW) ${item.spoiler_text}` : contentRemovedHtml; + const title = `${titleAuthor}: "${titleText}"`; return { - title: `${titleAuthor}: "${titleText}"`, + title, author, description: item.spoiler_text + '
' + content + media, - pubDate: new Date(item.created_at).toUTCString(), + pubDate: parseDate(item.created_at), link, guid: item.uri, };