X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-comment.ts;h=90625d987a9f6436ecf125f3360ee9a8fe544a1b;hb=e234debc4d62e1f58b34f8af5a6139074fb7724d;hp=ba09522cceb492ca30fcf5ae7cc758cf9cda718b;hpb=35b30b643cf9870b0934f34253ffb23cf6a264b0;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index ba09522cc..90625d987 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -3,7 +3,7 @@ import { uniq } from 'lodash' import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { getServerActor } from '@server/models/application/application' -import { MAccount, MAccountId, MUserAccountId } from '@server/typings/models' +import { MAccount, MAccountId, MUserAccountId } from '@server/types/models' import { VideoPrivacy } from '@shared/models' import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' @@ -23,7 +23,7 @@ import { MCommentOwnerVideoFeed, MCommentOwnerVideoReply, MVideoImmutable -} from '../../typings/models/video' +} from '../../types/models/video' import { AccountModel } from '../account/account' import { ActorModel, unusedActorAttributesForAPI } from '../activitypub/actor' import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' @@ -144,6 +144,11 @@ enum ScopeNames { }, { fields: [ 'accountId' ] + }, + { + fields: [ + { name: 'createdAt', order: 'DESC' } + ] } ] }) @@ -422,8 +427,31 @@ export class VideoCommentModel extends Model { return VideoCommentModel.findAndCountAll(query) } - static async listForFeed (start: number, count: number, videoId?: number): Promise { + static async listForFeed (parameters: { + start: number + count: number + videoId?: number + accountId?: number + videoChannelId?: number + }): Promise { const serverActor = await getServerActor() + const { start, count, videoId, accountId, videoChannelId } = parameters + + const accountExclusion = { + [Op.notIn]: Sequelize.literal( + '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' + ) + } + const accountWhere = accountId + ? { + [Op.and]: { + ...accountExclusion, + [Op.eq]: accountId + } + } + : accountExclusion + + const videoChannelWhere = videoChannelId ? { id: videoChannelId } : undefined const query = { order: [ [ 'createdAt', 'DESC' ] ] as Order, @@ -431,11 +459,7 @@ export class VideoCommentModel extends Model { limit: count, where: { deletedAt: null, - accountId: { - [Op.notIn]: Sequelize.literal( - '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')' - ) - } + accountId: accountWhere }, include: [ { @@ -449,7 +473,8 @@ export class VideoCommentModel extends Model { { attributes: [ 'accountId' ], model: VideoChannelModel.unscoped(), - required: true + required: true, + where: videoChannelWhere } ] }