mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2026-09-03 20:53:09 -05:00
19 lines
737 B
TypeScript
19 lines
737 B
TypeScript
import { uniqify } from '@peertube/peertube-core-utils'
|
|
import { WEBSERVER } from '@server/initializers/constants.js'
|
|
import { actorNameAlphabet } from './custom-validators/activitypub/actor.js'
|
|
import { regexpCapture } from './regexp.js'
|
|
|
|
export function extractLocalMentions (text: string, fromLocalEntity: boolean) {
|
|
const setHostOptionalChar = fromLocalEntity
|
|
? '?'
|
|
: ''
|
|
|
|
// FIXME: Use RegExp.escape() when NodeJS 24 is the minimum version required by peertube
|
|
const mentionRegex = new RegExp(`(?<=^|\\s)@(${actorNameAlphabet}+)(?:@${WEBSERVER.HOST})${setHostOptionalChar}(?=[\\s.,!?)]|$)`, 'gmu')
|
|
|
|
const results = regexpCapture(text, mentionRegex)
|
|
.map(([ , username ]) => username)
|
|
|
|
return uniqify(results)
|
|
}
|