diff options
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r-- | server/models/video/video-comment.ts | 83 |
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 @@ | |||
1 | import { | 1 | import { 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' | ||
15 | import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' | 2 | import { ActivityTagObject } from '../../../shared/models/activitypub/objects/common-objects' |
16 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 3 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
17 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 4 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
18 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 5 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
19 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' | 6 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' |
20 | import { sendDeleteVideoComment } from '../../lib/activitypub/send' | ||
21 | import { AccountModel } from '../account/account' | 7 | import { AccountModel } from '../account/account' |
22 | import { ActorModel } from '../activitypub/actor' | 8 | import { ActorModel } from '../activitypub/actor' |
23 | import { AvatarModel } from '../avatar/avatar' | ||
24 | import { ServerModel } from '../server/server' | ||
25 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' | 9 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getSort, throwIfNotValid } from '../utils' |
26 | import { VideoModel } from './video' | 10 | import { VideoModel } from './video' |
27 | import { VideoChannelModel } from './video-channel' | 11 | import { VideoChannelModel } from './video-channel' |
28 | import { getServerActor } from '../../helpers/utils' | 12 | import { getServerActor } from '../../helpers/utils' |
29 | import { UserModel } from '../account/user' | ||
30 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' | 13 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' |
31 | import { regexpCapture } from '../../helpers/regexp' | 14 | import { regexpCapture } from '../../helpers/regexp' |
32 | import { uniq } from 'lodash' | 15 | import { uniq } from 'lodash' |
33 | import { FindOptions, literal, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' | 16 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
17 | import * as Bluebird from 'bluebird' | ||
18 | import { | ||
19 | MComment, | ||
20 | MCommentId, | ||
21 | MCommentOwner, | ||
22 | MCommentOwnerReplyVideoLight, | ||
23 | MCommentOwnerVideo, | ||
24 | MCommentOwnerVideoFeed, | ||
25 | MCommentOwnerVideoReply | ||
26 | } from '../../typings/models/video' | ||
27 | import { MUserAccountId } from '@server/typings/models' | ||
34 | 28 | ||
35 | enum ScopeNames { | 29 | enum 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) { |