From 9476770cdb888325d322dbd522d3506908ddfc64 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 8 Apr 2024 22:54:39 -1000 Subject: [PATCH] Make mentions appear in new posts --- database/entities/Status.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/database/entities/Status.ts b/database/entities/Status.ts index c41451f4..07bdb7a9 100644 --- a/database/entities/Status.ts +++ b/database/entities/Status.ts @@ -206,7 +206,7 @@ export const createNewStatus = async (data: { emojis?: Emoji[]; content_type?: string; uri?: string; - mentions?: User[]; + mentions?: UserWithRelations[]; media_attachments?: string[]; reply?: { status: Status; @@ -260,6 +260,34 @@ export const createNewStatus = async (data: { .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", + ), + `${match}`, + ); + } + } + const status = await client.status.create({ data: { authorId: data.account.id,