aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-comment.ts60
1 files changed, 38 insertions, 22 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 8d1c38826..cfd1d5b7a 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -414,7 +414,15 @@ export class VideoCommentModel extends Model {
414 414
415 const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ videoId, user, isVideoOwned }) 415 const blockerAccountIds = await VideoCommentModel.buildBlockerAccountIds({ videoId, user, isVideoOwned })
416 416
417 const query = { 417 const accountBlockedWhere = {
418 accountId: {
419 [Op.notIn]: Sequelize.literal(
420 '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
421 )
422 }
423 }
424
425 const queryList = {
418 offset: start, 426 offset: start,
419 limit: count, 427 limit: count,
420 order: getCommentSort(sort), 428 order: getCommentSort(sort),
@@ -428,13 +436,7 @@ export class VideoCommentModel extends Model {
428 }, 436 },
429 { 437 {
430 [Op.or]: [ 438 [Op.or]: [
431 { 439 accountBlockedWhere,
432 accountId: {
433 [Op.notIn]: Sequelize.literal(
434 '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
435 )
436 }
437 },
438 { 440 {
439 accountId: null 441 accountId: null
440 } 442 }
@@ -444,19 +446,27 @@ export class VideoCommentModel extends Model {
444 } 446 }
445 } 447 }
446 448
447 const scopes: (string | ScopeOptions)[] = [ 449 const scopesList: (string | ScopeOptions)[] = [
448 ScopeNames.WITH_ACCOUNT_FOR_API, 450 ScopeNames.WITH_ACCOUNT_FOR_API,
449 { 451 {
450 method: [ ScopeNames.ATTRIBUTES_FOR_API, blockerAccountIds ] 452 method: [ ScopeNames.ATTRIBUTES_FOR_API, blockerAccountIds ]
451 } 453 }
452 ] 454 ]
453 455
454 return VideoCommentModel 456 const queryCount = {
455 .scope(scopes) 457 where: {
456 .findAndCountAll(query) 458 videoId,
457 .then(({ rows, count }) => { 459 deletedAt: null,
458 return { total: count, data: rows } 460 ...accountBlockedWhere
459 }) 461 }
462 }
463
464 return Promise.all([
465 VideoCommentModel.scope(scopesList).findAndCountAll(queryList),
466 VideoCommentModel.count(queryCount)
467 ]).then(([ { rows, count }, totalNotDeletedComments ]) => {
468 return { total: count, data: rows, totalNotDeletedComments }
469 })
460 } 470 }
461 471
462 static async listThreadCommentsForApi (parameters: { 472 static async listThreadCommentsForApi (parameters: {
@@ -477,11 +487,18 @@ export class VideoCommentModel extends Model {
477 { id: threadId }, 487 { id: threadId },
478 { originCommentId: threadId } 488 { originCommentId: threadId }
479 ], 489 ],
480 accountId: { 490 [Op.or]: [
481 [Op.notIn]: Sequelize.literal( 491 {
482 '(' + buildBlockedAccountSQL(blockerAccountIds) + ')' 492 accountId: {
483 ) 493 [Op.notIn]: Sequelize.literal(
484 } 494 '(' + buildBlockedAccountSQL(blockerAccountIds) + ')'
495 )
496 }
497 },
498 {
499 accountId: null
500 }
501 ]
485 } 502 }
486 } 503 }
487 504
@@ -492,8 +509,7 @@ export class VideoCommentModel extends Model {
492 } 509 }
493 ] 510 ]
494 511
495 return VideoCommentModel 512 return VideoCommentModel.scope(scopes)
496 .scope(scopes)
497 .findAndCountAll(query) 513 .findAndCountAll(query)
498 .then(({ rows, count }) => { 514 .then(({ rows, count }) => {
499 return { total: count, data: rows } 515 return { total: count, data: rows }