X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fusers%2Fuser.model.ts;h=7707d7dda7ecc73bda9d2b7ec485de0b7c224b85;hb=dd4f25eea802fd88ea641d730432b56f562e0861;hp=b4be2270f8c82818db140ed7a3731d9f752f2388;hpb=ad9e39fb815d85e5e718c40540fa75471474fa17;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/users/user.model.ts b/client/src/app/shared/users/user.model.ts index b4be2270f..7707d7dda 100644 --- a/client/src/app/shared/users/user.model.ts +++ b/client/src/app/shared/users/user.model.ts @@ -1,71 +1,91 @@ -import { - Account as AccountServerModel, - hasUserRight, - User as UserServerModel, - UserRight, - UserRole, - VideoChannel -} from '../../../../../shared' +import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRight, UserRole, VideoChannel } from '../../../../../shared' import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type' -import { Actor } from '@app/shared/actor/actor.model' import { Account } from '@app/shared/account/account.model' +import { Avatar } from '../../../../../shared/models/avatars/avatar.model' +import { UserAdminFlag } from '@shared/models/users/user-flag.model' -export type UserConstructorHash = { - id: number, - username: string, - email: string, - role: UserRole, - videoQuota?: number, - nsfwPolicy?: NSFWPolicyType, - autoPlayVideo?: boolean, - createdAt?: Date, - account?: AccountServerModel, - videoChannels?: VideoChannel[] -} export class User implements UserServerModel { id: number username: string email: string - role: UserRole + pendingEmail: string | null + + emailVerified: boolean nsfwPolicy: NSFWPolicyType + + adminFlags?: UserAdminFlag + autoPlayVideo: boolean + autoPlayNextVideo: boolean + autoPlayNextVideoPlaylist: boolean + webTorrentEnabled: boolean + videosHistoryEnabled: boolean + videoLanguages: string[] + + role: UserRole + roleLabel: string + videoQuota: number + videoQuotaDaily: number + videoQuotaUsed?: number + videoQuotaUsedDaily?: number + + theme: string + account: Account - videoChannels: VideoChannel[] + notificationSettings?: UserNotificationSetting + videoChannels?: VideoChannel[] + + blocked: boolean + blockedReason?: string + + noInstanceConfigWarningModal: boolean + noWelcomeModal: boolean + createdAt: Date - accountAvatarUrl: string - constructor (hash: UserConstructorHash) { + constructor (hash: Partial) { this.id = hash.id this.username = hash.username this.email = hash.email + this.role = hash.role - if (hash.account !== undefined) { - this.account = new Account(hash.account) - } + this.videoChannels = hash.videoChannels - if (hash.videoChannels !== undefined) { - this.videoChannels = hash.videoChannels - } + this.videoQuota = hash.videoQuota + this.videoQuotaDaily = hash.videoQuotaDaily + this.videoQuotaUsed = hash.videoQuotaUsed + this.videoQuotaUsedDaily = hash.videoQuotaUsedDaily - if (hash.videoQuota !== undefined) { - this.videoQuota = hash.videoQuota - } + this.nsfwPolicy = hash.nsfwPolicy + this.webTorrentEnabled = hash.webTorrentEnabled + this.videosHistoryEnabled = hash.videosHistoryEnabled + this.autoPlayVideo = hash.autoPlayVideo - if (hash.nsfwPolicy !== undefined) { - this.nsfwPolicy = hash.nsfwPolicy - } + this.theme = hash.theme - if (hash.autoPlayVideo !== undefined) { - this.autoPlayVideo = hash.autoPlayVideo - } + this.adminFlags = hash.adminFlags + + this.blocked = hash.blocked + this.blockedReason = hash.blockedReason - if (hash.createdAt !== undefined) { - this.createdAt = hash.createdAt + this.noInstanceConfigWarningModal = hash.noInstanceConfigWarningModal + this.noWelcomeModal = hash.noWelcomeModal + + this.notificationSettings = hash.notificationSettings + + this.createdAt = hash.createdAt + + if (hash.account !== undefined) { + this.account = new Account(hash.account) } + } - this.updateComputedAttributes() + get accountAvatarUrl () { + if (!this.account) return '' + + return this.account.avatarUrl } hasRight (right: UserRight) { @@ -80,11 +100,9 @@ export class User implements UserServerModel { if (obj.account !== undefined) { this.account = new Account(obj.account) } - - this.updateComputedAttributes() } - private updateComputedAttributes () { - this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) + updateAccountAvatar (newAccountAvatar: Avatar) { + this.account.updateAvatar(newAccountAvatar) } }