diff options
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r-- | server/models/video/video-comment.ts | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index cb5f1cbbe..5f7cd3671 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -1,4 +1,3 @@ | |||
1 | import * as Sequelize from 'sequelize' | ||
2 | import { | 1 | import { |
3 | AllowNull, | 2 | AllowNull, |
4 | BeforeDestroy, | 3 | BeforeDestroy, |
@@ -7,7 +6,6 @@ import { | |||
7 | CreatedAt, | 6 | CreatedAt, |
8 | DataType, | 7 | DataType, |
9 | ForeignKey, | 8 | ForeignKey, |
10 | IFindOptions, | ||
11 | Is, | 9 | Is, |
12 | Model, | 10 | Model, |
13 | Scopes, | 11 | Scopes, |
@@ -32,6 +30,7 @@ import { UserModel } from '../account/user' | |||
32 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' | 30 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' |
33 | import { regexpCapture } from '../../helpers/regexp' | 31 | import { regexpCapture } from '../../helpers/regexp' |
34 | import { uniq } from 'lodash' | 32 | import { uniq } from 'lodash' |
33 | import { FindOptions, Op, Order, Sequelize, Transaction } from 'sequelize' | ||
35 | 34 | ||
36 | enum ScopeNames { | 35 | enum ScopeNames { |
37 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 36 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
@@ -86,7 +85,7 @@ enum ScopeNames { | |||
86 | } | 85 | } |
87 | ] | 86 | ] |
88 | } | 87 | } |
89 | ] | 88 | ] as any // FIXME: sequelize typings |
90 | }, | 89 | }, |
91 | [ScopeNames.WITH_IN_REPLY_TO]: { | 90 | [ScopeNames.WITH_IN_REPLY_TO]: { |
92 | include: [ | 91 | include: [ |
@@ -120,7 +119,7 @@ enum ScopeNames { | |||
120 | } | 119 | } |
121 | ] | 120 | ] |
122 | } | 121 | } |
123 | ] | 122 | ] as any // FIXME: sequelize typings |
124 | } | 123 | } |
125 | }) | 124 | }) |
126 | @Table({ | 125 | @Table({ |
@@ -244,8 +243,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
244 | } | 243 | } |
245 | } | 244 | } |
246 | 245 | ||
247 | static loadById (id: number, t?: Sequelize.Transaction) { | 246 | static loadById (id: number, t?: Transaction) { |
248 | const query: IFindOptions<VideoCommentModel> = { | 247 | const query: FindOptions = { |
249 | where: { | 248 | where: { |
250 | id | 249 | id |
251 | } | 250 | } |
@@ -256,8 +255,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
256 | return VideoCommentModel.findOne(query) | 255 | return VideoCommentModel.findOne(query) |
257 | } | 256 | } |
258 | 257 | ||
259 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Sequelize.Transaction) { | 258 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction) { |
260 | const query: IFindOptions<VideoCommentModel> = { | 259 | const query: FindOptions = { |
261 | where: { | 260 | where: { |
262 | id | 261 | id |
263 | } | 262 | } |
@@ -270,8 +269,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
270 | .findOne(query) | 269 | .findOne(query) |
271 | } | 270 | } |
272 | 271 | ||
273 | static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) { | 272 | static loadByUrlAndPopulateAccount (url: string, t?: Transaction) { |
274 | const query: IFindOptions<VideoCommentModel> = { | 273 | const query: FindOptions = { |
275 | where: { | 274 | where: { |
276 | url | 275 | url |
277 | } | 276 | } |
@@ -282,8 +281,8 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
282 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) | 281 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) |
283 | } | 282 | } |
284 | 283 | ||
285 | static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Sequelize.Transaction) { | 284 | static loadByUrlAndPopulateReplyAndVideo (url: string, t?: Transaction) { |
286 | const query: IFindOptions<VideoCommentModel> = { | 285 | const query: FindOptions = { |
287 | where: { | 286 | where: { |
288 | url | 287 | url |
289 | } | 288 | } |
@@ -307,7 +306,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
307 | videoId, | 306 | videoId, |
308 | inReplyToCommentId: null, | 307 | inReplyToCommentId: null, |
309 | accountId: { | 308 | accountId: { |
310 | [Sequelize.Op.notIn]: Sequelize.literal( | 309 | [Op.notIn]: Sequelize.literal( |
311 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' | 310 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' |
312 | ) | 311 | ) |
313 | } | 312 | } |
@@ -336,15 +335,15 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
336 | const userAccountId = user ? user.Account.id : undefined | 335 | const userAccountId = user ? user.Account.id : undefined |
337 | 336 | ||
338 | const query = { | 337 | const query = { |
339 | order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ], | 338 | order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ] as Order, |
340 | where: { | 339 | where: { |
341 | videoId, | 340 | videoId, |
342 | [ Sequelize.Op.or ]: [ | 341 | [ Op.or ]: [ |
343 | { id: threadId }, | 342 | { id: threadId }, |
344 | { originCommentId: threadId } | 343 | { originCommentId: threadId } |
345 | ], | 344 | ], |
346 | accountId: { | 345 | accountId: { |
347 | [Sequelize.Op.notIn]: Sequelize.literal( | 346 | [Op.notIn]: Sequelize.literal( |
348 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' | 347 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' |
349 | ) | 348 | ) |
350 | } | 349 | } |
@@ -366,12 +365,12 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
366 | }) | 365 | }) |
367 | } | 366 | } |
368 | 367 | ||
369 | static listThreadParentComments (comment: VideoCommentModel, t: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') { | 368 | static listThreadParentComments (comment: VideoCommentModel, t: Transaction, order: 'ASC' | 'DESC' = 'ASC') { |
370 | const query = { | 369 | const query = { |
371 | order: [ [ 'createdAt', order ] ], | 370 | order: [ [ 'createdAt', order ] ] as Order, |
372 | where: { | 371 | where: { |
373 | id: { | 372 | id: { |
374 | [ Sequelize.Op.in ]: Sequelize.literal('(' + | 373 | [ Op.in ]: Sequelize.literal('(' + |
375 | 'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' + | 374 | 'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' + |
376 | `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` + | 375 | `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` + |
377 | 'UNION ' + | 376 | 'UNION ' + |
@@ -380,7 +379,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
380 | ') ' + | 379 | ') ' + |
381 | 'SELECT id FROM children' + | 380 | 'SELECT id FROM children' + |
382 | ')'), | 381 | ')'), |
383 | [ Sequelize.Op.ne ]: comment.id | 382 | [ Op.ne ]: comment.id |
384 | } | 383 | } |
385 | }, | 384 | }, |
386 | transaction: t | 385 | transaction: t |
@@ -391,9 +390,9 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
391 | .findAll(query) | 390 | .findAll(query) |
392 | } | 391 | } |
393 | 392 | ||
394 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') { | 393 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction, order: 'ASC' | 'DESC' = 'ASC') { |
395 | const query = { | 394 | const query = { |
396 | order: [ [ 'createdAt', order ] ], | 395 | order: [ [ 'createdAt', order ] ] as Order, |
397 | offset: start, | 396 | offset: start, |
398 | limit: count, | 397 | limit: count, |
399 | where: { | 398 | where: { |
@@ -407,7 +406,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
407 | 406 | ||
408 | static listForFeed (start: number, count: number, videoId?: number) { | 407 | static listForFeed (start: number, count: number, videoId?: number) { |
409 | const query = { | 408 | const query = { |
410 | order: [ [ 'createdAt', 'DESC' ] ], | 409 | order: [ [ 'createdAt', 'DESC' ] ] as Order, |
411 | offset: start, | 410 | offset: start, |
412 | limit: count, | 411 | limit: count, |
413 | where: {}, | 412 | where: {}, |
@@ -457,7 +456,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
457 | const query = { | 456 | const query = { |
458 | where: { | 457 | where: { |
459 | updatedAt: { | 458 | updatedAt: { |
460 | [Sequelize.Op.lt]: beforeUpdatedAt | 459 | [Op.lt]: beforeUpdatedAt |
461 | }, | 460 | }, |
462 | videoId | 461 | videoId |
463 | } | 462 | } |