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'
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'
return VideoCommentModel.findAndCountAll<MComment>(query)
}
- static async listForFeed (start: number, count: number, videoId?: number): Promise<MCommentOwnerVideoFeed[]> {
+ static async listForFeed (parameters: {
+ start: number
+ count: number
+ videoId?: number
+ accountId?: number
+ videoChannelId?: number
+ }): Promise<MCommentOwnerVideoFeed[]> {
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,
limit: count,
where: {
deletedAt: null,
- accountId: {
- [Op.notIn]: Sequelize.literal(
- '(' + buildBlockedAccountSQL([ serverActor.Account.id, '"Video->VideoChannel"."accountId"' ]) + ')'
- )
- }
+ accountId: accountWhere
},
include: [
{
{
attributes: [ 'accountId' ],
model: VideoChannelModel.unscoped(),
- required: true
+ required: true,
+ where: videoChannelWhere
}
]
}