diff --git a/src/modules/fedimbed.js b/src/modules/fedimbed.js index 4a13cdf..e6d3ca2 100644 --- a/src/modules/fedimbed.js +++ b/src/modules/fedimbed.js @@ -325,7 +325,7 @@ function getStatsBluesky(post) { return stats.join("\u3000"); } -async function blueskyQuoteEmbed(quote) { +async function blueskyQuoteEmbed(quote, minimal = false) { const images = []; const videos = []; @@ -349,6 +349,10 @@ async function blueskyQuoteEmbed(quote) { }; } + const quoteUrl = `https://bsky.app/profile/${quote.author.did}/post/${quote.uri.substring( + quote.uri.lastIndexOf("/") + 1 + )}`; + for (const label of quote.labels) { if (label.val === "!hide") { hidden = true; @@ -373,27 +377,34 @@ async function blueskyQuoteEmbed(quote) { } content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217").replaceAll("||", "|\u200b|"); - const header = [ - { - type: 10, - content: `-# ${Icons.fedimbed.quote} Quoted Post`, - }, - { - type: 9, - components: [ + const header = minimal + ? [ { type: 10, - content: `## ${quote.author.displayName}\n-# [@${quote.author.handle}](https://bsky.app/profile/${quote.author.did})\n${content}`, + content: `### ${Icons.fedimbed.quote} [${quote.author.displayName} (@${quote.author.handle})](${quoteUrl})`, }, - ], - accessory: { - type: 11, - media: { - url: quote.author.avatar, + ] + : [ + { + type: 10, + content: `-# ${Icons.fedimbed.quote} Quoted Post`, }, - }, - }, - ]; + { + type: 9, + components: [ + { + type: 10, + content: `## ${quote.author.displayName}\n-# [@${quote.author.handle}](https://bsky.app/profile/${quote.author.did})\n${content}`, + }, + ], + accessory: { + type: 11, + media: { + url: quote.author.avatar, + }, + }, + }, + ]; components.push(...header); if (quote.embeds?.[0]) { @@ -445,23 +456,30 @@ async function blueskyQuoteEmbed(quote) { } } - const footer = { - type: 9, - components: [ - { + const footer = minimal + ? { type: 10, - content: `### -# ${getStatsBluesky(quote)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 `, - }, - ], - accessory: { - type: 2, - style: 5, - label: "View Post", - url: `https://bsky.app/profile/${quote.author.did}/post/${quote.uri.substring(quote.uri.lastIndexOf("/") + 1)}`, - }, - }; + } + : { + type: 9, + components: [ + { + type: 10, + content: `### -# ${getStatsBluesky(quote)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 `, + }, + ], + accessory: { + type: 2, + style: 5, + label: "View Post", + url: quoteUrl, + }, + }; if (images.length > 0) { components.push({ @@ -565,7 +583,7 @@ async function bluesky(msg, url, spoiler = false, minimal = false) { case "app.bsky.embed.record#view": { hasQuote = true; const quote = post.embed.record; - quoteData = await blueskyQuoteEmbed(quote); + quoteData = await blueskyQuoteEmbed(quote, minimal); if (quoteData.adult) adult = true; if (quoteData.hidden) hidden = true; @@ -1551,8 +1569,9 @@ async function processUrl(msg, url, spoiler = false, command = false, inQuote = const quoteComponents = quoteRes.response.components[0].components; const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`; if (quoteComponents[0].type == 10) { - quoteComponents[0].content = - (minimal ? Icons.fedimbed.quote + " " : quoteContext + "\n") + quoteComponents[0].content; + quoteComponents[0].content = minimal + ? quoteComponents[0].content.replace(/^### /, "$& " + Icons.fedimbed.quote) + : quoteContext + "\n" + quoteComponents[0].content; } else { quoteComponents.splice(0, 0, {type: 10, content: quoteContext}); }