]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/users/user.model.ts
Add ability to choose what policy we have for NSFW videos
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / users / user.model.ts
index 7beea5910958aa9638715bdb465350420e830413..2bdc48a1dc81a381ba0cda7915e7f0069aca296d 100644 (file)
@@ -1,8 +1,6 @@
-import {
-  User as UserServerModel,
-  UserRole,
-  VideoChannel
-} from '../../../../../shared'
+import { hasUserRight, User as UserServerModel, UserRight, UserRole, VideoChannel } from '../../../../../shared'
+import { Account } from '../account/account.model'
+import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
 
 export type UserConstructorHash = {
   id: number,
@@ -10,12 +8,10 @@ export type UserConstructorHash = {
   email: string,
   role: UserRole,
   videoQuota?: number,
-  displayNSFW?: boolean,
+  nsfwPolicy?: NSFWPolicyType,
+  autoPlayVideo?: boolean,
   createdAt?: Date,
-  author?: {
-    id: number
-    uuid: string
-  },
+  account?: Account,
   videoChannels?: VideoChannel[]
 }
 export class User implements UserServerModel {
@@ -23,12 +19,10 @@ export class User implements UserServerModel {
   username: string
   email: string
   role: UserRole
-  displayNSFW: boolean
+  nsfwPolicy: NSFWPolicyType
+  autoPlayVideo: boolean
   videoQuota: number
-  author: {
-    id: number
-    uuid: string
-  }
+  account: Account
   videoChannels: VideoChannel[]
   createdAt: Date
 
@@ -37,7 +31,7 @@ export class User implements UserServerModel {
     this.username = hash.username
     this.email = hash.email
     this.role = hash.role
-    this.author = hash.author
+    this.account = hash.account
 
     if (hash.videoChannels !== undefined) {
       this.videoChannels = hash.videoChannels
@@ -47,8 +41,12 @@ export class User implements UserServerModel {
       this.videoQuota = hash.videoQuota
     }
 
-    if (hash.displayNSFW !== undefined) {
-      this.displayNSFW = hash.displayNSFW
+    if (hash.nsfwPolicy !== undefined) {
+      this.nsfwPolicy = hash.nsfwPolicy
+    }
+
+    if (hash.autoPlayVideo !== undefined) {
+      this.autoPlayVideo = hash.autoPlayVideo
     }
 
     if (hash.createdAt !== undefined) {
@@ -56,7 +54,17 @@ export class User implements UserServerModel {
     }
   }
 
-  isAdmin () {
-    return this.role === 'admin'
+  hasRight (right: UserRight) {
+    return hasUserRight(this.role, right)
+  }
+
+  getAvatarUrl () {
+    return Account.GET_ACCOUNT_AVATAR_URL(this.account)
+  }
+
+  patch (obj: UserServerModel) {
+    for (const key of Object.keys(obj)) {
+      this[key] = obj[key]
+    }
   }
 }