diff options
author | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2017-12-28 11:16:08 +0100 |
commit | da854ddd502cd70685ef779c673b9e63757b8aa0 (patch) | |
tree | 21501d170cceaa044a5f23449cbd2eb47fd6415d /server/models/video/video-comment.ts | |
parent | f40bbe3146553ef45515ee6b6d93ce6028f045ca (diff) | |
download | PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.gz PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.tar.zst PeerTube-da854ddd502cd70685ef779c673b9e63757b8aa0.zip |
Propagate old comment on new follow
Diffstat (limited to 'server/models/video/video-comment.ts')
-rw-r--r-- | server/models/video/video-comment.ts | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/server/models/video/video-comment.ts b/server/models/video/video-comment.ts index 8ceeb563a..1992c2dd8 100644 --- a/server/models/video/video-comment.ts +++ b/server/models/video/video-comment.ts | |||
@@ -5,7 +5,7 @@ import { | |||
5 | } from 'sequelize-typescript' | 5 | } from 'sequelize-typescript' |
6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' | 6 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
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' | 8 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
9 | import { CONSTRAINTS_FIELDS } from '../../initializers' | 9 | import { CONSTRAINTS_FIELDS } from '../../initializers' |
10 | import { AccountModel } from '../account/account' | 10 | import { AccountModel } from '../account/account' |
11 | import { ActorModel } from '../activitypub/actor' | 11 | import { ActorModel } from '../activitypub/actor' |
@@ -16,6 +16,7 @@ import { VideoModel } from './video' | |||
16 | enum ScopeNames { | 16 | enum ScopeNames { |
17 | WITH_ACCOUNT = 'WITH_ACCOUNT', | 17 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
18 | WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', | 18 | WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', |
19 | WITH_VIDEO = 'WITH_VIDEO', | ||
19 | ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API' | 20 | ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API' |
20 | } | 21 | } |
21 | 22 | ||
@@ -56,7 +57,15 @@ enum ScopeNames { | |||
56 | include: [ | 57 | include: [ |
57 | { | 58 | { |
58 | model: () => VideoCommentModel, | 59 | model: () => VideoCommentModel, |
59 | as: 'InReplyTo' | 60 | as: 'InReplyToVideoComment' |
61 | } | ||
62 | ] | ||
63 | }, | ||
64 | [ScopeNames.WITH_VIDEO]: { | ||
65 | include: [ | ||
66 | { | ||
67 | model: () => VideoModel, | ||
68 | required: false | ||
60 | } | 69 | } |
61 | ] | 70 | ] |
62 | } | 71 | } |
@@ -108,7 +117,7 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
108 | foreignKey: { | 117 | foreignKey: { |
109 | allowNull: true | 118 | allowNull: true |
110 | }, | 119 | }, |
111 | as: 'InReplyTo', | 120 | as: 'InReplyToVideoComment', |
112 | onDelete: 'CASCADE' | 121 | onDelete: 'CASCADE' |
113 | }) | 122 | }) |
114 | InReplyToVideoComment: VideoCommentModel | 123 | InReplyToVideoComment: VideoCommentModel |
@@ -155,6 +164,20 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
155 | return VideoCommentModel.findOne(query) | 164 | return VideoCommentModel.findOne(query) |
156 | } | 165 | } |
157 | 166 | ||
167 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Sequelize.Transaction) { | ||
168 | const query: IFindOptions<VideoCommentModel> = { | ||
169 | where: { | ||
170 | id | ||
171 | } | ||
172 | } | ||
173 | |||
174 | if (t !== undefined) query.transaction = t | ||
175 | |||
176 | return VideoCommentModel | ||
177 | .scope([ ScopeNames.WITH_VIDEO, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_IN_REPLY_TO ]) | ||
178 | .findOne(query) | ||
179 | } | ||
180 | |||
158 | static loadByUrl (url: string, t?: Sequelize.Transaction) { | 181 | static loadByUrl (url: string, t?: Sequelize.Transaction) { |
159 | const query: IFindOptions<VideoCommentModel> = { | 182 | const query: IFindOptions<VideoCommentModel> = { |
160 | where: { | 183 | where: { |
@@ -238,8 +261,10 @@ export class VideoCommentModel extends Model<VideoCommentModel> { | |||
238 | id: this.url, | 261 | id: this.url, |
239 | content: this.text, | 262 | content: this.text, |
240 | inReplyTo, | 263 | inReplyTo, |
264 | updated: this.updatedAt.toISOString(), | ||
241 | published: this.createdAt.toISOString(), | 265 | published: this.createdAt.toISOString(), |
242 | url: this.url | 266 | url: this.url, |
267 | attributedTo: this.Account.Actor.url | ||
243 | } | 268 | } |
244 | } | 269 | } |
245 | } | 270 | } |