]>
Commit | Line | Data |
---|---|---|
276d9652 | 1 | import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared' |
0883b324 | 2 | import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' |
ad9e39fb | 3 | import { Account } from '@app/shared/account/account.model' |
0c237b19 | 4 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' |
69f616ab C |
5 | |
6 | export class User implements UserServerModel { | |
df98563e C |
7 | id: number |
8 | username: string | |
9 | email: string | |
fc2ec87a | 10 | emailVerified: boolean |
df98563e | 11 | role: UserRole |
0883b324 | 12 | nsfwPolicy: NSFWPolicyType |
276d9652 | 13 | |
ed638e53 | 14 | webTorrentEnabled: boolean |
7efe153b | 15 | autoPlayVideo: boolean |
276d9652 C |
16 | videosHistoryEnabled: boolean |
17 | ||
b0f9f39e | 18 | videoQuota: number |
bee0abff | 19 | videoQuotaDaily: number |
2295ce6c | 20 | account: Account |
404b54e1 | 21 | videoChannels: VideoChannel[] |
df98563e | 22 | createdAt: Date |
7da18e44 | 23 | |
eacb25c4 C |
24 | blocked: boolean |
25 | blockedReason?: string | |
26 | ||
276d9652 | 27 | constructor (hash: Partial<UserServerModel>) { |
df98563e C |
28 | this.id = hash.id |
29 | this.username = hash.username | |
30 | this.email = hash.email | |
31 | this.role = hash.role | |
ad9e39fb | 32 | |
eacb25c4 C |
33 | this.videoChannels = hash.videoChannels |
34 | this.videoQuota = hash.videoQuota | |
bee0abff | 35 | this.videoQuotaDaily = hash.videoQuotaDaily |
eacb25c4 | 36 | this.nsfwPolicy = hash.nsfwPolicy |
ed638e53 | 37 | this.webTorrentEnabled = hash.webTorrentEnabled |
276d9652 | 38 | this.videosHistoryEnabled = hash.videosHistoryEnabled |
eacb25c4 C |
39 | this.autoPlayVideo = hash.autoPlayVideo |
40 | this.createdAt = hash.createdAt | |
41 | this.blocked = hash.blocked | |
42 | this.blockedReason = hash.blockedReason | |
43 | ||
ad9e39fb C |
44 | if (hash.account !== undefined) { |
45 | this.account = new Account(hash.account) | |
46 | } | |
52d9f792 C |
47 | } |
48 | ||
49 | get accountAvatarUrl () { | |
50 | if (!this.account) return '' | |
d3e91a5f | 51 | |
52d9f792 | 52 | return this.account.avatarUrl |
7da18e44 C |
53 | } |
54 | ||
954605a8 C |
55 | hasRight (right: UserRight) { |
56 | return hasUserRight(this.role, right) | |
7da18e44 | 57 | } |
2295ce6c | 58 | |
ce5496d6 C |
59 | patch (obj: UserServerModel) { |
60 | for (const key of Object.keys(obj)) { | |
61 | this[key] = obj[key] | |
62 | } | |
d3e91a5f | 63 | |
ad9e39fb C |
64 | if (obj.account !== undefined) { |
65 | this.account = new Account(obj.account) | |
66 | } | |
d3e91a5f C |
67 | } |
68 | ||
0c237b19 | 69 | updateAccountAvatar (newAccountAvatar: Avatar) { |
52d9f792 | 70 | this.account.updateAvatar(newAccountAvatar) |
ce5496d6 | 71 | } |
7da18e44 | 72 | } |