diff --git a/packages/backend/src/mfm/to-html.ts b/packages/backend/src/mfm/to-html.ts index 117f8b278..9b72b98c6 100644 --- a/packages/backend/src/mfm/to-html.ts +++ b/packages/backend/src/mfm/to-html.ts @@ -14,23 +14,8 @@ export async function toHtml(mfmText: string, mentions?: string[]): Promise (handlers as any)[x.type](x))) targetElement.appendChild(child); - } - } - const handlers: { [K in mfm.MfmNode['type']]: (node: mfm.NodeType) => any } = { bold(node) { const el = doc.createElement('b'); @@ -117,8 +102,17 @@ export async function toHtml(mfmText: string, mentions?: string[]): Promise { const { username, host, acct } = node.props; + const ids = mentions ?? extractMentions(nodes); + const mentionedUsers = await UserProfiles.createQueryBuilder('user_profile') + .leftJoin('user_profile.user', 'user') + .select('user.username') + .addSelect('user.host') + // links should preferably use user friendly urls, only fall back to AP ids + .addSelect('COALESCE(user_profile.url, user.uri)', 'url') + .where('userId IN (:...ids)', { ids }) + .getMany(); const userInfo = mentionedUsers.find(user => user.user?.username === username && user.userHost === host); if (userInfo != null) { // Mastodon microformat: span.h-card > a.u-url.mention @@ -131,10 +125,9 @@ export async function toHtml(mfmText: string, mentions?: string[]): Promise 0) { + for (const child of children.map(x => (handlers as any)[x.type](x))) targetElement.appendChild(child); + } + } + appendChildren(nodes, doc.body); return `

${doc.body.innerHTML}

`;