mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Add recepients-inline for better Mastodon compatibility
This commit is contained in:
parent
8d021865c6
commit
af5420222b
1 changed files with 23 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { findReplyTag, lodash, nip19, TTLCache, unfurl, z } from '@/deps.ts';
|
import { findReplyTag, lodash, nip19, nip21, TTLCache, unfurl, z } from '@/deps.ts';
|
||||||
import { type Event } from '@/event.ts';
|
import { type Event } from '@/event.ts';
|
||||||
import { type MetaContent, parseMetaContent } from '@/schema.ts';
|
import { type MetaContent, parseMetaContent } from '@/schema.ts';
|
||||||
|
|
||||||
|
|
@ -107,11 +107,18 @@ async function toStatus(event: Event<1>) {
|
||||||
const { html, links, firstUrl } = parseNoteContent(event.content);
|
const { html, links, firstUrl } = parseNoteContent(event.content);
|
||||||
const mediaLinks = getMediaLinks(links);
|
const mediaLinks = getMediaLinks(links);
|
||||||
|
|
||||||
|
const [mentions, card] = await Promise.all([
|
||||||
|
Promise.all(mentionedPubkeys.map(toMention)),
|
||||||
|
firstUrl ? await unfurlCardCached(firstUrl) : null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
const content = buildInlineRecipients(mentions) + html;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: event.id,
|
id: event.id,
|
||||||
account,
|
account,
|
||||||
card: firstUrl ? await unfurlCardCached(firstUrl) : null,
|
card,
|
||||||
content: html,
|
content,
|
||||||
created_at: new Date(event.created_at * 1000).toISOString(),
|
created_at: new Date(event.created_at * 1000).toISOString(),
|
||||||
in_reply_to_id: replyTag ? replyTag[1] : null,
|
in_reply_to_id: replyTag ? replyTag[1] : null,
|
||||||
in_reply_to_account_id: null,
|
in_reply_to_account_id: null,
|
||||||
|
|
@ -129,7 +136,7 @@ async function toStatus(event: Event<1>) {
|
||||||
reblog: null,
|
reblog: null,
|
||||||
application: null,
|
application: null,
|
||||||
media_attachments: mediaLinks.map(renderAttachment),
|
media_attachments: mediaLinks.map(renderAttachment),
|
||||||
mentions: await Promise.all(mentionedPubkeys.map(toMention)),
|
mentions,
|
||||||
tags: [],
|
tags: [],
|
||||||
emojis: [],
|
emojis: [],
|
||||||
poll: null,
|
poll: null,
|
||||||
|
|
@ -138,6 +145,18 @@ async function toStatus(event: Event<1>) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Mention = Awaited<ReturnType<typeof toMention>>;
|
||||||
|
|
||||||
|
function buildInlineRecipients(mentions: Mention[]): string {
|
||||||
|
const elements = mentions.reduce<string[]>((acc, { url, username }) => {
|
||||||
|
const name = nip21.BECH32_REGEX.test(username) ? username.substring(0, 8) : username;
|
||||||
|
acc.push(`<a href="${url}" class="u-url mention" rel="ugc">@<span>${name}</span></a>`);
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return `<span class="recipients-inline">${elements.join(' ')} </span>`;
|
||||||
|
}
|
||||||
|
|
||||||
const attachmentTypeSchema = z.enum(['image', 'video', 'gifv', 'audio', 'unknown']).catch('unknown');
|
const attachmentTypeSchema = z.enum(['image', 'video', 'gifv', 'audio', 'unknown']).catch('unknown');
|
||||||
|
|
||||||
function renderAttachment({ url, mimeType }: MediaLink) {
|
function renderAttachment({ url, mimeType }: MediaLink) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue