aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video/video-comment.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r--server/models/video/video-comment.ts30
1 files changed, 17 insertions, 13 deletions
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 {
6import { VideoComment } from '../../../shared/models/videos/video-comment.model' 6import { VideoComment } from '../../../shared/models/videos/video-comment.model'
7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub' 7import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub'
8import { CONSTRAINTS_FIELDS } from '../../initializers' 8import { CONSTRAINTS_FIELDS } from '../../initializers'
9import { ActorModel } from '../activitypub/actor' 9import { AccountModel } from '../account/account'
10import { getSort, throwIfNotValid } from '../utils' 10import { getSort, throwIfNotValid } from '../utils'
11import { VideoModel } from './video' 11import { VideoModel } from './video'
12 12
13enum ScopeNames { 13enum ScopeNames {
14 WITH_ACTOR = 'WITH_ACTOR' 14 WITH_ACCOUNT = 'WITH_ACCOUNT'
15} 15}
16 16
17@Scopes({ 17@Scopes({
18 [ScopeNames.WITH_ACTOR]: { 18 [ScopeNames.WITH_ACCOUNT]: {
19 include: [ 19 include: [
20 () => ActorModel 20 () => AccountModel
21 ] 21 ]
22 } 22 }
23}) 23})
@@ -84,17 +84,17 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
84 }) 84 })
85 Video: VideoModel 85 Video: VideoModel
86 86
87 @ForeignKey(() => ActorModel) 87 @ForeignKey(() => AccountModel)
88 @Column 88 @Column
89 actorId: number 89 accountId: number
90 90
91 @BelongsTo(() => ActorModel, { 91 @BelongsTo(() => AccountModel, {
92 foreignKey: { 92 foreignKey: {
93 allowNull: false 93 allowNull: false
94 }, 94 },
95 onDelete: 'CASCADE' 95 onDelete: 'CASCADE'
96 }) 96 })
97 Actor: ActorModel 97 Account: AccountModel
98 98
99 @AfterDestroy 99 @AfterDestroy
100 static sendDeleteIfOwned (instance: VideoCommentModel) { 100 static sendDeleteIfOwned (instance: VideoCommentModel) {
@@ -132,12 +132,13 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
132 limit: count, 132 limit: count,
133 order: [ getSort(sort) ], 133 order: [ getSort(sort) ],
134 where: { 134 where: {
135 videoId 135 videoId,
136 inReplyToCommentId: null
136 } 137 }
137 } 138 }
138 139
139 return VideoCommentModel 140 return VideoCommentModel
140 .scope([ ScopeNames.WITH_ACTOR ]) 141 .scope([ ScopeNames.WITH_ACCOUNT ])
141 .findAndCountAll(query) 142 .findAndCountAll(query)
142 .then(({ rows, count }) => { 143 .then(({ rows, count }) => {
143 return { total: count, data: rows } 144 return { total: count, data: rows }
@@ -146,7 +147,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
146 147
147 static listThreadCommentsForApi (videoId: number, threadId: number) { 148 static listThreadCommentsForApi (videoId: number, threadId: number) {
148 const query = { 149 const query = {
149 order: [ 'id', 'ASC' ], 150 order: [ [ 'id', 'ASC' ] ],
150 where: { 151 where: {
151 videoId, 152 videoId,
152 [ Sequelize.Op.or ]: [ 153 [ Sequelize.Op.or ]: [
@@ -157,7 +158,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
157 } 158 }
158 159
159 return VideoCommentModel 160 return VideoCommentModel
160 .scope([ ScopeNames.WITH_ACTOR ]) 161 .scope([ ScopeNames.WITH_ACCOUNT ])
161 .findAndCountAll(query) 162 .findAndCountAll(query)
162 .then(({ rows, count }) => { 163 .then(({ rows, count }) => {
163 return { total: count, data: rows } 164 return { total: count, data: rows }
@@ -173,7 +174,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
173 inReplyToCommentId: this.inReplyToCommentId, 174 inReplyToCommentId: this.inReplyToCommentId,
174 videoId: this.videoId, 175 videoId: this.videoId,
175 createdAt: this.createdAt, 176 createdAt: this.createdAt,
176 updatedAt: this.updatedAt 177 updatedAt: this.updatedAt,
178 account: {
179 name: this.Account.name
180 }
177 } as VideoComment 181 } as VideoComment
178 } 182 }
179} 183}