aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/users
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/users')
-rw-r--r--client/src/app/core/users/user.model.ts3
-rw-r--r--client/src/app/core/users/user.service.ts55
2 files changed, 23 insertions, 35 deletions
diff --git a/client/src/app/core/users/user.model.ts b/client/src/app/core/users/user.model.ts
index f0d3a08b8..7c9569ed4 100644
--- a/client/src/app/core/users/user.model.ts
+++ b/client/src/app/core/users/user.model.ts
@@ -10,11 +10,8 @@ import {
10 UserRole, 10 UserRole,
11 VideoChannel 11 VideoChannel
12} from '@shared/models' 12} from '@shared/models'
13import { UserKeys } from '@root-helpers/user-keys'
14 13
15export class User implements UserServerModel { 14export class User implements UserServerModel {
16 static KEYS = UserKeys
17
18 id: number 15 id: number
19 username: string 16 username: string
20 email: string 17 email: string
diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts
index c98b3844c..aac2a0206 100644
--- a/client/src/app/core/users/user.service.ts
+++ b/client/src/app/core/users/user.service.ts
@@ -1,4 +1,3 @@
1import { has } from 'lodash-es'
2import { BytesPipe } from 'ngx-pipes' 1import { BytesPipe } from 'ngx-pipes'
3import { SortMeta } from 'primeng/api' 2import { SortMeta } from 'primeng/api'
4import { from, Observable, of } from 'rxjs' 3import { from, Observable, of } from 'rxjs'
@@ -7,6 +6,7 @@ import { HttpClient, HttpParams } from '@angular/common/http'
7import { Injectable } from '@angular/core' 6import { Injectable } from '@angular/core'
8import { AuthService } from '@app/core/auth' 7import { AuthService } from '@app/core/auth'
9import { I18n } from '@ngx-translate/i18n-polyfill' 8import { I18n } from '@ngx-translate/i18n-polyfill'
9import { UserLocalStorageKeys } from '@root-helpers/users'
10import { 10import {
11 Avatar, 11 Avatar,
12 NSFWPolicyType, 12 NSFWPolicyType,
@@ -81,37 +81,28 @@ export class UserService {
81 } 81 }
82 82
83 updateMyAnonymousProfile (profile: UserUpdateMe) { 83 updateMyAnonymousProfile (profile: UserUpdateMe) {
84 const supportedKeys = { 84 try {
85 // local storage keys 85 this.localStorageService.setItem(UserLocalStorageKeys.NSFW_POLICY, profile.nsfwPolicy)
86 nsfwPolicy: (val: NSFWPolicyType) => this.localStorageService.setItem(User.KEYS.NSFW_POLICY, val), 86 this.localStorageService.setItem(UserLocalStorageKeys.WEBTORRENT_ENABLED, profile.webTorrentEnabled)
87 webTorrentEnabled: (val: boolean) => this.localStorageService.setItem(User.KEYS.WEBTORRENT_ENABLED, String(val)),
88 autoPlayVideo: (val: boolean) => this.localStorageService.setItem(User.KEYS.AUTO_PLAY_VIDEO, String(val)),
89 autoPlayNextVideoPlaylist: (val: boolean) => this.localStorageService.setItem(User.KEYS.AUTO_PLAY_VIDEO_PLAYLIST, String(val)),
90 theme: (val: string) => this.localStorageService.setItem(User.KEYS.THEME, val),
91 videoLanguages: (val: string[]) => this.localStorageService.setItem(User.KEYS.VIDEO_LANGUAGES, JSON.stringify(val)),
92 87
93 // session storage keys 88 this.localStorageService.setItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO, profile.autoPlayNextVideo)
94 autoPlayNextVideo: (val: boolean) => 89 this.localStorageService.setItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST, profile.autoPlayNextVideoPlaylist)
95 this.sessionStorageService.setItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO, String(val))
96 }
97 90
98 for (const key of Object.keys(profile)) { 91 this.localStorageService.setItem(UserLocalStorageKeys.THEME, profile.theme)
99 try { 92 this.localStorageService.setItem(UserLocalStorageKeys.VIDEO_LANGUAGES, profile.videoLanguages)
100 if (has(supportedKeys, key)) supportedKeys[key](profile[key]) 93 } catch (err) {
101 } catch (err) { 94 console.error(`Cannot set item in localStorage. Likely due to a value impossible to stringify.`, err)
102 console.error(`Cannot set item ${key} in localStorage. Likely due to a value impossible to stringify.`, err)
103 }
104 } 95 }
105 } 96 }
106 97
107 listenAnonymousUpdate () { 98 listenAnonymousUpdate () {
108 return this.localStorageService.watch([ 99 return this.localStorageService.watch([
109 User.KEYS.NSFW_POLICY, 100 UserLocalStorageKeys.NSFW_POLICY,
110 User.KEYS.WEBTORRENT_ENABLED, 101 UserLocalStorageKeys.WEBTORRENT_ENABLED,
111 User.KEYS.AUTO_PLAY_VIDEO, 102 UserLocalStorageKeys.AUTO_PLAY_VIDEO,
112 User.KEYS.AUTO_PLAY_VIDEO_PLAYLIST, 103 UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST,
113 User.KEYS.THEME, 104 UserLocalStorageKeys.THEME,
114 User.KEYS.VIDEO_LANGUAGES 105 UserLocalStorageKeys.VIDEO_LANGUAGES
115 ]).pipe( 106 ]).pipe(
116 throttleTime(200), 107 throttleTime(200),
117 filter(() => this.authService.isLoggedIn() !== true), 108 filter(() => this.authService.isLoggedIn() !== true),
@@ -269,7 +260,7 @@ export class UserService {
269 let videoLanguages: string[] 260 let videoLanguages: string[]
270 261
271 try { 262 try {
272 videoLanguages = JSON.parse(this.localStorageService.getItem(User.KEYS.VIDEO_LANGUAGES)) 263 videoLanguages = JSON.parse(this.localStorageService.getItem(UserLocalStorageKeys.VIDEO_LANGUAGES))
273 } catch (err) { 264 } catch (err) {
274 videoLanguages = null 265 videoLanguages = null
275 console.error('Cannot parse desired video languages from localStorage.', err) 266 console.error('Cannot parse desired video languages from localStorage.', err)
@@ -277,16 +268,16 @@ export class UserService {
277 268
278 return new User({ 269 return new User({
279 // local storage keys 270 // local storage keys
280 nsfwPolicy: this.localStorageService.getItem(User.KEYS.NSFW_POLICY) as NSFWPolicyType, 271 nsfwPolicy: this.localStorageService.getItem(UserLocalStorageKeys.NSFW_POLICY) as NSFWPolicyType,
281 webTorrentEnabled: this.localStorageService.getItem(User.KEYS.WEBTORRENT_ENABLED) !== 'false', 272 webTorrentEnabled: this.localStorageService.getItem(UserLocalStorageKeys.WEBTORRENT_ENABLED) !== 'false',
282 theme: this.localStorageService.getItem(User.KEYS.THEME) || 'instance-default', 273 theme: this.localStorageService.getItem(UserLocalStorageKeys.THEME) || 'instance-default',
283 videoLanguages, 274 videoLanguages,
284 275
285 autoPlayNextVideoPlaylist: this.localStorageService.getItem(User.KEYS.AUTO_PLAY_VIDEO_PLAYLIST) !== 'false', 276 autoPlayNextVideoPlaylist: this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST) !== 'false',
286 autoPlayVideo: this.localStorageService.getItem(User.KEYS.AUTO_PLAY_VIDEO) === 'true', 277 autoPlayVideo: this.localStorageService.getItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO) === 'true',
287 278
288 // session storage keys 279 // session storage keys
289 autoPlayNextVideo: this.sessionStorageService.getItem(User.KEYS.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true' 280 autoPlayNextVideo: this.sessionStorageService.getItem(UserLocalStorageKeys.SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO) === 'true'
290 }) 281 })
291 } 282 }
292 283