[backend] Format mentions in outgoing AP messages properly

This commit is contained in:
Laura Hausmann 2023-10-12 00:03:33 +02:00
parent be28fae40f
commit 1ff5102e34
No known key found for this signature in database
GPG Key ID: D044E84C5BE01605
2 changed files with 18 additions and 4 deletions

View File

@ -112,6 +112,9 @@ export function toHtml(
}, },
mention(node) { mention(node) {
const el = doc.createElement("span");
el.setAttribute("class", "h-card");
el.setAttribute("translate", "no");
const a = doc.createElement("a"); const a = doc.createElement("a");
const { username, host, acct } = node.props; const { username, host, acct } = node.props;
const remoteUserInfo = mentionedRemoteUsers.find( const remoteUserInfo = mentionedRemoteUsers.find(
@ -124,8 +127,12 @@ export function toHtml(
: remoteUserInfo.uri : remoteUserInfo.uri
: `${config.url}/${acct}`; : `${config.url}/${acct}`;
a.className = "u-url mention"; a.className = "u-url mention";
a.textContent = acct; const span = doc.createElement("span");
return a; span.textContent = username;
a.textContent = '@';
a.appendChild(span);
el.appendChild(a);
return el;
}, },
quote(node) { quote(node) {

View File

@ -129,6 +129,9 @@ export class MfmHelpers {
}, },
mention(node) { mention(node) {
const el = doc.createElement("span");
el.setAttribute("class", "h-card");
el.setAttribute("translate", "no");
const a = doc.createElement("a"); const a = doc.createElement("a");
const { username, host} = node.props; const { username, host} = node.props;
const remoteUserInfo = mentionedRemoteUsers.find( const remoteUserInfo = mentionedRemoteUsers.find(
@ -143,8 +146,12 @@ export class MfmHelpers {
: remoteUserInfo.uri : remoteUserInfo.uri
: `${config.url}/${acct}`; : `${config.url}/${acct}`;
a.className = "u-url mention"; a.className = "u-url mention";
a.textContent = localpart; const span = doc.createElement("span");
return a; span.textContent = username;
a.textContent = '@';
a.appendChild(span);
el.appendChild(a);
return el;
}, },
quote(node) { quote(node) {