aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/video
diff options
context:
space:
mode:
Diffstat (limited to 'server/models/video')
-rw-r--r--server/models/video/video-comment.ts43
1 files changed, 6 insertions, 37 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts
index 6eda32f05..58b75510d 100644
--- a/server/models/video/video-comment.ts
+++ b/server/models/video/video-comment.ts
@@ -106,6 +106,10 @@ enum ScopeNames {
106 required: true, 106 required: true,
107 include: [ 107 include: [
108 { 108 {
109 model: ActorModel,
110 required: true
111 },
112 {
109 model: AccountModel, 113 model: AccountModel,
110 required: true, 114 required: true,
111 include: [ 115 include: [
@@ -208,41 +212,6 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
208 }) 212 })
209 Account: AccountModel 213 Account: AccountModel
210 214
211 @BeforeDestroy
212 static async sendDeleteIfOwned (instance: VideoCommentModel, options) {
213 if (!instance.Account || !instance.Account.Actor) {
214 instance.Account = await instance.$get('Account', {
215 include: [ ActorModel ],
216 transaction: options.transaction
217 }) as AccountModel
218 }
219
220 if (!instance.Video) {
221 instance.Video = await instance.$get('Video', {
222 include: [
223 {
224 model: VideoChannelModel,
225 include: [
226 {
227 model: AccountModel,
228 include: [
229 {
230 model: ActorModel
231 }
232 ]
233 }
234 ]
235 }
236 ],
237 transaction: options.transaction
238 }) as VideoModel
239 }
240
241 if (instance.isOwned()) {
242 await sendDeleteVideoComment(instance, options.transaction)
243 }
244 }
245
246 static loadById (id: number, t?: Transaction) { 215 static loadById (id: number, t?: Transaction) {
247 const query: FindOptions = { 216 const query: FindOptions = {
248 where: { 217 where: {
@@ -269,7 +238,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
269 .findOne(query) 238 .findOne(query)
270 } 239 }
271 240
272 static loadByUrlAndPopulateAccount (url: string, t?: Transaction) { 241 static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction) {
273 const query: FindOptions = { 242 const query: FindOptions = {
274 where: { 243 where: {
275 url 244 url
@@ -278,7 +247,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> {
278 247
279 if (t !== undefined) query.transaction = t 248 if (t !== undefined) query.transaction = t
280 249
281 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT ]).findOne(query) 250 return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query)
282 } 251 }
283 252
284 static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction) { 253 static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction) {