]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/users/user.model.ts
add webtorrent opt-out settings
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
CommitLineData
ad9e39fb
C
1import {
2 Account as AccountServerModel,
3 hasUserRight,
4 User as UserServerModel,
5 UserRight,
6 UserRole,
7 VideoChannel
8} from '../../../../../shared'
0883b324 9import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
ad9e39fb 10import { Account } from '@app/shared/account/account.model'
0c237b19 11import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
64cc5e85 12import { WebTorrentPolicyType } from '../../../../../shared/models/users/user-webtorrent-policy.type'
69f616ab 13
404b54e1
C
14export type UserConstructorHash = {
15 id: number,
16 username: string,
17 email: string,
18 role: UserRole,
19 videoQuota?: number,
bee0abff 20 videoQuotaDaily?: number,
0883b324 21 nsfwPolicy?: NSFWPolicyType,
64cc5e85 22 webTorrentPolicy?: WebTorrentPolicyType,
7efe153b 23 autoPlayVideo?: boolean,
404b54e1 24 createdAt?: Date,
ad9e39fb 25 account?: AccountServerModel,
404b54e1 26 videoChannels?: VideoChannel[]
eacb25c4
C
27
28 blocked?: boolean
29 blockedReason?: string
404b54e1 30}
69f616ab 31export class User implements UserServerModel {
df98563e
C
32 id: number
33 username: string
34 email: string
35 role: UserRole
0883b324 36 nsfwPolicy: NSFWPolicyType
64cc5e85 37 webTorrentPolicy: WebTorrentPolicyType
7efe153b 38 autoPlayVideo: boolean
b0f9f39e 39 videoQuota: number
bee0abff 40 videoQuotaDaily: number
2295ce6c 41 account: Account
404b54e1 42 videoChannels: VideoChannel[]
df98563e 43 createdAt: Date
7da18e44 44
eacb25c4
C
45 blocked: boolean
46 blockedReason?: string
47
404b54e1 48 constructor (hash: UserConstructorHash) {
df98563e
C
49 this.id = hash.id
50 this.username = hash.username
51 this.email = hash.email
52 this.role = hash.role
ad9e39fb 53
eacb25c4
C
54 this.videoChannels = hash.videoChannels
55 this.videoQuota = hash.videoQuota
bee0abff 56 this.videoQuotaDaily = hash.videoQuotaDaily
eacb25c4 57 this.nsfwPolicy = hash.nsfwPolicy
64cc5e85 58 this.webTorrentPolicy = hash.webTorrentPolicy
eacb25c4
C
59 this.autoPlayVideo = hash.autoPlayVideo
60 this.createdAt = hash.createdAt
61 this.blocked = hash.blocked
62 this.blockedReason = hash.blockedReason
63
ad9e39fb
C
64 if (hash.account !== undefined) {
65 this.account = new Account(hash.account)
66 }
52d9f792
C
67 }
68
69 get accountAvatarUrl () {
70 if (!this.account) return ''
d3e91a5f 71
52d9f792 72 return this.account.avatarUrl
7da18e44
C
73 }
74
954605a8
C
75 hasRight (right: UserRight) {
76 return hasUserRight(this.role, right)
7da18e44 77 }
2295ce6c 78
ce5496d6
C
79 patch (obj: UserServerModel) {
80 for (const key of Object.keys(obj)) {
81 this[key] = obj[key]
82 }
d3e91a5f 83
ad9e39fb
C
84 if (obj.account !== undefined) {
85 this.account = new Account(obj.account)
86 }
d3e91a5f
C
87 }
88
0c237b19 89 updateAccountAvatar (newAccountAvatar: Avatar) {
52d9f792 90 this.account.updateAvatar(newAccountAvatar)
ce5496d6 91 }
7da18e44 92}