import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
import { VideoComment } from '../../../shared/models/videos/video-comment.model'
import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
-import { CONSTRAINTS_FIELDS } from '../../initializers'
+import { CONFIG, CONSTRAINTS_FIELDS } from '../../initializers'
import { sendDeleteVideoComment } from '../../lib/activitypub/send'
import { AccountModel } from '../account/account'
import { ActorModel } from '../activitypub/actor'
import { VideoChannelModel } from './video-channel'
import { getServerActor } from '../../helpers/utils'
import { UserModel } from '../account/user'
+import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
+import { regexpCapture } from '../../helpers/regexp'
+import { uniq } from 'lodash'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
id: {
[ Sequelize.Op.in ]: Sequelize.literal('(' +
'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +
- 'SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ' + comment.id + ' UNION ' +
- 'SELECT p.id, p."inReplyToCommentId" from "videoComment" p ' +
- 'INNER JOIN children c ON c."inReplyToCommentId" = p.id) ' +
+ `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` +
+ 'UNION ' +
+ 'SELECT "parent"."id", "parent"."inReplyToCommentId" FROM "videoComment" "parent" ' +
+ 'INNER JOIN "children" ON "children"."inReplyToCommentId" = "parent"."id"' +
+ ') ' +
'SELECT id FROM children' +
')'),
[ Sequelize.Op.ne ]: comment.id
}
}
+ static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) {
+ const query = {
+ where: {
+ updatedAt: {
+ [Sequelize.Op.lt]: beforeUpdatedAt
+ },
+ videoId
+ }
+ }
+
+ return VideoCommentModel.destroy(query)
+ }
+
+ getCommentStaticPath () {
+ return this.Video.getWatchStaticPath() + ';threadId=' + this.getThreadId()
+ }
+
getThreadId (): number {
return this.originCommentId || this.id
}
return this.Account.isOwned()
}
+ extractMentions () {
+ 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')
+
+ result = result.concat(
+ regexpCapture(this.text, firstMentionRegex)
+ .map(([ , username1, username2 ]) => username1 || username2),
+
+ regexpCapture(this.text, endMentionRegex)
+ .map(([ , username1, username2 ]) => username1 || username2),
+
+ regexpCapture(this.text, remoteMentionsRegex)
+ .map(([ , username ]) => username)
+ )
+
+ // Include local mentions
+ if (this.isOwned()) {
+ const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g')
+
+ result = result.concat(
+ regexpCapture(this.text, localMentionsRegex)
+ .map(([ , username ]) => username)
+ )
+ }
+
+ return uniq(result)
+ }
+
toFormattedJSON () {
return {
id: this.id,