From a9f6802e7dac4f21599076bc1119bb6ff16961dc Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 20 Aug 2020 10:34:40 +0200 Subject: Fix user video languages settings --- .../user-video-settings.component.ts | 46 ++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'client/src/app/shared/shared-user-settings') diff --git a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts index ab77f6f9c..2497e001c 100644 --- a/client/src/app/shared/shared-user-settings/user-video-settings.component.ts +++ b/client/src/app/shared/shared-user-settings/user-video-settings.component.ts @@ -95,27 +95,22 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, const autoPlayVideo = this.form.value['autoPlayVideo'] const autoPlayNextVideo = this.form.value['autoPlayNextVideo'] - let videoLanguages: string[] = this.form.value['videoLanguages'] + const videoLanguagesForm = this.form.value['videoLanguages'] - if (Array.isArray(videoLanguages)) { - if (videoLanguages.length > 20) { + if (Array.isArray(videoLanguagesForm)) { + if (videoLanguagesForm.length > 20) { this.notifier.error($localize`Too many languages are enabled. Please enable them all or stay below 20 enabled languages.`) return } - if (videoLanguages.length === 0) { + if (videoLanguagesForm.length === 0) { this.notifier.error($localize`You need to enable at least 1 video language.`) return } - - if ( - videoLanguages.length === this.languageItems.length || - (videoLanguages.length === 1 && videoLanguages[0] === this.allLanguagesGroup) - ) { - videoLanguages = null // null means "All" - } } + const videoLanguages = this.getVideoLanguages(videoLanguagesForm) + let details: UserUpdateMe = { nsfwPolicy, webTorrentEnabled, @@ -124,6 +119,10 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, videoLanguages } + if (videoLanguages) { + details = Object.assign(details, videoLanguages) + } + if (onlyKeys) details = pick(details, onlyKeys) if (this.authService.isLoggedIn()) { @@ -141,4 +140,29 @@ export class UserVideoSettingsComponent extends FormReactive implements OnInit, if (this.notifyOnUpdate) this.notifier.success($localize`Display/Video settings updated.`) } } + + private getVideoLanguages (videoLanguages: ItemSelectCheckboxValue[]) { + if (!Array.isArray(videoLanguages)) return undefined + + // null means "All" + if (videoLanguages.length === this.languageItems.length) return null + + if (videoLanguages.length === 1) { + const videoLanguage = videoLanguages[0] + + if (typeof videoLanguage === 'string') { + if (videoLanguage === this.allLanguagesGroup) return null + } else { + if (videoLanguage.group === this.allLanguagesGroup) return null + } + } + + return videoLanguages.map(l => { + if (typeof l === 'string') return l + + if (l.group) return l.group + + return l.id + '' + }) + } } -- cgit v1.2.3