]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/shared/shared-video-comment/video-comment.model.ts
Refactor video views
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-video-comment / video-comment.model.ts
1 import { getAbsoluteAPIUrl } from '@app/helpers'
2 import { Actor, Video } from '@app/shared/shared-main'
3 import {
4 Account as AccountInterface,
5 VideoComment as VideoCommentServerModel,
6 VideoCommentAdmin as VideoCommentAdminServerModel
7 } from '@shared/models'
8
9 export class VideoComment implements VideoCommentServerModel {
10 id: number
11 url: string
12 text: string
13 threadId: number
14 inReplyToCommentId: number
15 videoId: number
16 createdAt: Date | string
17 updatedAt: Date | string
18 deletedAt: Date | string
19 isDeleted: boolean
20 account: AccountInterface
21 totalRepliesFromVideoAuthor: number
22 totalReplies: number
23 by: string
24
25 isLocal: boolean
26
27 constructor (hash: VideoCommentServerModel) {
28 this.id = hash.id
29 this.url = hash.url
30 this.text = hash.text
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
41
42 if (this.account) {
43 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
44
45 const absoluteAPIUrl = getAbsoluteAPIUrl()
46 const thisHost = new URL(absoluteAPIUrl).host
47 this.isLocal = this.account.host.trim() === thisHost
48 }
49 }
50 }
51
52 export class VideoCommentAdmin implements VideoCommentAdminServerModel {
53 id: number
54 url: string
55 text: string
56 textHtml: string
57
58 threadId: number
59 inReplyToCommentId: number
60
61 createdAt: Date | string
62 updatedAt: Date | string
63
64 account: AccountInterface & { localUrl?: string }
65 localUrl: string
66
67 video: {
68 id: number
69 uuid: string
70 name: string
71 localUrl: string
72 }
73
74 by: string
75
76 constructor (hash: VideoCommentAdminServerModel, textHtml: string) {
77 this.id = hash.id
78 this.url = hash.url
79 this.text = hash.text
80 this.textHtml = textHtml
81
82 this.threadId = hash.threadId
83 this.inReplyToCommentId = hash.inReplyToCommentId
84
85 this.createdAt = new Date(hash.createdAt.toString())
86 this.updatedAt = new Date(hash.updatedAt.toString())
87
88 this.video = {
89 id: hash.video.id,
90 uuid: hash.video.uuid,
91 name: hash.video.name,
92 localUrl: Video.buildWatchUrl(hash.video)
93 }
94
95 this.localUrl = this.video.localUrl + ';threadId=' + this.threadId
96
97 this.account = hash.account
98
99 if (this.account) {
100 this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host)
101
102 this.account.localUrl = '/a/' + this.by
103 }
104 }
105 }