From 1f6d57e354ef69b66525ac25684a3d7c59e1db57 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Feb 2019 11:04:50 +0100 Subject: Fix mention notification with a remote account --- server/models/video/video-comment.ts | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) (limited to 'server/models') 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 { } extractMentions () { - if (!this.text) return [] + let result: string[] = [] const localMention = `@(${actorNameAlphabet}+)` const remoteMention = `${localMention}@${CONFIG.WEBSERVER.HOST}` + const mentionRegex = this.isOwned() + ? '(?:(?:' + remoteMention + ')|(?:' + localMention + '))' // Include local mentions? + : '(?:' + remoteMention + ')' + + const firstMentionRegex = new RegExp(`^${mentionRegex} `, 'g') + const endMentionRegex = new RegExp(` ${mentionRegex}$`, 'g') const remoteMentionsRegex = new RegExp(' ' + remoteMention + ' ', 'g') - const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g') - const firstMentionRegex = new RegExp('^(?:(?:' + remoteMention + ')|(?:' + localMention + ')) ', 'g') - const endMentionRegex = new RegExp(' (?:(?:' + remoteMention + ')|(?:' + localMention + '))$', 'g') - return uniq( - [].concat( - regexpCapture(this.text, remoteMentionsRegex) - .map(([ , username ]) => username), + result = result.concat( + regexpCapture(this.text, firstMentionRegex) + .map(([ , username1, username2 ]) => username1 || username2), - regexpCapture(this.text, localMentionsRegex) - .map(([ , username ]) => username), + regexpCapture(this.text, endMentionRegex) + .map(([ , username1, username2 ]) => username1 || username2), + + regexpCapture(this.text, remoteMentionsRegex) + .map(([ , username ]) => username) + ) - regexpCapture(this.text, firstMentionRegex) - .map(([ , username1, username2 ]) => username1 || username2), + // Include local mentions + if (this.isOwned()) { + const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g') - regexpCapture(this.text, endMentionRegex) - .map(([ , username1, username2 ]) => username1 || username2) + result = result.concat( + regexpCapture(this.text, localMentionsRegex) + .map(([ , username ]) => username) ) - ) + } + + return uniq(result) } toFormattedJSON () { -- cgit v1.2.3