diff options
author | Kim <1877318+kimsible@users.noreply.github.com> | 2020-07-28 15:18:38 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-28 15:18:38 +0200 |
commit | dfe3f7b72ef46401206f6f461077a7984a0c72f0 (patch) | |
tree | 775a747f2dd4bc098afc2ec254792e2e8e8cbbb4 /client/src/app/core/auth/auth-user.model.ts | |
parent | 0579dee3b29e301838387f53b91b58bff2ffb19a (diff) | |
download | PeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.tar.gz PeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.tar.zst PeerTube-dfe3f7b72ef46401206f6f461077a7984a0c72f0.zip |
Add alert and hide upload view when no upload is possible (#2966)
* Add alert and hide upload view when no upload is possible
* Add about instance link to alert
* Hide videos and imports links when no upload is possible
* Correct curly spacing lint
* Put logic canUpload to User model + add isHidden param to to-menu-dropdown
* Use canSeeVideoLinks from user model
* Rename and change logic canUpload to isUploadDisabled
* Use isDisplayed() method intead of isHidden value
* Refactor client and check videos count using quota
Co-authored-by: kimsible <kimsible@users.noreply.github.com>
Co-authored-by: Chocobozzz <me@florianbigard.com>
Diffstat (limited to 'client/src/app/core/auth/auth-user.model.ts')
-rw-r--r-- | client/src/app/core/auth/auth-user.model.ts | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 4e7801550..88b730938 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts | |||
@@ -1,3 +1,5 @@ | |||
1 | import { Observable, of } from 'rxjs' | ||
2 | import { map } from 'rxjs/operators' | ||
1 | import { User } from '@app/core/users/user.model' | 3 | import { User } from '@app/core/users/user.model' |
2 | import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' | 4 | import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' |
3 | import { | 5 | import { |
@@ -7,7 +9,8 @@ import { | |||
7 | NSFWPolicyType, | 9 | NSFWPolicyType, |
8 | User as ServerUserModel, | 10 | User as ServerUserModel, |
9 | UserRight, | 11 | UserRight, |
10 | UserRole | 12 | UserRole, |
13 | UserVideoQuota | ||
11 | } from '@shared/models' | 14 | } from '@shared/models' |
12 | 15 | ||
13 | export type TokenOptions = { | 16 | export type TokenOptions = { |
@@ -74,6 +77,8 @@ export class AuthUser extends User implements ServerMyUserModel { | |||
74 | tokens: Tokens | 77 | tokens: Tokens |
75 | specialPlaylists: MyUserSpecialPlaylist[] | 78 | specialPlaylists: MyUserSpecialPlaylist[] |
76 | 79 | ||
80 | canSeeVideosLink = true | ||
81 | |||
77 | static load () { | 82 | static load () { |
78 | const usernameLocalStorage = peertubeLocalStorage.getItem(this.KEYS.USERNAME) | 83 | const usernameLocalStorage = peertubeLocalStorage.getItem(this.KEYS.USERNAME) |
79 | if (usernameLocalStorage) { | 84 | if (usernameLocalStorage) { |
@@ -150,4 +155,26 @@ export class AuthUser extends User implements ServerMyUserModel { | |||
150 | peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) | 155 | peertubeLocalStorage.setItem(AuthUser.KEYS.AUTO_PLAY_VIDEO, JSON.stringify(this.autoPlayVideo)) |
151 | this.tokens.save() | 156 | this.tokens.save() |
152 | } | 157 | } |
158 | |||
159 | computeCanSeeVideosLink (quotaObservable: Observable<UserVideoQuota>): Observable<boolean> { | ||
160 | if (!this.isUploadDisabled()) { | ||
161 | this.canSeeVideosLink = true | ||
162 | return of(this.canSeeVideosLink) | ||
163 | } | ||
164 | |||
165 | // Check if the user has videos | ||
166 | return quotaObservable.pipe( | ||
167 | map(({ videoQuotaUsed }) => { | ||
168 | if (videoQuotaUsed !== 0) { | ||
169 | // User already uploaded videos, so it can see the link | ||
170 | this.canSeeVideosLink = true | ||
171 | } else { | ||
172 | // No videos, no upload so the user don't need to see the videos link | ||
173 | this.canSeeVideosLink = false | ||
174 | } | ||
175 | |||
176 | return this.canSeeVideosLink | ||
177 | }) | ||
178 | ) | ||
179 | } | ||
153 | } | 180 | } |