fedimbed: quoted fix, forgot bsky quotes
This commit is contained in:
		
							parent
							
								
									37c09e1944
								
							
						
					
					
						commit
						e9ad6e570d
					
				
					 1 changed files with 54 additions and 35 deletions
				
			
		| 
						 | 
					@ -325,7 +325,7 @@ function getStatsBluesky(post) {
 | 
				
			||||||
  return stats.join("\u3000");
 | 
					  return stats.join("\u3000");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
async function blueskyQuoteEmbed(quote) {
 | 
					async function blueskyQuoteEmbed(quote, minimal = false) {
 | 
				
			||||||
  const images = [];
 | 
					  const images = [];
 | 
				
			||||||
  const videos = [];
 | 
					  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) {
 | 
					  for (const label of quote.labels) {
 | 
				
			||||||
    if (label.val === "!hide") {
 | 
					    if (label.val === "!hide") {
 | 
				
			||||||
      hidden = true;
 | 
					      hidden = true;
 | 
				
			||||||
| 
						 | 
					@ -373,27 +377,34 @@ async function blueskyQuoteEmbed(quote) {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217").replaceAll("||", "|\u200b|");
 | 
					  content = content.replaceAll("`", "\u02cb").replaceAll("*", "\u2217").replaceAll("||", "|\u200b|");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const header = [
 | 
					  const header = minimal
 | 
				
			||||||
    {
 | 
					    ? [
 | 
				
			||||||
      type: 10,
 | 
					 | 
				
			||||||
      content: `-# ${Icons.fedimbed.quote} Quoted Post`,
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      type: 9,
 | 
					 | 
				
			||||||
      components: [
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          type: 10,
 | 
					          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: {
 | 
					          type: 10,
 | 
				
			||||||
          url: quote.author.avatar,
 | 
					          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);
 | 
					  components.push(...header);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (quote.embeds?.[0]) {
 | 
					  if (quote.embeds?.[0]) {
 | 
				
			||||||
| 
						 | 
					@ -445,23 +456,30 @@ async function blueskyQuoteEmbed(quote) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const footer = {
 | 
					  const footer = minimal
 | 
				
			||||||
    type: 9,
 | 
					    ? {
 | 
				
			||||||
    components: [
 | 
					 | 
				
			||||||
      {
 | 
					 | 
				
			||||||
        type: 10,
 | 
					        type: 10,
 | 
				
			||||||
        content: `### -# ${getStatsBluesky(quote)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
					        content: `${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
				
			||||||
          new Date(quote.value.createdAt).getTime() / 1000
 | 
					          new Date(quote.value.createdAt).getTime() / 1000
 | 
				
			||||||
        )}:F>`,
 | 
					        )}:F>`,
 | 
				
			||||||
      },
 | 
					      }
 | 
				
			||||||
    ],
 | 
					    : {
 | 
				
			||||||
    accessory: {
 | 
					        type: 9,
 | 
				
			||||||
      type: 2,
 | 
					        components: [
 | 
				
			||||||
      style: 5,
 | 
					          {
 | 
				
			||||||
      label: "View Post",
 | 
					            type: 10,
 | 
				
			||||||
      url: `https://bsky.app/profile/${quote.author.did}/post/${quote.uri.substring(quote.uri.lastIndexOf("/") + 1)}`,
 | 
					            content: `### -# ${getStatsBluesky(quote)}\n${Icons.fedimbed.bluesky} Bluesky \u2022 <t:${Math.floor(
 | 
				
			||||||
    },
 | 
					              new Date(quote.value.createdAt).getTime() / 1000
 | 
				
			||||||
  };
 | 
					            )}:F>`,
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        accessory: {
 | 
				
			||||||
 | 
					          type: 2,
 | 
				
			||||||
 | 
					          style: 5,
 | 
				
			||||||
 | 
					          label: "View Post",
 | 
				
			||||||
 | 
					          url: quoteUrl,
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (images.length > 0) {
 | 
					  if (images.length > 0) {
 | 
				
			||||||
    components.push({
 | 
					    components.push({
 | 
				
			||||||
| 
						 | 
					@ -565,7 +583,7 @@ async function bluesky(msg, url, spoiler = false, minimal = false) {
 | 
				
			||||||
      case "app.bsky.embed.record#view": {
 | 
					      case "app.bsky.embed.record#view": {
 | 
				
			||||||
        hasQuote = true;
 | 
					        hasQuote = true;
 | 
				
			||||||
        const quote = post.embed.record;
 | 
					        const quote = post.embed.record;
 | 
				
			||||||
        quoteData = await blueskyQuoteEmbed(quote);
 | 
					        quoteData = await blueskyQuoteEmbed(quote, minimal);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (quoteData.adult) adult = true;
 | 
					        if (quoteData.adult) adult = true;
 | 
				
			||||||
        if (quoteData.hidden) hidden = 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 quoteComponents = quoteRes.response.components[0].components;
 | 
				
			||||||
    const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`;
 | 
					    const quoteContext = `-# ${Icons.fedimbed.quote} Quoted Post`;
 | 
				
			||||||
    if (quoteComponents[0].type == 10) {
 | 
					    if (quoteComponents[0].type == 10) {
 | 
				
			||||||
      quoteComponents[0].content =
 | 
					      quoteComponents[0].content = minimal
 | 
				
			||||||
        (minimal ? Icons.fedimbed.quote + " " : quoteContext + "\n") + quoteComponents[0].content;
 | 
					        ? quoteComponents[0].content.replace(/^### /, "$& " + Icons.fedimbed.quote)
 | 
				
			||||||
 | 
					        : quoteContext + "\n" + quoteComponents[0].content;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
 | 
					      quoteComponents.splice(0, 0, {type: 10, content: quoteContext});
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue