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.ts83
1 files changed, 26 insertions, 57 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 58b75510d..c88dac1c1 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -1,36 +1,30 @@
1import { 1import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
2 AllowNull,
3 BeforeDestroy,
4 BelongsTo,
5 Column,
6 CreatedAt,
7 DataType,
8 ForeignKey,
9 Is,
10 Model,
11 Scopes,
12 Table,
13 UpdatedAt
14} from 'sequelize-typescript'
15import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' 2import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects'
16import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' 3import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object'
17import { VideoComment } from '../../../shared/models/videos/video-comment.model' 4import { VideoComment } from '../../../shared/models/videos/video-comment.model'
18import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 5import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
19import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' 6import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants'
20import { sendDeleteVideoComment } from '../../lib/activitypub/send'
21import { AccountModel } from '../account/account' 7import { AccountModel } from '../account/account'
22import { ActorModel } from '../activitypub/actor' 8import { ActorModel } from '../activitypub/actor'
23import { AvatarModel } from '../avatar/avatar'
24import { ServerModel } from '../server/server'
25import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' 9import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils'
26import { VideoModel } from './video' 10import { VideoModel } from './video'
27import { VideoChannelModel } from './video-channel' 11import { VideoChannelModel } from './video-channel'
28import { getServerActor } from '../../helpers/utils' 12import { getServerActor } from '../../helpers/utils'
29import { UserModel } from '../account/user'
30import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' 13import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor'
31import { regexpCapture } from '../../helpers/regexp' 14import { regexpCapture } from '../../helpers/regexp'
32import { uniq } from 'lodash' 15import { uniq } from 'lodash'
33import { FindOptions, literal, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' 16import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize'
17import * as Bluebird from 'bluebird'
18import {
19 MComment,
20 MCommentId,
21 MCommentOwner,
22 MCommentOwnerReplyVideoLight,
23 MCommentOwnerVideo,
24 MCommentOwnerVideoFeed,
25 MCommentOwnerVideoReply
26} from '../../typings/models/video'
27import { MUserAccountId } from '@server/typings/models'
34 28
35enum ScopeNames { 29enum ScopeNames {
36 WITH_ACCOUNT = 'WITH_ACCOUNT', 30 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -68,22 +62,7 @@ enum ScopeNames {
68 [ScopeNames.WITH_ACCOUNT]: { 62 [ScopeNames.WITH_ACCOUNT]: {
69 include: [ 63 include: [
70 { 64 {
71 model: AccountModel, 65 model: AccountModel
72 include: [
73 {
74 model: ActorModel,
75 include: [
76 {
77 model: ServerModel,
78 required: false
79 },
80 {
81 model: AvatarModel,
82 required: false
83 }
84 ]
85 }
86 ]
87 } 66 }
88 ] 67 ]
89 }, 68 },
@@ -102,22 +81,12 @@ enum ScopeNames {
102 required: true, 81 required: true,
103 include: [ 82 include: [
104 { 83 {
105 model: VideoChannelModel.unscoped(), 84 model: VideoChannelModel,
106 required: true, 85 required: true,
107 include: [ 86 include: [
108 { 87 {
109 model: ActorModel,
110 required: true
111 },
112 {
113 model: AccountModel, 88 model: AccountModel,
114 required: true, 89 required: true
115 include: [
116 {
117 model: ActorModel,
118 required: true
119 }
120 ]
121 } 90 }
122 ] 91 ]
123 } 92 }
@@ -212,7 +181,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
212 }) 181 })
213 Account: AccountModel 182 Account: AccountModel
214 183
215 static loadById (id: number, t?: Transaction) { 184 static loadById (id: number, t?: Transaction): Bluebird<MComment> {
216 const query: FindOptions = { 185 const query: FindOptions = {
217 where: { 186 where: {
218 id 187 id
@@ -224,7 +193,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
224 return VideoCommentModel.findOne(query) 193 return VideoCommentModel.findOne(query)
225 } 194 }
226 195
227 static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction) { 196 static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction): Bluebird<MCommentOwnerVideoReply> {
228 const query: FindOptions = { 197 const query: FindOptions = {
229 where: { 198 where: {
230 id 199 id
@@ -238,7 +207,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
238 .findOne(query) 207 .findOne(query)
239 } 208 }
240 209
241 static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction) { 210 static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction): Bluebird<MCommentOwnerVideo> {
242 const query: FindOptions = { 211 const query: FindOptions = {
243 where: { 212 where: {
244 url 213 url
@@ -250,7 +219,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
250 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query) 219 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query)
251 } 220 }
252 221
253 static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction) { 222 static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction): Bluebird<MCommentOwnerReplyVideoLight> {
254 const query: FindOptions = { 223 const query: FindOptions = {
255 where: { 224 where: {
256 url 225 url
@@ -273,7 +242,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
273 start: number, 242 start: number,
274 count: number, 243 count: number,
275 sort: string, 244 sort: string,
276 user?: UserModel 245 user?: MUserAccountId
277 }) { 246 }) {
278 const { videoId, start, count, sort, user } = parameters 247 const { videoId, start, count, sort, user } = parameters
279 248
@@ -314,7 +283,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
314 static async listThreadCommentsForApi (parameters: { 283 static async listThreadCommentsForApi (parameters: {
315 videoId: number, 284 videoId: number,
316 threadId: number, 285 threadId: number,
317 user?: UserModel 286 user?: MUserAccountId
318 }) { 287 }) {
319 const { videoId, threadId, user } = parameters 288 const { videoId, threadId, user } = parameters
320 289
@@ -353,7 +322,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
353 }) 322 })
354 } 323 }
355 324
356 static listThreadParentComments (comment: VideoCommentModel, t: Transaction, order: 'ASC' | 'DESC' = 'ASC') { 325 static listThreadParentComments (comment: MCommentId, t: Transaction, order: 'ASC' | 'DESC' = 'ASC'): Bluebird<MCommentOwner[]> {
357 const query = { 326 const query = {
358 order: [ [ 'createdAt', order ] ] as Order, 327 order: [ [ 'createdAt', order ] ] as Order,
359 where: { 328 where: {
@@ -389,10 +358,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
389 transaction: t 358 transaction: t
390 } 359 }
391 360
392 return VideoCommentModel.findAndCountAll(query) 361 return VideoCommentModel.findAndCountAll<MComment>(query)
393 } 362 }
394 363
395 static listForFeed (start: number, count: number, videoId?: number) { 364 static listForFeed (start: number, count: number, videoId?: number): Bluebird<MCommentOwnerVideoFeed[]> {
396 const query = { 365 const query = {
397 order: [ [ 'createdAt', 'DESC' ] ] as Order, 366 order: [ [ 'createdAt', 'DESC' ] ] as Order,
398 offset: start, 367 offset: start,
@@ -521,7 +490,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
521 } as VideoComment 490 } as VideoComment
522 } 491 }
523 492
524 toActivityPubObject (threadParentComments: VideoCommentModel[]): VideoCommentObject { 493 toActivityPubObject (threadParentComments: MCommentOwner[]): VideoCommentObject {
525 let inReplyTo: string 494 let inReplyTo: string
526 // New thread, so in AS we reply to the video 495 // New thread, so in AS we reply to the video
527 if (this.inReplyToCommentId === null) { 496 if (this.inReplyToCommentId === null) {