1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Account, Actor } from '@app/shared/shared-main'
3 import { Account as AccountInterface, VideoComment as VideoCommentServerModel, VideoCommentAdmin as VideoCommentAdminServerModel } from '@shared/models'
5 export class VideoComment implements VideoCommentServerModel {
10 inReplyToCommentId: number
12 createdAt: Date | string
13 updatedAt: Date | string
14 deletedAt: Date | string
16 account: AccountInterface
17 totalRepliesFromVideoAuthor: number
20 accountAvatarUrl: string
24 constructor (hash: VideoCommentServerModel) {
28 this.threadId = hash.threadId
29 this.inReplyToCommentId = hash.inReplyToCommentId
30 this.videoId = hash.videoId
31 this.createdAt = new Date(hash.createdAt.toString())
32 this.updatedAt = new Date(hash.updatedAt.toString())
33 this.deletedAt = hash.deletedAt ? new Date(hash.deletedAt.toString()) : null
34 this.isDeleted = hash.isDeleted
35 this.account = hash.account
36 this.totalRepliesFromVideoAuthor = hash.totalRepliesFromVideoAuthor
37 this.totalReplies = hash.totalReplies
40 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
41 this.accountAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.account)
43 const absoluteAPIUrl = getAbsoluteAPIUrl()
44 const thisHost = new URL(absoluteAPIUrl).host
45 this.isLocal = this.account.host.trim() === thisHost
50 export class VideoCommentAdmin implements VideoCommentAdminServerModel {
57 inReplyToCommentId: number
59 createdAt: Date | string
60 updatedAt: Date | string
62 account: AccountInterface & { localUrl?: string }
73 accountAvatarUrl: string
75 constructor (hash: VideoCommentAdminServerModel, textHtml: string) {
79 this.textHtml = textHtml
81 this.threadId = hash.threadId
82 this.inReplyToCommentId = hash.inReplyToCommentId
84 this.createdAt = new Date(hash.createdAt.toString())
85 this.updatedAt = new Date(hash.updatedAt.toString())
89 uuid: hash.video.uuid,
90 name: hash.video.name,
91 localUrl: '/videos/watch/' + hash.video.uuid
94 this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
96 this.account = hash.account
99 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
100 this.accountAvatarUrl = Account.GET_ACTOR_AVATAR_URL(this.account)
102 this.account.localUrl = '/accounts/' + this.by