import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
import { AccountModel } from '../account/account'
import { ActorModel } from '../activitypub/actor'
-import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils'
+import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils'
import { VideoModel } from './video'
import { VideoChannelModel } from './video-channel'
-import { getServerActor } from '../../helpers/utils'
import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
import { regexpCapture } from '../../helpers/regexp'
import { uniq } from 'lodash'
MCommentOwnerVideoReply
} from '../../typings/models/video'
import { MUserAccountId } from '@server/typings/models'
+import { VideoPrivacy } from '@shared/models'
+import { getServerActor } from '@server/models/application/application'
enum ScopeNames {
WITH_ACCOUNT = 'WITH_ACCOUNT',
')'
),
'totalReplies'
+ ],
+ [
+ Sequelize.literal(
+ '(' +
+ 'SELECT COUNT("replies"."id") ' +
+ 'FROM "videoComment" AS "replies" ' +
+ 'INNER JOIN "video" ON "video"."id" = "replies"."videoId" ' +
+ 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
+ 'WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ' +
+ 'AND "replies"."accountId" = "videoChannel"."accountId"' +
+ ')'
+ ),
+ 'totalRepliesFromVideoAuthor'
]
]
}
}
static async listThreadsForApi (parameters: {
- videoId: number,
- start: number,
- count: number,
- sort: string,
+ videoId: number
+ start: number
+ count: number
+ sort: string
user?: MUserAccountId
}) {
const { videoId, start, count, sort, user } = parameters
const query = {
offset: start,
limit: count,
- order: getSort(sort),
+ order: getCommentSort(sort),
where: {
videoId,
inReplyToCommentId: null,
}
static async listThreadCommentsForApi (parameters: {
- videoId: number,
- threadId: number,
+ videoId: number
+ threadId: number
user?: MUserAccountId
}) {
const { videoId, threadId, user } = parameters
order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ] as Order,
where: {
videoId,
- [ Op.or ]: [
+ [Op.or]: [
{ id: threadId },
{ originCommentId: threadId }
],
order: [ [ 'createdAt', order ] ] as Order,
where: {
id: {
- [ Op.in ]: Sequelize.literal('(' +
+ [Op.in]: Sequelize.literal('(' +
'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' +
`SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` +
'UNION ' +
') ' +
'SELECT id FROM children' +
')'),
- [ Op.ne ]: comment.id
+ [Op.ne]: comment.id
}
},
transaction: t
order: [ [ 'createdAt', 'DESC' ] ] as Order,
offset: start,
limit: count,
- where: {},
+ where: {
+ deletedAt: null
+ },
include: [
{
attributes: [ 'name', 'uuid' ],
model: VideoModel.unscoped(),
- required: true
+ required: true,
+ where: {
+ privacy: VideoPrivacy.PUBLIC
+ }
}
]
}
}
isDeleted () {
- return null !== this.deletedAt
+ return this.deletedAt !== null
}
extractMentions () {
updatedAt: this.updatedAt,
deletedAt: this.deletedAt,
isDeleted: this.isDeleted(),
+ totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0,
totalReplies: this.get('totalReplies') || 0,
account: this.Account ? this.Account.toFormattedJSON() : null
} as VideoComment