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