diff options
Diffstat (limited to 'client/src/app/core/auth')
-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 | } |