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