]>
Commit | Line | Data |
---|---|---|
453e83ea | 1 | import { AllowNull, BelongsTo, Column, CreatedAt, DataType, ForeignKey, Is, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript' |
69222afa | 2 | import { ActivityTagObject, ActivityTombstoneObject } from '../../../shared/models/activitypub/objects/common-objects' |
ea44f375 | 3 | import { VideoCommentObject } from '../../../shared/models/activitypub/objects/video-comment-object' |
bf1f6508 | 4 | import { VideoComment } from '../../../shared/models/videos/video-comment.model' |
da854ddd | 5 | import { isActivityPubUrlValid } from '../../helpers/custom-validators/activitypub/misc' |
74dc3bca | 6 | import { CONSTRAINTS_FIELDS, WEBSERVER } from '../../initializers/constants' |
d3ea8975 | 7 | import { AccountModel } from '../account/account' |
4635f59d | 8 | import { ActorModel } from '../activitypub/actor' |
c1125bca | 9 | import { buildBlockedAccountSQL, buildLocalAccountIdsIn, getCommentSort, throwIfNotValid } from '../utils' |
6d852470 | 10 | import { VideoModel } from './video' |
4cb6d457 | 11 | import { VideoChannelModel } from './video-channel' |
7ad9b984 | 12 | import { getServerActor } from '../../helpers/utils' |
f7cc67b4 C |
13 | import { actorNameAlphabet } from '../../helpers/custom-validators/activitypub/actor' |
14 | import { regexpCapture } from '../../helpers/regexp' | |
15 | import { uniq } from 'lodash' | |
453e83ea C |
16 | import { FindOptions, Op, Order, ScopeOptions, Sequelize, Transaction } from 'sequelize' |
17 | import * as Bluebird from 'bluebird' | |
18 | import { | |
19 | MComment, | |
b5fecbf4 | 20 | MCommentAP, |
1ca9f7c3 | 21 | MCommentFormattable, |
453e83ea C |
22 | MCommentId, |
23 | MCommentOwner, | |
24 | MCommentOwnerReplyVideoLight, | |
25 | MCommentOwnerVideo, | |
26 | MCommentOwnerVideoFeed, | |
27 | MCommentOwnerVideoReply | |
28 | } from '../../typings/models/video' | |
29 | import { MUserAccountId } from '@server/typings/models' | |
68b6fd21 | 30 | import { VideoPrivacy } from '@shared/models' |
6d852470 | 31 | |
bf1f6508 | 32 | enum ScopeNames { |
ea44f375 | 33 | WITH_ACCOUNT = 'WITH_ACCOUNT', |
4635f59d | 34 | WITH_IN_REPLY_TO = 'WITH_IN_REPLY_TO', |
da854ddd | 35 | WITH_VIDEO = 'WITH_VIDEO', |
4635f59d | 36 | ATTRIBUTES_FOR_API = 'ATTRIBUTES_FOR_API' |
bf1f6508 C |
37 | } |
38 | ||
3acc5084 | 39 | @Scopes(() => ({ |
7ad9b984 C |
40 | [ScopeNames.ATTRIBUTES_FOR_API]: (serverAccountId: number, userAccountId?: number) => { |
41 | return { | |
42 | attributes: { | |
43 | include: [ | |
44 | [ | |
45 | Sequelize.literal( | |
46 | '(' + | |
47 | 'WITH "blocklist" AS (' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' + | |
48 | 'SELECT COUNT("replies"."id") - (' + | |
49 | 'SELECT COUNT("replies"."id") ' + | |
50 | 'FROM "videoComment" AS "replies" ' + | |
51 | 'WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ' + | |
52 | 'AND "accountId" IN (SELECT "id" FROM "blocklist")' + | |
53 | ')' + | |
54 | 'FROM "videoComment" AS "replies" ' + | |
55 | 'WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ' + | |
56 | 'AND "accountId" NOT IN (SELECT "id" FROM "blocklist")' + | |
57 | ')' | |
58 | ), | |
59 | 'totalReplies' | |
5b0413dd RK |
60 | ], |
61 | [ | |
62 | Sequelize.literal( | |
63 | '(' + | |
64 | 'SELECT COUNT("replies"."id") ' + | |
65 | 'FROM "videoComment" AS "replies" ' + | |
562724a1 C |
66 | 'INNER JOIN "video" ON "video"."id" = "replies"."videoId" ' + |
67 | 'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' + | |
5b0413dd | 68 | 'WHERE "replies"."originCommentId" = "VideoCommentModel"."id" ' + |
562724a1 | 69 | 'AND "replies"."accountId" = "videoChannel"."accountId"' + |
5b0413dd RK |
70 | ')' |
71 | ), | |
72 | 'totalRepliesFromVideoAuthor' | |
7ad9b984 | 73 | ] |
4635f59d | 74 | ] |
7ad9b984 | 75 | } |
3acc5084 | 76 | } as FindOptions |
4635f59d | 77 | }, |
d3ea8975 | 78 | [ScopeNames.WITH_ACCOUNT]: { |
bf1f6508 | 79 | include: [ |
4635f59d | 80 | { |
453e83ea | 81 | model: AccountModel |
4635f59d | 82 | } |
3acc5084 | 83 | ] |
ea44f375 C |
84 | }, |
85 | [ScopeNames.WITH_IN_REPLY_TO]: { | |
86 | include: [ | |
87 | { | |
3acc5084 | 88 | model: VideoCommentModel, |
da854ddd C |
89 | as: 'InReplyToVideoComment' |
90 | } | |
91 | ] | |
92 | }, | |
93 | [ScopeNames.WITH_VIDEO]: { | |
94 | include: [ | |
95 | { | |
3acc5084 | 96 | model: VideoModel, |
4cb6d457 C |
97 | required: true, |
98 | include: [ | |
99 | { | |
453e83ea | 100 | model: VideoChannelModel, |
4cb6d457 C |
101 | required: true, |
102 | include: [ | |
103 | { | |
3acc5084 | 104 | model: AccountModel, |
453e83ea | 105 | required: true |
4cb6d457 C |
106 | } |
107 | ] | |
108 | } | |
109 | ] | |
ea44f375 | 110 | } |
3acc5084 | 111 | ] |
bf1f6508 | 112 | } |
3acc5084 | 113 | })) |
6d852470 C |
114 | @Table({ |
115 | tableName: 'videoComment', | |
116 | indexes: [ | |
117 | { | |
118 | fields: [ 'videoId' ] | |
bf1f6508 C |
119 | }, |
120 | { | |
121 | fields: [ 'videoId', 'originCommentId' ] | |
0776d83f C |
122 | }, |
123 | { | |
124 | fields: [ 'url' ], | |
125 | unique: true | |
8cd72bd3 C |
126 | }, |
127 | { | |
128 | fields: [ 'accountId' ] | |
6d852470 C |
129 | } |
130 | ] | |
131 | }) | |
132 | export class VideoCommentModel extends Model<VideoCommentModel> { | |
133 | @CreatedAt | |
134 | createdAt: Date | |
135 | ||
136 | @UpdatedAt | |
137 | updatedAt: Date | |
138 | ||
69222afa JM |
139 | @AllowNull(true) |
140 | @Column(DataType.DATE) | |
141 | deletedAt: Date | |
142 | ||
6d852470 C |
143 | @AllowNull(false) |
144 | @Is('VideoCommentUrl', value => throwIfNotValid(value, isActivityPubUrlValid, 'url')) | |
145 | @Column(DataType.STRING(CONSTRAINTS_FIELDS.VIDEOS.URL.max)) | |
146 | url: string | |
147 | ||
148 | @AllowNull(false) | |
149 | @Column(DataType.TEXT) | |
150 | text: string | |
151 | ||
152 | @ForeignKey(() => VideoCommentModel) | |
153 | @Column | |
154 | originCommentId: number | |
155 | ||
156 | @BelongsTo(() => VideoCommentModel, { | |
157 | foreignKey: { | |
db799da3 | 158 | name: 'originCommentId', |
6d852470 C |
159 | allowNull: true |
160 | }, | |
db799da3 | 161 | as: 'OriginVideoComment', |
6d852470 C |
162 | onDelete: 'CASCADE' |
163 | }) | |
164 | OriginVideoComment: VideoCommentModel | |
165 | ||
166 | @ForeignKey(() => VideoCommentModel) | |
167 | @Column | |
168 | inReplyToCommentId: number | |
169 | ||
170 | @BelongsTo(() => VideoCommentModel, { | |
171 | foreignKey: { | |
db799da3 | 172 | name: 'inReplyToCommentId', |
6d852470 C |
173 | allowNull: true |
174 | }, | |
da854ddd | 175 | as: 'InReplyToVideoComment', |
6d852470 C |
176 | onDelete: 'CASCADE' |
177 | }) | |
c1e791ba | 178 | InReplyToVideoComment: VideoCommentModel | null |
6d852470 C |
179 | |
180 | @ForeignKey(() => VideoModel) | |
181 | @Column | |
182 | videoId: number | |
183 | ||
184 | @BelongsTo(() => VideoModel, { | |
185 | foreignKey: { | |
186 | allowNull: false | |
187 | }, | |
188 | onDelete: 'CASCADE' | |
189 | }) | |
190 | Video: VideoModel | |
191 | ||
d3ea8975 | 192 | @ForeignKey(() => AccountModel) |
6d852470 | 193 | @Column |
d3ea8975 | 194 | accountId: number |
6d852470 | 195 | |
d3ea8975 | 196 | @BelongsTo(() => AccountModel, { |
6d852470 | 197 | foreignKey: { |
69222afa | 198 | allowNull: true |
6d852470 C |
199 | }, |
200 | onDelete: 'CASCADE' | |
201 | }) | |
d3ea8975 | 202 | Account: AccountModel |
6d852470 | 203 | |
453e83ea | 204 | static loadById (id: number, t?: Transaction): Bluebird<MComment> { |
1735c825 | 205 | const query: FindOptions = { |
bf1f6508 C |
206 | where: { |
207 | id | |
208 | } | |
209 | } | |
210 | ||
211 | if (t !== undefined) query.transaction = t | |
212 | ||
213 | return VideoCommentModel.findOne(query) | |
214 | } | |
215 | ||
453e83ea | 216 | static loadByIdAndPopulateVideoAndAccountAndReply (id: number, t?: Transaction): Bluebird<MCommentOwnerVideoReply> { |
1735c825 | 217 | const query: FindOptions = { |
da854ddd C |
218 | where: { |
219 | id | |
220 | } | |
221 | } | |
222 | ||
223 | if (t !== undefined) query.transaction = t | |
224 | ||
225 | return VideoCommentModel | |
226 | .scope([ ScopeNames.WITH_VIDEO, ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_IN_REPLY_TO ]) | |
227 | .findOne(query) | |
228 | } | |
229 | ||
453e83ea | 230 | static loadByUrlAndPopulateAccountAndVideo (url: string, t?: Transaction): Bluebird<MCommentOwnerVideo> { |
1735c825 | 231 | const query: FindOptions = { |
6d852470 C |
232 | where: { |
233 | url | |
234 | } | |
235 | } | |
236 | ||
237 | if (t !== undefined) query.transaction = t | |
238 | ||
511765c9 | 239 | return VideoCommentModel.scope([ ScopeNames.WITH_ACCOUNT, ScopeNames.WITH_VIDEO ]).findOne(query) |
6d852470 | 240 | } |
bf1f6508 | 241 | |
453e83ea | 242 | static loadByUrlAndPopulateReplyAndVideoUrlAndAccount (url: string, t?: Transaction): Bluebird<MCommentOwnerReplyVideoLight> { |
1735c825 | 243 | const query: FindOptions = { |
4cb6d457 C |
244 | where: { |
245 | url | |
6b9c966f C |
246 | }, |
247 | include: [ | |
248 | { | |
249 | attributes: [ 'id', 'url' ], | |
250 | model: VideoModel.unscoped() | |
251 | } | |
252 | ] | |
4cb6d457 C |
253 | } |
254 | ||
255 | if (t !== undefined) query.transaction = t | |
256 | ||
6b9c966f | 257 | return VideoCommentModel.scope([ ScopeNames.WITH_IN_REPLY_TO, ScopeNames.WITH_ACCOUNT ]).findOne(query) |
4cb6d457 C |
258 | } |
259 | ||
b4055e1c | 260 | static async listThreadsForApi (parameters: { |
a1587156 C |
261 | videoId: number |
262 | start: number | |
263 | count: number | |
264 | sort: string | |
453e83ea | 265 | user?: MUserAccountId |
b4055e1c C |
266 | }) { |
267 | const { videoId, start, count, sort, user } = parameters | |
268 | ||
7ad9b984 C |
269 | const serverActor = await getServerActor() |
270 | const serverAccountId = serverActor.Account.id | |
65b21c96 | 271 | const userAccountId = user ? user.Account.id : undefined |
7ad9b984 | 272 | |
bf1f6508 C |
273 | const query = { |
274 | offset: start, | |
275 | limit: count, | |
c1125bca | 276 | order: getCommentSort(sort), |
bf1f6508 | 277 | where: { |
d3ea8975 | 278 | videoId, |
7ad9b984 C |
279 | inReplyToCommentId: null, |
280 | accountId: { | |
1735c825 | 281 | [Op.notIn]: Sequelize.literal( |
7ad9b984 C |
282 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' |
283 | ) | |
284 | } | |
bf1f6508 C |
285 | } |
286 | } | |
287 | ||
3acc5084 | 288 | const scopes: (string | ScopeOptions)[] = [ |
7ad9b984 C |
289 | ScopeNames.WITH_ACCOUNT, |
290 | { | |
291 | method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ] | |
292 | } | |
293 | ] | |
294 | ||
bf1f6508 | 295 | return VideoCommentModel |
7ad9b984 | 296 | .scope(scopes) |
bf1f6508 C |
297 | .findAndCountAll(query) |
298 | .then(({ rows, count }) => { | |
299 | return { total: count, data: rows } | |
300 | }) | |
301 | } | |
302 | ||
b4055e1c | 303 | static async listThreadCommentsForApi (parameters: { |
a1587156 C |
304 | videoId: number |
305 | threadId: number | |
453e83ea | 306 | user?: MUserAccountId |
b4055e1c C |
307 | }) { |
308 | const { videoId, threadId, user } = parameters | |
309 | ||
7ad9b984 C |
310 | const serverActor = await getServerActor() |
311 | const serverAccountId = serverActor.Account.id | |
65b21c96 | 312 | const userAccountId = user ? user.Account.id : undefined |
7ad9b984 | 313 | |
bf1f6508 | 314 | const query = { |
1735c825 | 315 | order: [ [ 'createdAt', 'ASC' ], [ 'updatedAt', 'ASC' ] ] as Order, |
bf1f6508 C |
316 | where: { |
317 | videoId, | |
a1587156 | 318 | [Op.or]: [ |
bf1f6508 C |
319 | { id: threadId }, |
320 | { originCommentId: threadId } | |
7ad9b984 C |
321 | ], |
322 | accountId: { | |
1735c825 | 323 | [Op.notIn]: Sequelize.literal( |
7ad9b984 C |
324 | '(' + buildBlockedAccountSQL(serverAccountId, userAccountId) + ')' |
325 | ) | |
326 | } | |
bf1f6508 C |
327 | } |
328 | } | |
329 | ||
7ad9b984 C |
330 | const scopes: any[] = [ |
331 | ScopeNames.WITH_ACCOUNT, | |
332 | { | |
333 | method: [ ScopeNames.ATTRIBUTES_FOR_API, serverAccountId, userAccountId ] | |
334 | } | |
335 | ] | |
336 | ||
bf1f6508 | 337 | return VideoCommentModel |
7ad9b984 | 338 | .scope(scopes) |
bf1f6508 C |
339 | .findAndCountAll(query) |
340 | .then(({ rows, count }) => { | |
341 | return { total: count, data: rows } | |
342 | }) | |
343 | } | |
344 | ||
453e83ea | 345 | static listThreadParentComments (comment: MCommentId, t: Transaction, order: 'ASC' | 'DESC' = 'ASC'): Bluebird<MCommentOwner[]> { |
d7e70384 | 346 | const query = { |
1735c825 | 347 | order: [ [ 'createdAt', order ] ] as Order, |
d7e70384 | 348 | where: { |
d7e70384 | 349 | id: { |
a1587156 | 350 | [Op.in]: Sequelize.literal('(' + |
a3cffab4 | 351 | 'WITH RECURSIVE children (id, "inReplyToCommentId") AS ( ' + |
f7cc67b4 C |
352 | `SELECT id, "inReplyToCommentId" FROM "videoComment" WHERE id = ${comment.id} ` + |
353 | 'UNION ' + | |
354 | 'SELECT "parent"."id", "parent"."inReplyToCommentId" FROM "videoComment" "parent" ' + | |
355 | 'INNER JOIN "children" ON "children"."inReplyToCommentId" = "parent"."id"' + | |
356 | ') ' + | |
a3cffab4 C |
357 | 'SELECT id FROM children' + |
358 | ')'), | |
a1587156 | 359 | [Op.ne]: comment.id |
d7e70384 C |
360 | } |
361 | }, | |
362 | transaction: t | |
363 | } | |
364 | ||
365 | return VideoCommentModel | |
366 | .scope([ ScopeNames.WITH_ACCOUNT ]) | |
367 | .findAll(query) | |
368 | } | |
369 | ||
1735c825 | 370 | static listAndCountByVideoId (videoId: number, start: number, count: number, t?: Transaction, order: 'ASC' | 'DESC' = 'ASC') { |
8fffe21a | 371 | const query = { |
1735c825 | 372 | order: [ [ 'createdAt', order ] ] as Order, |
9a4a9b6c C |
373 | offset: start, |
374 | limit: count, | |
8fffe21a C |
375 | where: { |
376 | videoId | |
377 | }, | |
378 | transaction: t | |
379 | } | |
380 | ||
453e83ea | 381 | return VideoCommentModel.findAndCountAll<MComment>(query) |
8fffe21a C |
382 | } |
383 | ||
453e83ea | 384 | static listForFeed (start: number, count: number, videoId?: number): Bluebird<MCommentOwnerVideoFeed[]> { |
fe3a55b0 | 385 | const query = { |
1735c825 | 386 | order: [ [ 'createdAt', 'DESC' ] ] as Order, |
9a4a9b6c C |
387 | offset: start, |
388 | limit: count, | |
193272b8 C |
389 | where: { |
390 | deletedAt: null | |
391 | }, | |
fe3a55b0 C |
392 | include: [ |
393 | { | |
4dae00e6 | 394 | attributes: [ 'name', 'uuid' ], |
fe3a55b0 | 395 | model: VideoModel.unscoped(), |
68b6fd21 C |
396 | required: true, |
397 | where: { | |
398 | privacy: VideoPrivacy.PUBLIC | |
399 | } | |
fe3a55b0 C |
400 | } |
401 | ] | |
402 | } | |
403 | ||
404 | if (videoId) query.where['videoId'] = videoId | |
405 | ||
406 | return VideoCommentModel | |
407 | .scope([ ScopeNames.WITH_ACCOUNT ]) | |
408 | .findAll(query) | |
409 | } | |
410 | ||
09cababd C |
411 | static async getStats () { |
412 | const totalLocalVideoComments = await VideoCommentModel.count({ | |
413 | include: [ | |
414 | { | |
415 | model: AccountModel, | |
416 | required: true, | |
417 | include: [ | |
418 | { | |
419 | model: ActorModel, | |
420 | required: true, | |
421 | where: { | |
422 | serverId: null | |
423 | } | |
424 | } | |
425 | ] | |
426 | } | |
427 | ] | |
428 | }) | |
429 | const totalVideoComments = await VideoCommentModel.count() | |
430 | ||
431 | return { | |
432 | totalLocalVideoComments, | |
433 | totalVideoComments | |
434 | } | |
435 | } | |
436 | ||
2ba92871 C |
437 | static cleanOldCommentsOf (videoId: number, beforeUpdatedAt: Date) { |
438 | const query = { | |
439 | where: { | |
440 | updatedAt: { | |
1735c825 | 441 | [Op.lt]: beforeUpdatedAt |
2ba92871 | 442 | }, |
6b9c966f C |
443 | videoId, |
444 | accountId: { | |
445 | [Op.notIn]: buildLocalAccountIdsIn() | |
970ceac0 | 446 | } |
6b9c966f | 447 | } |
2ba92871 C |
448 | } |
449 | ||
450 | return VideoCommentModel.destroy(query) | |
451 | } | |
452 | ||
cef534ed C |
453 | getCommentStaticPath () { |
454 | return this.Video.getWatchStaticPath() + ';threadId=' + this.getThreadId() | |
455 | } | |
456 | ||
d7e70384 C |
457 | getThreadId (): number { |
458 | return this.originCommentId || this.id | |
459 | } | |
460 | ||
4cb6d457 | 461 | isOwned () { |
69222afa JM |
462 | if (!this.Account) { |
463 | return false | |
464 | } | |
465 | ||
4cb6d457 C |
466 | return this.Account.isOwned() |
467 | } | |
468 | ||
69222afa | 469 | isDeleted () { |
a1587156 | 470 | return this.deletedAt !== null |
69222afa JM |
471 | } |
472 | ||
f7cc67b4 | 473 | extractMentions () { |
1f6d57e3 | 474 | let result: string[] = [] |
f7cc67b4 C |
475 | |
476 | const localMention = `@(${actorNameAlphabet}+)` | |
6dd9de95 | 477 | const remoteMention = `${localMention}@${WEBSERVER.HOST}` |
f7cc67b4 | 478 | |
1f6d57e3 C |
479 | const mentionRegex = this.isOwned() |
480 | ? '(?:(?:' + remoteMention + ')|(?:' + localMention + '))' // Include local mentions? | |
481 | : '(?:' + remoteMention + ')' | |
482 | ||
483 | const firstMentionRegex = new RegExp(`^${mentionRegex} `, 'g') | |
484 | const endMentionRegex = new RegExp(` ${mentionRegex}$`, 'g') | |
f7cc67b4 | 485 | const remoteMentionsRegex = new RegExp(' ' + remoteMention + ' ', 'g') |
f7cc67b4 | 486 | |
1f6d57e3 C |
487 | result = result.concat( |
488 | regexpCapture(this.text, firstMentionRegex) | |
489 | .map(([ , username1, username2 ]) => username1 || username2), | |
f7cc67b4 | 490 | |
1f6d57e3 C |
491 | regexpCapture(this.text, endMentionRegex) |
492 | .map(([ , username1, username2 ]) => username1 || username2), | |
493 | ||
494 | regexpCapture(this.text, remoteMentionsRegex) | |
495 | .map(([ , username ]) => username) | |
496 | ) | |
f7cc67b4 | 497 | |
1f6d57e3 C |
498 | // Include local mentions |
499 | if (this.isOwned()) { | |
500 | const localMentionsRegex = new RegExp(' ' + localMention + ' ', 'g') | |
f7cc67b4 | 501 | |
1f6d57e3 C |
502 | result = result.concat( |
503 | regexpCapture(this.text, localMentionsRegex) | |
504 | .map(([ , username ]) => username) | |
f7cc67b4 | 505 | ) |
1f6d57e3 C |
506 | } |
507 | ||
508 | return uniq(result) | |
f7cc67b4 C |
509 | } |
510 | ||
1ca9f7c3 | 511 | toFormattedJSON (this: MCommentFormattable) { |
bf1f6508 C |
512 | return { |
513 | id: this.id, | |
514 | url: this.url, | |
515 | text: this.text, | |
516 | threadId: this.originCommentId || this.id, | |
d50acfab | 517 | inReplyToCommentId: this.inReplyToCommentId || null, |
bf1f6508 C |
518 | videoId: this.videoId, |
519 | createdAt: this.createdAt, | |
d3ea8975 | 520 | updatedAt: this.updatedAt, |
69222afa JM |
521 | deletedAt: this.deletedAt, |
522 | isDeleted: this.isDeleted(), | |
5b0413dd | 523 | totalRepliesFromVideoAuthor: this.get('totalRepliesFromVideoAuthor') || 0, |
4635f59d | 524 | totalReplies: this.get('totalReplies') || 0, |
69222afa | 525 | account: this.Account ? this.Account.toFormattedJSON() : null |
bf1f6508 C |
526 | } as VideoComment |
527 | } | |
ea44f375 | 528 | |
69222afa | 529 | toActivityPubObject (this: MCommentAP, threadParentComments: MCommentOwner[]): VideoCommentObject | ActivityTombstoneObject { |
b5206dfc JM |
530 | let inReplyTo: string |
531 | // New thread, so in AS we reply to the video | |
532 | if (this.inReplyToCommentId === null) { | |
533 | inReplyTo = this.Video.url | |
534 | } else { | |
535 | inReplyTo = this.InReplyToVideoComment.url | |
536 | } | |
537 | ||
69222afa JM |
538 | if (this.isDeleted()) { |
539 | return { | |
540 | id: this.url, | |
541 | type: 'Tombstone', | |
542 | formerType: 'Note', | |
b5206dfc | 543 | inReplyTo, |
69222afa JM |
544 | published: this.createdAt.toISOString(), |
545 | updated: this.updatedAt.toISOString(), | |
546 | deleted: this.deletedAt.toISOString() | |
547 | } | |
548 | } | |
549 | ||
d7e70384 C |
550 | const tag: ActivityTagObject[] = [] |
551 | for (const parentComment of threadParentComments) { | |
b5206dfc JM |
552 | if (!parentComment.Account) continue |
553 | ||
d7e70384 C |
554 | const actor = parentComment.Account.Actor |
555 | ||
556 | tag.push({ | |
557 | type: 'Mention', | |
558 | href: actor.url, | |
559 | name: `@${actor.preferredUsername}@${actor.getHost()}` | |
560 | }) | |
561 | } | |
562 | ||
ea44f375 C |
563 | return { |
564 | type: 'Note' as 'Note', | |
565 | id: this.url, | |
566 | content: this.text, | |
567 | inReplyTo, | |
da854ddd | 568 | updated: this.updatedAt.toISOString(), |
ea44f375 | 569 | published: this.createdAt.toISOString(), |
da854ddd | 570 | url: this.url, |
d7e70384 C |
571 | attributedTo: this.Account.Actor.url, |
572 | tag | |
ea44f375 C |
573 | } |
574 | } | |
6d852470 | 575 | } |