aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2019-02-14 11:04:50 +0100
committerChocobozzz <me@florianbigard.com>2019-02-15 09:43:37 +0100
commit1f6d57e354ef69b66525ac25684a3d7c59e1db57 (patch)
tree299cf86442e51b635d996fdb1949d0eda85a5f4f /server/models
parent72be63e56f5d93de05b2601300ec782f8076c4bf (diff)
downloadPeerTube-1f6d57e354ef69b66525ac25684a3d7c59e1db57.tar.gz
PeerTube-1f6d57e354ef69b66525ac25684a3d7c59e1db57.tar.zst
PeerTube-1f6d57e354ef69b66525ac25684a3d7c59e1db57.zip
Fix mention notification with a remote account
Diffstat (limited to 'server/models')
-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 () {