diff options
author | Chocobozzz <me@florianbigard.com> | 2020-06-16 11:00:35 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2020-06-16 11:26:46 +0200 |
commit | 5c20a45518c3afc40c9494cad4a78def92e5e288 (patch) | |
tree | d4f6894b37394f3a40e6c58d34012bc55c05f55e /client/src/app/shared/users | |
parent | 64e0f8cf12c804a7a2fa582fd954f686cea9a45b (diff) | |
download | PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.tar.gz PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.tar.zst PeerTube-5c20a45518c3afc40c9494cad4a78def92e5e288.zip |
Fix anonymous nsfw policy
Diffstat (limited to 'client/src/app/shared/users')
-rw-r--r-- | client/src/app/shared/users/user.service.ts | 51 |
1 files changed, 40 insertions, 11 deletions
diff --git a/client/src/app/shared/users/user.service.ts b/client/src/app/shared/users/user.service.ts index 7c1ae5799..de1c8ec94 100644 --- a/client/src/app/shared/users/user.service.ts +++ b/client/src/app/shared/users/user.service.ts | |||
@@ -1,19 +1,20 @@ | |||
1 | import { from, Observable } from 'rxjs' | 1 | import { has } from 'lodash-es' |
2 | import { catchError, concatMap, map, shareReplay, toArray } from 'rxjs/operators' | 2 | import { BytesPipe } from 'ngx-pipes' |
3 | import { SortMeta } from 'primeng/api' | ||
4 | import { from, Observable, of } from 'rxjs' | ||
5 | import { catchError, concatMap, first, map, shareReplay, toArray, throttleTime, filter } from 'rxjs/operators' | ||
3 | import { HttpClient, HttpParams } from '@angular/common/http' | 6 | import { HttpClient, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 7 | import { Injectable } from '@angular/core' |
5 | import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' | 8 | import { AuthService } from '@app/core/auth' |
6 | import { environment } from '../../../environments/environment' | ||
7 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
8 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' | ||
9 | import { SortMeta } from 'primeng/api' | ||
10 | import { BytesPipe } from 'ngx-pipes' | ||
11 | import { I18n } from '@ngx-translate/i18n-polyfill' | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
12 | import { UserRegister } from '@shared/models/users/user-register.model' | 10 | import { UserRegister } from '@shared/models/users/user-register.model' |
13 | import { User } from './user.model' | ||
14 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' | 11 | import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' |
15 | import { has } from 'lodash-es' | 12 | import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' |
13 | import { Avatar } from '../../../../../shared/models/avatars/avatar.model' | ||
14 | import { environment } from '../../../environments/environment' | ||
16 | import { LocalStorageService, SessionStorageService } from '../misc/storage.service' | 15 | import { LocalStorageService, SessionStorageService } from '../misc/storage.service' |
16 | import { RestExtractor, RestPagination, RestService } from '../rest' | ||
17 | import { User } from './user.model' | ||
17 | 18 | ||
18 | @Injectable() | 19 | @Injectable() |
19 | export class UserService { | 20 | export class UserService { |
@@ -25,6 +26,7 @@ export class UserService { | |||
25 | 26 | ||
26 | constructor ( | 27 | constructor ( |
27 | private authHttp: HttpClient, | 28 | private authHttp: HttpClient, |
29 | private authService: AuthService, | ||
28 | private restExtractor: RestExtractor, | 30 | private restExtractor: RestExtractor, |
29 | private restService: RestService, | 31 | private restService: RestService, |
30 | private localStorageService: LocalStorageService, | 32 | private localStorageService: LocalStorageService, |
@@ -94,6 +96,21 @@ export class UserService { | |||
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
99 | listenAnonymousUpdate () { | ||
100 | return this.localStorageService.watch([ | ||
101 | User.KEYS.NSFW_POLICY, | ||
102 | User.KEYS.WEBTORRENT_ENABLED, | ||
103 | User.KEYS.AUTO_PLAY_VIDEO, | ||
104 | User.KEYS.AUTO_PLAY_VIDEO_PLAYLIST, | ||
105 | User.KEYS.THEME, | ||
106 | User.KEYS.VIDEO_LANGUAGES | ||
107 | ]).pipe( | ||
108 | throttleTime(200), | ||
109 | filter(() => this.authService.isLoggedIn() !== true), | ||
110 | map(() => this.getAnonymousUser()) | ||
111 | ) | ||
112 | } | ||
113 | |||
97 | deleteMe () { | 114 | deleteMe () { |
98 | const url = UserService.BASE_USERS_URL + 'me' | 115 | const url = UserService.BASE_USERS_URL + 'me' |
99 | 116 | ||
@@ -241,7 +258,7 @@ export class UserService { | |||
241 | } | 258 | } |
242 | 259 | ||
243 | getAnonymousUser () { | 260 | getAnonymousUser () { |
244 | let videoLanguages | 261 | let videoLanguages: string[] |
245 | 262 | ||
246 | try { | 263 | try { |
247 | videoLanguages = JSON.parse(this.localStorageService.getItem(User.KEYS.VIDEO_LANGUAGES)) | 264 | videoLanguages = JSON.parse(this.localStorageService.getItem(User.KEYS.VIDEO_LANGUAGES)) |
@@ -313,6 +330,18 @@ export class UserService { | |||
313 | ) | 330 | ) |
314 | } | 331 | } |
315 | 332 | ||
333 | getAnonymousOrLoggedUser () { | ||
334 | if (!this.authService.isLoggedIn()) { | ||
335 | return of(this.getAnonymousUser()) | ||
336 | } | ||
337 | |||
338 | return this.authService.userInformationLoaded | ||
339 | .pipe( | ||
340 | first(), | ||
341 | map(() => this.authService.getUser()) | ||
342 | ) | ||
343 | } | ||
344 | |||
316 | private formatUser (user: UserServerModel) { | 345 | private formatUser (user: UserServerModel) { |
317 | let videoQuota | 346 | let videoQuota |
318 | if (user.videoQuota === -1) { | 347 | if (user.videoQuota === -1) { |