X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Fmodels%2Fvideo%2Fvideo-comment.ts;h=e79aff20939467746736f4dcbb8556a6958ab13b;hb=8cd72bd37724054f8942f2fefc7aa2e60eca74cf;hp=5386a10aa4892a8fa9f9b58f6150da30c1c0b31d;hpb=a3cffab42d78560a7db8ad1df14680be5b55277f;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 5386a10aa..e79aff209 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -108,6 +108,9 @@ enum ScopeNames { { fields: [ 'url' ], unique: true + }, + { + fields: [ 'accountId' ] } ] }) @@ -326,6 +329,42 @@ export class VideoCommentModel extends Model { .findAll(query) } + static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Sequelize.Transaction, order: 'ASC' | 'DESC' = 'ASC') { + const query = { + order: [ [ 'createdAt', order ] ], + offset: start, + limit: count, + where: { + videoId + }, + transaction: t + } + + return VideoCommentModel.findAndCountAll(query) + } + + static listForFeed (start: number, count: number, videoId?: number) { + const query = { + order: [ [ 'createdAt', 'DESC' ] ], + offset: start, + limit: count, + where: {}, + include: [ + { + attributes: [ 'name', 'uuid' ], + model: VideoModel.unscoped(), + required: true + } + ] + } + + if (videoId) query.where['videoId'] = videoId + + return VideoCommentModel + .scope([ ScopeNames.WITH_ACCOUNT ]) + .findAll(query) + } + static async getStats () { const totalLocalVideoComments = await VideoCommentModel.count({ include: [