X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=server%2Fmodels%2Fvideo%2Fvideo-comment.ts;h=8e84bfc06ab0603429b4811c8837a73c8f93136f;hb=d3ea89759104e6c14b00443526f2c2a0a13aeb97;hp=d66f933ee714fd7ebffe7083882d6bf1f9aeea0b;hpb=bf1f650817dadfd5eeee9e5e0b6b6938c136e25d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index d66f933ee..8e84bfc06 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts @@ -6,18 +6,18 @@ import { import { VideoComment } from '../../../shared/models/videos/video-comment.model' import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' import { CONSTRAINTS_FIELDS } from '../../initializers' -import { ActorModel } from '../activitypub/actor' +import { AccountModel } from '../account/account' import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' enum ScopeNames { - WITH_ACTOR = 'WITH_ACTOR' + WITH_ACCOUNT = 'WITH_ACCOUNT' } @Scopes({ - [ScopeNames.WITH_ACTOR]: { + [ScopeNames.WITH_ACCOUNT]: { include: [ - () => ActorModel + () => AccountModel ] } }) @@ -84,17 +84,17 @@ export class VideoCommentModel extends Model { }) Video: VideoModel - @ForeignKey(() => ActorModel) + @ForeignKey(() => AccountModel) @Column - actorId: number + accountId: number - @BelongsTo(() => ActorModel, { + @BelongsTo(() => AccountModel, { foreignKey: { allowNull: false }, onDelete: 'CASCADE' }) - Actor: ActorModel + Account: AccountModel @AfterDestroy static sendDeleteIfOwned (instance: VideoCommentModel) { @@ -132,12 +132,13 @@ export class VideoCommentModel extends Model { limit: count, order: [ getSort(sort) ], where: { - videoId + videoId, + inReplyToCommentId: null } } return VideoCommentModel - .scope([ ScopeNames.WITH_ACTOR ]) + .scope([ ScopeNames.WITH_ACCOUNT ]) .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } @@ -146,7 +147,7 @@ export class VideoCommentModel extends Model { static listThreadCommentsForApi (videoId: number, threadId: number) { const query = { - order: [ 'id', 'ASC' ], + order: [ [ 'id', 'ASC' ] ], where: { videoId, [ Sequelize.Op.or ]: [ @@ -157,7 +158,7 @@ export class VideoCommentModel extends Model { } return VideoCommentModel - .scope([ ScopeNames.WITH_ACTOR ]) + .scope([ ScopeNames.WITH_ACCOUNT ]) .findAndCountAll(query) .then(({ rows, count }) => { return { total: count, data: rows } @@ -173,7 +174,10 @@ export class VideoCommentModel extends Model { inReplyToCommentId: this.inReplyToCommentId, videoId: this.videoId, createdAt: this.createdAt, - updatedAt: this.updatedAt + updatedAt: this.updatedAt, + account: { + name: this.Account.name + } } as VideoComment } }