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.ts45
1 files changed, 41 insertions, 4 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index d2d8945c3..66fca2484 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -7,12 +7,14 @@ import { VideoCommentObject } from '../../../shared/models/activitypub/objects/v
7import { VideoComment } from '../../../shared/models/videos/video-comment.model' 7import { VideoComment } from '../../../shared/models/videos/video-comment.model'
8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' 8import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc'
9import { CONSTRAINTS_FIELDS } from '../../initializers' 9import { CONSTRAINTS_FIELDS } from '../../initializers'
10import { sendDeleteVideoComment } from '../../lib/activitypub/send'
10import { AccountModel } from '../account/account' 11import { AccountModel } from '../account/account'
11import { ActorModel } from '../activitypub/actor' 12import { ActorModel } from '../activitypub/actor'
12import { AvatarModel } from '../avatar/avatar' 13import { AvatarModel } from '../avatar/avatar'
13import { ServerModel } from '../server/server' 14import { ServerModel } from '../server/server'
14import { getSort, throwIfNotValid } from '../utils' 15import { getSort, throwIfNotValid } from '../utils'
15import { VideoModel } from './video' 16import { VideoModel } from './video'
17import { VideoChannelModel } from './video-channel'
16 18
17enum ScopeNames { 19enum ScopeNames {
18 WITH_ACCOUNT = 'WITH_ACCOUNT', 20 WITH_ACCOUNT = 'WITH_ACCOUNT',
@@ -70,7 +72,25 @@ enum ScopeNames {
70 include: [ 72 include: [
71 { 73 {
72 model: () => VideoModel, 74 model: () => VideoModel,
73 required: false 75 required: true,
76 include: [
77 {
78 model: () => VideoChannelModel.unscoped(),
79 required: true,
80 include: [
81 {
82 model: () => AccountModel,
83 required: true,
84 include: [
85 {
86 model: () => ActorModel,
87 required: true
88 }
89 ]
90 }
91 ]
92 }
93 ]
74 } 94 }
75 ] 95 ]
76 } 96 }
@@ -155,9 +175,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
155 Account: AccountModel 175 Account: AccountModel
156 176
157 @AfterDestroy 177 @AfterDestroy
158 static sendDeleteIfOwned (instance: VideoCommentModel) { 178 static async sendDeleteIfOwned (instance: VideoCommentModel) {
159 // TODO 179 if (instance.isOwned()) {
160 return undefined 180 await sendDeleteVideoComment(instance, undefined)
181 }
161 } 182 }
162 183
163 static loadById (id: number, t?: Sequelize.Transaction) { 184 static loadById (id: number, t?: Sequelize.Transaction) {
@@ -198,6 +219,18 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
198 return VideoCommentModel.findOne(query) 219 return VideoCommentModel.findOne(query)
199 } 220 }
200 221
222 static loadByUrlAndPopulateAccount (url: string, t?: Sequelize.Transaction) {
223 const query: IFindOptions<VideoCommentModel> = {
224 where: {
225 url
226 }
227 }
228
229 if (t !== undefined) query.transaction = t
230
231 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query)
232 }
233
201 static listThreadsForApi (videoId: number, start: number, count: number, sort: string) { 234 static listThreadsForApi (videoId: number, start: number, count: number, sort: string) {
202 const query = { 235 const query = {
203 offset: start, 236 offset: start,
@@ -237,6 +270,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
237 }) 270 })
238 } 271 }
239 272
273 isOwned () {
274 return this.Account.isOwned()
275 }
276
240 toFormattedJSON () { 277 toFormattedJSON () {
241 return { 278 return {
242 id: this.id, 279 id: this.id,