]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/core/auth/auth-user.model.ts
Add alert and hide upload view when no upload is possible (#2966)
[github/Chocobozzz/PeerTube.git] / client / src / app / core / auth / auth-user.model.ts
index 4ad904beb2389db37e482cf1c3e848ef91ba8f69..88b730938ab33a203abaefc3955dfc4c783a0a8f 100644 (file)
@@ -1,10 +1,17 @@
-import { peertubeLocalStorage } from '@app/shared/misc/peertube-web-storage'
-import { UserRight } from '../../../../../shared/models/users/user-right.enum'
-import { MyUser as ServerMyUserModel, User as ServerUserModel, MyUserSpecialPlaylist } from '../../../../../shared/models/users/user.model'
-// Do not use the barrel (dependency loop)
-import { hasUserRight, UserRole } from '../../../../../shared/models/users/user-role'
-import { User } from '../../shared/users/user.model'
-import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
+import { Observable, of } from 'rxjs'
+import { map } from 'rxjs/operators'
+import { User } from '@app/core/users/user.model'
+import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
+import {
+  hasUserRight,
+  MyUser as ServerMyUserModel,
+  MyUserSpecialPlaylist,
+  NSFWPolicyType,
+  User as ServerUserModel,
+  UserRight,
+  UserRole,
+  UserVideoQuota
+} from '@shared/models'
 
 export type TokenOptions = {
   accessToken: string
@@ -70,6 +77,8 @@ export class AuthUser extends User implements ServerMyUserModel {
   tokens: Tokens
   specialPlaylists: MyUserSpecialPlaylist[]
 
+  canSeeVideosLink = true
+
   static load () {
     const usernameLocalStorage = peertubeLocalStorage.getItem(this.KEYS.USERNAME)
     if (usernameLocalStorage) {
@@ -146,4 +155,26 @@ export class AuthUser extends User implements ServerMyUserModel {
     peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo))
     this.tokens.save()
   }
+
+  computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> {
+    if (!this.isUploadDisabled()) {
+      this.canSeeVideosLink = true
+      return of(this.canSeeVideosLink)
+    }
+
+    // Check if the user has videos
+    return quotaObservable.pipe(
+      map(({ videoQuotaUsed }) => {
+        if (videoQuotaUsed !== 0) {
+          // User already uploaded videos, so it can see the link
+          this.canSeeVideosLink = true
+        } else {
+          // No videos, no upload so the user don't need to see the videos link
+          this.canSeeVideosLink = false
+        }
+
+        return this.canSeeVideosLink
+      })
+    )
+  }
 }