]> 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 4e7801550d05c5f2b5f0eeea2aa02db79c489600..88b730938ab33a203abaefc3955dfc4c783a0a8f 100644 (file)
@@ -1,3 +1,5 @@
+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 {
@@ -7,7 +9,8 @@ import {
   NSFWPolicyType,
   User as ServerUserModel,
   UserRight,
-  UserRole
+  UserRole,
+  UserVideoQuota
 } from '@shared/models'
 
 export type TokenOptions = {
@@ -74,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) {
@@ -150,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
+      })
+    )
+  }
 }