]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/shared-main/account/actor.model.ts
Add ability to report comments in front end
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-main / account / actor.model.ts
CommitLineData
67ed6552
C
1import { Actor as ActorServer, Avatar } from '@shared/models'
2import { getAbsoluteAPIUrl } from '@app/helpers'
d3e91a5f
C
3
4export abstract class Actor implements ActorServer {
5 id: number
d3e91a5f
C
6 url: string
7 name: string
8 host: string
9 followingCount: number
10 followersCount: number
db400f44
C
11 createdAt: Date | string
12 updatedAt: Date | string
d3e91a5f
C
13 avatar: Avatar
14
15 avatarUrl: string
16
d95d1559 17 static GET_ACTOR_AVATAR_URL (actor: { avatar?: { url?: string, path: string } }) {
5fb2e288 18 if (actor?.avatar?.url) return actor.avatar.url
d3e91a5f 19
5fb2e288
C
20 if (actor && actor.avatar) {
21 const absoluteAPIUrl = getAbsoluteAPIUrl()
22
23 return absoluteAPIUrl + actor.avatar.path
24 }
d3e91a5f 25
62fca05d 26 return this.GET_DEFAULT_AVATAR_URL()
c511c3f0
RK
27 }
28
29 static GET_DEFAULT_AVATAR_URL () {
d3e91a5f
C
30 return window.location.origin + '/client/assets/images/default-avatar.png'
31 }
32
e379f813 33 static CREATE_BY_STRING (accountName: string, host: string, forceHostname = false) {
d3e91a5f
C
34 const absoluteAPIUrl = getAbsoluteAPIUrl()
35 const thisHost = new URL(absoluteAPIUrl).host
36
e379f813 37 if (host.trim() === thisHost && !forceHostname) return accountName
d3e91a5f
C
38
39 return accountName + '@' + host
40 }
41
42 protected constructor (hash: ActorServer) {
43 this.id = hash.id
d3e91a5f
C
44 this.url = hash.url
45 this.name = hash.name
46 this.host = hash.host
47 this.followingCount = hash.followingCount
48 this.followersCount = hash.followersCount
8ca56654
C
49
50 if (hash.createdAt) this.createdAt = new Date(hash.createdAt.toString())
51 if (hash.updatedAt) this.updatedAt = new Date(hash.updatedAt.toString())
52
d3e91a5f
C
53 this.avatar = hash.avatar
54
52d9f792
C
55 this.updateComputedAttributes()
56 }
57
58 updateAvatar (newAvatar: Avatar) {
59 this.avatar = newAvatar
60
61 this.updateComputedAttributes()
62 }
63
64 private updateComputedAttributes () {
d3e91a5f
C
65 this.avatarUrl = Actor.GET_ACTOR_AVATAR_URL(this)
66 }
67}