aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/users
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/users')
-rw-r--r--client/src/app/shared/users/user.service.ts51
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 @@
1import { from, Observable } from 'rxjs' 1import { has } from 'lodash-es'
2import { catchError, concatMap, map, shareReplay, toArray } from 'rxjs/operators' 2import { BytesPipe } from 'ngx-pipes'
3import { SortMeta } from 'primeng/api'
4import { from, Observable, of } from 'rxjs'
5import { catchError, concatMap, first, map, shareReplay, toArray, throttleTime, filter } from 'rxjs/operators'
3import { HttpClient, HttpParams } from '@angular/common/http' 6import { HttpClient, HttpParams } from '@angular/common/http'
4import { Injectable } from '@angular/core' 7import { Injectable } from '@angular/core'
5import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared' 8import { AuthService } from '@app/core/auth'
6import { environment } from '../../../environments/environment'
7import { RestExtractor, RestPagination, RestService } from '../rest'
8import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
9import { SortMeta } from 'primeng/api'
10import { BytesPipe } from 'ngx-pipes'
11import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
12import { UserRegister } from '@shared/models/users/user-register.model' 10import { UserRegister } from '@shared/models/users/user-register.model'
13import { User } from './user.model'
14import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type' 11import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
15import { has } from 'lodash-es' 12import { ResultList, User as UserServerModel, UserCreate, UserRole, UserUpdate, UserUpdateMe, UserVideoQuota } from '../../../../../shared'
13import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
14import { environment } from '../../../environments/environment'
16import { LocalStorageService, SessionStorageService } from '../misc/storage.service' 15import { LocalStorageService, SessionStorageService } from '../misc/storage.service'
16import { RestExtractor, RestPagination, RestService } from '../rest'
17import { User } from './user.model'
17 18
18@Injectable() 19@Injectable()
19export class UserService { 20export 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) {