1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor, Video } from '@app/shared/shared-main'
4 Account as AccountInterface,
5 VideoComment as VideoCommentServerModel,
6 VideoCommentAdmin as VideoCommentAdminServerModel
7 } from '@shared/models'
9 export class VideoComment implements VideoCommentServerModel {
14 inReplyToCommentId: number
16 createdAt: Date | string
17 updatedAt: Date | string
18 deletedAt: Date | string
20 account: AccountInterface
21 totalRepliesFromVideoAuthor: number
27 constructor (hash: VideoCommentServerModel) {
31 this.threadId = hash.threadId
32 this.inReplyToCommentId = hash.inReplyToCommentId
33 this.videoId = hash.videoId
34 this.createdAt = new Date(hash.createdAt.toString())
35 this.updatedAt = new Date(hash.updatedAt.toString())
36 this.deletedAt = hash.deletedAt ? new Date(hash.deletedAt.toString()) : null
37 this.isDeleted = hash.isDeleted
38 this.account = hash.account
39 this.totalRepliesFromVideoAuthor = hash.totalRepliesFromVideoAuthor
40 this.totalReplies = hash.totalReplies
43 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
45 const absoluteAPIUrl = getAbsoluteAPIUrl()
46 const thisHost = new URL(absoluteAPIUrl).host
47 this.isLocal = this.account.host.trim() === thisHost
52 export class VideoCommentAdmin implements VideoCommentAdminServerModel {
59 inReplyToCommentId: number
61 createdAt: Date | string
62 updatedAt: Date | string
64 account: AccountInterface & { localUrl?: string }
76 constructor (hash: VideoCommentAdminServerModel, textHtml: string) {
80 this.textHtml = textHtml
82 this.threadId = hash.threadId
83 this.inReplyToCommentId = hash.inReplyToCommentId
85 this.createdAt = new Date(hash.createdAt.toString())
86 this.updatedAt = new Date(hash.updatedAt.toString())
90 uuid: hash.video.uuid,
91 name: hash.video.name,
92 localUrl: Video.buildWatchUrl(hash.video)
95 this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
97 this.account = hash.account
100 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
102 this.account.localUrl = '/a/' + this.by