mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 08:28:19 +01:00
Make mentions appear in new posts
This commit is contained in:
parent
b5f31fc4e4
commit
9476770cdb
|
|
@ -206,7 +206,7 @@ export const createNewStatus = async (data: {
|
||||||
emojis?: Emoji[];
|
emojis?: Emoji[];
|
||||||
content_type?: string;
|
content_type?: string;
|
||||||
uri?: string;
|
uri?: string;
|
||||||
mentions?: User[];
|
mentions?: UserWithRelations[];
|
||||||
media_attachments?: string[];
|
media_attachments?: string[];
|
||||||
reply?: {
|
reply?: {
|
||||||
status: Status;
|
status: Status;
|
||||||
|
|
@ -260,6 +260,34 @@ export const createNewStatus = async (data: {
|
||||||
.join("\n");
|
.join("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Turn each @username or @username@instance mention into an anchor link
|
||||||
|
for (const mention of mentions) {
|
||||||
|
const matches = data.content.match(
|
||||||
|
new RegExp(
|
||||||
|
`@${mention.username}(@${mention.instance?.base_url})?`,
|
||||||
|
"g",
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!matches) continue;
|
||||||
|
|
||||||
|
for (const match of matches) {
|
||||||
|
formattedContent = formattedContent.replace(
|
||||||
|
new RegExp(
|
||||||
|
`@${mention.username}(@${mention.instance?.base_url})?`,
|
||||||
|
"g",
|
||||||
|
),
|
||||||
|
`<a class="u-url mention" rel="nofollow noopener noreferrer" target="_blank" href="${
|
||||||
|
mention.uri ||
|
||||||
|
new URL(
|
||||||
|
`/@${mention.username}`,
|
||||||
|
config.http.base_url,
|
||||||
|
).toString()
|
||||||
|
}">${match}</a>`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const status = await client.status.create({
|
const status = await client.status.create({
|
||||||
data: {
|
data: {
|
||||||
authorId: data.account.id,
|
authorId: data.account.id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue