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