diff options
author | Chocobozzz <me@florianbigard.com> | 2018-01-04 11:19:16 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-01-04 11:19:16 +0100 |
commit | 4cb6d4578893db310297d7e118ce2fb7ecb952a3 (patch) | |
tree | a89a2e2062ba7bb91e922f07a7950ee51e090ccf /server/models | |
parent | cf117aaafc1e9ae1ab4c388fc5d2e5ba9349efee (diff) | |
download | PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.gz PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.tar.zst PeerTube-4cb6d4578893db310297d7e118ce2fb7ecb952a3.zip |
Add ability to delete comments
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/activitypub/actor.ts | 1 | ||||
-rw-r--r-- | server/models/video/video-comment.ts | 45 | ||||
-rw-r--r-- | server/models/video/video.ts | 46 |
3 files changed, 81 insertions, 11 deletions
diff --git a/server/models/activitypub/actor.ts b/server/models/activitypub/actor.ts index 2ef7c77a2..ed7fcfe27 100644 --- a/server/models/activitypub/actor.ts +++ b/server/models/activitypub/actor.ts | |||
@@ -271,6 +271,7 @@ export class ActorModel extends Model<ActorModel> { | |||
271 | 271 | ||
272 | return { | 272 | return { |
273 | id: this.id, | 273 | id: this.id, |
274 | url: this.url, | ||
274 | uuid: this.uuid, | 275 | uuid: this.uuid, |
275 | host: this.getHost(), | 276 | host: this.getHost(), |
276 | score, | 277 | score, |
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 | |||
7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' | 7 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' | 8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
9 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 9 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
10 | import { sendDeleteVideoComment } from '../../lib/activitypub/send' | ||
10 | import { AccountModel } from '../account/account' | 11 | import { AccountModel } from '../account/account' |
11 | import { ActorModel } from '../activitypub/actor' | 12 | import { ActorModel } from '../activitypub/actor' |
12 | import { AvatarModel } from '../avatar/avatar' | 13 | import { AvatarModel } from '../avatar/avatar' |
13 | import { ServerModel } from '../server/server' | 14 | import { ServerModel } from '../server/server' |
14 | import { getSort, throwIfNotValid } from '../utils' | 15 | import { getSort, throwIfNotValid } from '../utils' |
15 | import { VideoModel } from './video' | 16 | import { VideoModel } from './video' |
17 | import { VideoChannelModel } from './video-channel' | ||
16 | 18 | ||
17 | enum ScopeNames { | 19 | enum 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, |
diff --git a/server/models/video/video.ts b/server/models/video/video.ts index c4b716cd2..4d15c2a50 100644 --- a/server/models/video/video.ts +++ b/server/models/video/video.ts | |||
@@ -43,7 +43,8 @@ import { VideoTagModel } from './video-tag' | |||
43 | 43 | ||
44 | enum ScopeNames { | 44 | enum ScopeNames { |
45 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', | 45 | AVAILABLE_FOR_LIST = 'AVAILABLE_FOR_LIST', |
46 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 46 | WITH_ACCOUNT_API = 'WITH_ACCOUNT_API', |
47 | WITH_ACCOUNT_DETAILS = 'WITH_ACCOUNT_DETAILS', | ||
47 | WITH_TAGS = 'WITH_TAGS', | 48 | WITH_TAGS = 'WITH_TAGS', |
48 | WITH_FILES = 'WITH_FILES', | 49 | WITH_FILES = 'WITH_FILES', |
49 | WITH_SHARES = 'WITH_SHARES', | 50 | WITH_SHARES = 'WITH_SHARES', |
@@ -62,7 +63,35 @@ enum ScopeNames { | |||
62 | privacy: VideoPrivacy.PUBLIC | 63 | privacy: VideoPrivacy.PUBLIC |
63 | } | 64 | } |
64 | }, | 65 | }, |
65 | [ScopeNames.WITH_ACCOUNT]: { | 66 | [ScopeNames.WITH_ACCOUNT_API]: { |
67 | include: [ | ||
68 | { | ||
69 | model: () => VideoChannelModel.unscoped(), | ||
70 | required: true, | ||
71 | include: [ | ||
72 | { | ||
73 | attributes: [ 'name' ], | ||
74 | model: () => AccountModel.unscoped(), | ||
75 | required: true, | ||
76 | include: [ | ||
77 | { | ||
78 | attributes: [ 'serverId' ], | ||
79 | model: () => ActorModel.unscoped(), | ||
80 | required: true, | ||
81 | include: [ | ||
82 | { | ||
83 | model: () => ServerModel.unscoped(), | ||
84 | required: false | ||
85 | } | ||
86 | ] | ||
87 | } | ||
88 | ] | ||
89 | } | ||
90 | ] | ||
91 | } | ||
92 | ] | ||
93 | }, | ||
94 | [ScopeNames.WITH_ACCOUNT_DETAILS]: { | ||
66 | include: [ | 95 | include: [ |
67 | { | 96 | { |
68 | model: () => VideoChannelModel, | 97 | model: () => VideoChannelModel, |
@@ -146,6 +175,9 @@ enum ScopeNames { | |||
146 | }, | 175 | }, |
147 | { | 176 | { |
148 | fields: [ 'channelId' ] | 177 | fields: [ 'channelId' ] |
178 | }, | ||
179 | { | ||
180 | fields: [ 'id', 'privacy' ] | ||
149 | } | 181 | } |
150 | ] | 182 | ] |
151 | }) | 183 | }) |
@@ -461,7 +493,7 @@ export class VideoModel extends Model<VideoModel> { | |||
461 | order: [ getSort(sort) ] | 493 | order: [ getSort(sort) ] |
462 | } | 494 | } |
463 | 495 | ||
464 | return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT ]) | 496 | return VideoModel.scope([ ScopeNames.AVAILABLE_FOR_LIST, ScopeNames.WITH_ACCOUNT_API ]) |
465 | .findAndCountAll(query) | 497 | .findAndCountAll(query) |
466 | .then(({ rows, count }) => { | 498 | .then(({ rows, count }) => { |
467 | return { | 499 | return { |
@@ -496,7 +528,7 @@ export class VideoModel extends Model<VideoModel> { | |||
496 | 528 | ||
497 | if (t !== undefined) query.transaction = t | 529 | if (t !== undefined) query.transaction = t |
498 | 530 | ||
499 | return VideoModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_FILES ]).findOne(query) | 531 | return VideoModel.scope([ ScopeNames.WITH_ACCOUNT_DETAILS, ScopeNames.WITH_FILES ]).findOne(query) |
500 | } | 532 | } |
501 | 533 | ||
502 | static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) { | 534 | static loadByUUIDOrURL (uuid: string, url: string, t?: Sequelize.Transaction) { |
@@ -520,7 +552,7 @@ export class VideoModel extends Model<VideoModel> { | |||
520 | } | 552 | } |
521 | 553 | ||
522 | return VideoModel | 554 | return VideoModel |
523 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ]) | 555 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ]) |
524 | .findById(id, options) | 556 | .findById(id, options) |
525 | } | 557 | } |
526 | 558 | ||
@@ -545,7 +577,7 @@ export class VideoModel extends Model<VideoModel> { | |||
545 | } | 577 | } |
546 | 578 | ||
547 | return VideoModel | 579 | return VideoModel |
548 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT ]) | 580 | .scope([ ScopeNames.WITH_TAGS, ScopeNames.WITH_FILES, ScopeNames.WITH_ACCOUNT_DETAILS ]) |
549 | .findOne(options) | 581 | .findOne(options) |
550 | } | 582 | } |
551 | 583 | ||
@@ -563,7 +595,7 @@ export class VideoModel extends Model<VideoModel> { | |||
563 | ScopeNames.WITH_SHARES, | 595 | ScopeNames.WITH_SHARES, |
564 | ScopeNames.WITH_TAGS, | 596 | ScopeNames.WITH_TAGS, |
565 | ScopeNames.WITH_FILES, | 597 | ScopeNames.WITH_FILES, |
566 | ScopeNames.WITH_ACCOUNT, | 598 | ScopeNames.WITH_ACCOUNT_DETAILS, |
567 | ScopeNames.WITH_COMMENTS | 599 | ScopeNames.WITH_COMMENTS |
568 | ]) | 600 | ]) |
569 | .findOne(options) | 601 | .findOne(options) |