Fix user video languages settings

pull/3112/head
Chocobozzz 2020-08-20 10:34:40 +02:00
parent 8054669f11
commit a9f6802e7d
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 35 additions and 11 deletions

View File

@ -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 + ''
})
}
}