aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r--server/models/video/video-comment.ts40
1 files changed, 25 insertions, 15 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index cf6278da7..1163f9a0e 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -466,31 +466,41 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
466 } 466 }
467 467
468 extractMentions () { 468 extractMentions () {
469 if (!this.text) return [] 469 let result: string[] = []
470 470
471 const localMention = `@(${actorNameAlphabet}+)` 471 const localMention = `@(${actorNameAlphabet}+)`
472 const remoteMention = `${localMention}@${CONFIG.WEBSERVER.HOST}` 472 const remoteMention = `${localMention}@${CONFIG.WEBSERVER.HOST}`
473 473
474 const mentionRegex = this.isOwned()
475 ? '(?:(?:' + remoteMention + ')|(?:' + localMention + '))' // Include local mentions?
476 : '(?:' + remoteMention + ')'
477
478 const firstMentionRegex = new RegExp(`^${mentionRegex} `, 'g')
479 const endMentionRegex = new RegExp(` ${mentionRegex}$`, 'g')
474 const remoteMentionsRegex = new RegExp(' ' + remoteMention + ' ', 'g') 480 const remoteMentionsRegex = new RegExp(' ' + remoteMention + ' ', 'g')
475 const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g')
476 const firstMentionRegex = new RegExp('^(?:(?:' + remoteMention + ')|(?:' + localMention + ')) ', 'g')
477 const endMentionRegex = new RegExp(' (?:(?:' + remoteMention + ')|(?:' + localMention + '))$', 'g')
478 481
479 return uniq( 482 result = result.concat(
480 [].concat( 483 regexpCapture(this.text, firstMentionRegex)
481 regexpCapture(this.text, remoteMentionsRegex) 484 .map(([ , username1, username2 ]) => username1 || username2),
482 .map(([ , username ]) => username),
483 485
484 regexpCapture(this.text, localMentionsRegex) 486 regexpCapture(this.text, endMentionRegex)
485 .map(([ , username ]) => username), 487 .map(([ , username1, username2 ]) => username1 || username2),
488
489 regexpCapture(this.text, remoteMentionsRegex)
490 .map(([ , username ]) => username)
491 )
486 492
487 regexpCapture(this.text, firstMentionRegex) 493 // Include local mentions
488 .map(([ , username1, username2 ]) => username1 || username2), 494 if (this.isOwned()) {
495 const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g')
489 496
490 regexpCapture(this.text, endMentionRegex) 497 result = result.concat(
491 .map(([ , username1, username2 ]) => username1 || username2) 498 regexpCapture(this.text, localMentionsRegex)
499 .map(([ , username ]) => username)
492 ) 500 )
493 ) 501 }
502
503 return uniq(result)
494 } 504 }
495 505
496 toFormattedJSON () { 506 toFormattedJSON () {