aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-02-25 10:26:10 +0100
committerChocobozzz <me@florianbigard.com>2021-02-25 10:26:10 +0100
commit24d3352ce4b48bc9ff15e8c0af0c93df6d903e5e (patch)
tree9eac8bddfe2ddd86b4124a80c965673d86f37369 /client/src/app/core
parent0221f8c9b174c1c95b7348215f0d652bb1899c6b (diff)
downloadPeerTube-24d3352ce4b48bc9ff15e8c0af0c93df6d903e5e.tar.gz
PeerTube-24d3352ce4b48bc9ff15e8c0af0c93df6d903e5e.tar.zst
PeerTube-24d3352ce4b48bc9ff15e8c0af0c93df6d903e5e.zip
Fix anonymous user settings
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/users/user.service.ts40
1 files changed, 30 insertions, 10 deletions
diff --git a/client/src/app/core/users/user.service.ts b/client/src/app/core/users/user.service.ts
index f4850c3ba..16ea8aa1a 100644
--- a/client/src/app/core/users/user.service.ts
+++ b/client/src/app/core/users/user.service.ts
@@ -77,17 +77,34 @@ export class UserService {
77 } 77 }
78 78
79 updateMyAnonymousProfile (profile: UserUpdateMe) { 79 updateMyAnonymousProfile (profile: UserUpdateMe) {
80 try { 80 const localStorageKeys: { [ id in keyof UserUpdateMe ]: string } = {
81 this.localStorageService.setItem(UserLocalStorageKeys.NSFW_POLICY, profile.nsfwPolicy) 81 nsfwPolicy: UserLocalStorageKeys.NSFW_POLICY,
82 this.localStorageService.setItem(UserLocalStorageKeys.WEBTORRENT_ENABLED, profile.webTorrentEnabled) 82 webTorrentEnabled: UserLocalStorageKeys.WEBTORRENT_ENABLED,
83 autoPlayNextVideo: UserLocalStorageKeys.AUTO_PLAY_VIDEO,
84 autoPlayNextVideoPlaylist: UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST,
85 theme: UserLocalStorageKeys.THEME,
86 videoLanguages: UserLocalStorageKeys.VIDEO_LANGUAGES
87 }
83 88
84 this.localStorageService.setItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO, profile.autoPlayNextVideo) 89 const obj = Object.keys(localStorageKeys)
85 this.localStorageService.setItem(UserLocalStorageKeys.AUTO_PLAY_VIDEO_PLAYLIST, profile.autoPlayNextVideoPlaylist) 90 .filter(key => key in profile)
91 .map(key => ([ localStorageKeys[key], profile[key] ]))
86 92
87 this.localStorageService.setItem(UserLocalStorageKeys.THEME, profile.theme) 93 for (const [ key, value ] of obj) {
88 this.localStorageService.setItem(UserLocalStorageKeys.VIDEO_LANGUAGES, profile.videoLanguages) 94 try {
89 } catch (err) { 95 if (!value) {
90 console.error(`Cannot set item in localStorage. Likely due to a value impossible to stringify.`, err) 96 this.localStorageService.removeItem(key)
97 continue
98 }
99
100 const localStorageValue = typeof value === 'string'
101 ? value
102 : JSON.stringify(value)
103
104 this.localStorageService.setItem(key, localStorageValue)
105 } catch (err) {
106 console.error(`Cannot set ${key}->${value} in localStorage. Likely due to a value impossible to stringify.`, err)
107 }
91 } 108 }
92 } 109 }
93 110
@@ -266,7 +283,10 @@ export class UserService {
266 let videoLanguages: string[] 283 let videoLanguages: string[]
267 284
268 try { 285 try {
269 videoLanguages = JSON.parse(this.localStorageService.getItem(UserLocalStorageKeys.VIDEO_LANGUAGES)) 286 const languagesString = this.localStorageService.getItem(UserLocalStorageKeys.VIDEO_LANGUAGES)
287 videoLanguages = languagesString && languagesString !== 'undefined'
288 ? JSON.parse(languagesString)
289 : null
270 } catch (err) { 290 } catch (err) {
271 videoLanguages = null 291 videoLanguages = null
272 console.error('Cannot parse desired video languages from localStorage.', err) 292 console.error('Cannot parse desired video languages from localStorage.', err)