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,