aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+my-account/my-account-settings
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+my-account/my-account-settings')
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts13
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts10
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts5
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/index.ts1
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html17
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.scss21
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts89
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts11
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts9
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-settings.component.html4
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-settings.component.ts9
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/index.ts1
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html75
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scss24
-rw-r--r--client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts142
15 files changed, 23 insertions, 408 deletions
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts
index 9d406805f..5444b97ae 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-change-email/my-account-change-email.component.ts
@@ -1,12 +1,10 @@
1import { forkJoin } from 'rxjs'
2import { tap } from 'rxjs/operators'
1import { Component, OnInit } from '@angular/core' 3import { Component, OnInit } from '@angular/core'
2import { AuthService, Notifier, ServerService } from '@app/core' 4import { AuthService, ServerService, UserService } from '@app/core'
3import { FormReactive, UserService } from '../../../shared' 5import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
4import { I18n } from '@ngx-translate/i18n-polyfill' 6import { I18n } from '@ngx-translate/i18n-polyfill'
5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 7import { User } from '@shared/models'
6import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7import { User } from '../../../../../../shared'
8import { tap } from 'rxjs/operators'
9import { forkJoin } from 'rxjs'
10 8
11@Component({ 9@Component({
12 selector: 'my-account-change-email', 10 selector: 'my-account-change-email',
@@ -21,7 +19,6 @@ export class MyAccountChangeEmailComponent extends FormReactive implements OnIni
21 constructor ( 19 constructor (
22 protected formValidatorService: FormValidatorService, 20 protected formValidatorService: FormValidatorService,
23 private userValidatorsService: UserValidatorsService, 21 private userValidatorsService: UserValidatorsService,
24 private notifier: Notifier,
25 private authService: AuthService, 22 private authService: AuthService,
26 private userService: UserService, 23 private userService: UserService,
27 private serverService: ServerService, 24 private serverService: ServerService,
diff --git a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
index cbb068c7c..6a16f8a2c 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-change-password/my-account-change-password.component.ts
@@ -1,11 +1,9 @@
1import { filter } from 'rxjs/operators'
1import { Component, OnInit } from '@angular/core' 2import { Component, OnInit } from '@angular/core'
2import { AuthService, Notifier } from '@app/core' 3import { AuthService, Notifier, UserService } from '@app/core'
3import { FormReactive, UserService } from '../../../shared' 4import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
4import { I18n } from '@ngx-translate/i18n-polyfill' 5import { I18n } from '@ngx-translate/i18n-polyfill'
5import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' 6import { User } from '@shared/models'
6import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
7import { filter } from 'rxjs/operators'
8import { User } from '../../../../../../shared'
9 7
10@Component({ 8@Component({
11 selector: 'my-account-change-password', 9 selector: 'my-account-change-password',
diff --git a/client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts b/client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts
index 25d862867..ae6ac5387 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-danger-zone/my-account-danger-zone.component.ts
@@ -1,9 +1,6 @@
1import { Component, Input } from '@angular/core' 1import { Component, Input } from '@angular/core'
2import { Notifier } from '@app/core' 2import { AuthService, ConfirmService, Notifier, RedirectService, User, UserService } from '@app/core'
3import { AuthService, ConfirmService, RedirectService } from '../../../core'
4import { UserService } from '../../../shared'
5import { I18n } from '@ngx-translate/i18n-polyfill' 3import { I18n } from '@ngx-translate/i18n-polyfill'
6import { User } from '@app/shared'
7 4
8@Component({ 5@Component({
9 selector: 'my-account-danger-zone', 6 selector: 'my-account-danger-zone',
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/index.ts b/client/src/app/+my-account/my-account-settings/my-account-interface/index.ts
deleted file mode 100644
index 62fce79a8..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './my-account-interface-settings.component'
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html
deleted file mode 100644
index 0d0ddc0f2..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.html
+++ /dev/null
@@ -1,17 +0,0 @@
1<form role="form" (ngSubmit)="updateInterfaceSettings()" [formGroup]="form">
2
3 <div class="form-group">
4 <label i18n for="theme">Theme</label>
5
6 <div class="peertube-select-container">
7 <select formControlName="theme" id="theme" class="form-control">
8 <option i18n value="instance-default">instance default</option>
9 <option i18n value="default">peertube default</option>
10
11 <option *ngFor="let theme of availableThemes" [value]="theme">{{ theme }}</option>
12 </select>
13 </div>
14 </div>
15
16 <input *ngIf="!reactiveUpdate" type="submit" class="mt-0" i18n-value value="Save" [disabled]="!form.valid">
17</form>
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.scss b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.scss
deleted file mode 100644
index 7818dfc02..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.scss
+++ /dev/null
@@ -1,21 +0,0 @@
1@import '_variables';
2@import '_mixins';
3
4label {
5 font-weight: $font-regular;
6 font-size: 100%;
7}
8
9input[type=submit] {
10 @include peertube-button;
11 @include orange-button;
12
13 display: block;
14 margin-top: 15px;
15}
16
17.peertube-select-container {
18 @include peertube-select-container(340px);
19
20 margin-bottom: 30px;
21}
diff --git a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts
deleted file mode 100644
index b6c17c0e3..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-interface/my-account-interface-settings.component.ts
+++ /dev/null
@@ -1,89 +0,0 @@
1import { Component, Input, OnInit, OnDestroy } from '@angular/core'
2import { Notifier, ServerService } from '@app/core'
3import { ServerConfig, UserUpdateMe } from '../../../../../../shared'
4import { AuthService } from '../../../core'
5import { FormReactive } from '../../../shared/forms/form-reactive'
6import { User, UserService } from '../../../shared/users'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9import { Subject, Subscription } from 'rxjs'
10
11@Component({
12 selector: 'my-account-interface-settings',
13 templateUrl: './my-account-interface-settings.component.html',
14 styleUrls: [ './my-account-interface-settings.component.scss' ]
15})
16export class MyAccountInterfaceSettingsComponent extends FormReactive implements OnInit, OnDestroy {
17 @Input() user: User = null
18 @Input() reactiveUpdate = false
19 @Input() notifyOnUpdate = true
20 @Input() userInformationLoaded: Subject<any>
21
22 formValuesWatcher: Subscription
23
24 private serverConfig: ServerConfig
25
26 constructor (
27 protected formValidatorService: FormValidatorService,
28 private authService: AuthService,
29 private notifier: Notifier,
30 private userService: UserService,
31 private serverService: ServerService,
32 private i18n: I18n
33 ) {
34 super()
35 }
36
37 get availableThemes () {
38 return this.serverConfig.theme.registered
39 .map(t => t.name)
40 }
41
42 ngOnInit () {
43 this.serverConfig = this.serverService.getTmpConfig()
44 this.serverService.getConfig()
45 .subscribe(config => this.serverConfig = config)
46
47 this.buildForm({
48 theme: null
49 })
50
51 this.userInformationLoaded
52 .subscribe(() => {
53 this.form.patchValue({
54 theme: this.user.theme
55 })
56
57 if (this.reactiveUpdate) {
58 this.formValuesWatcher = this.form.valueChanges.subscribe(val => this.updateInterfaceSettings())
59 }
60 })
61 }
62
63 ngOnDestroy () {
64 this.formValuesWatcher?.unsubscribe()
65 }
66
67 updateInterfaceSettings () {
68 const theme = this.form.value['theme']
69
70 const details: UserUpdateMe = {
71 theme
72 }
73
74 if (this.authService.isLoggedIn()) {
75 this.userService.updateMyProfile(details).subscribe(
76 () => {
77 this.authService.refreshUserInformation()
78
79 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
80 },
81
82 err => this.notifier.error(err.message)
83 )
84 } else {
85 this.userService.updateMyAnonymousProfile(details)
86 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Interface settings updated.'))
87 }
88 }
89}
diff --git a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts
index af17a0352..cfa514b26 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-notification-preferences/my-account-notification-preferences.component.ts
@@ -1,11 +1,10 @@
1import { debounce } from 'lodash-es'
2import { Subject } from 'rxjs'
1import { Component, Input, OnInit } from '@angular/core' 3import { Component, Input, OnInit } from '@angular/core'
2import { User } from '@app/shared' 4import { Notifier, ServerService, User } from '@app/core'
5import { UserNotificationService } from '@app/shared/shared-main'
3import { I18n } from '@ngx-translate/i18n-polyfill' 6import { I18n } from '@ngx-translate/i18n-polyfill'
4import { Subject } from 'rxjs' 7import { UserNotificationSetting, UserNotificationSettingValue, UserRight } from '@shared/models'
5import { UserNotificationSetting, UserNotificationSettingValue, UserRight } from '../../../../../../shared'
6import { Notifier, ServerService } from '@app/core'
7import { debounce } from 'lodash-es'
8import { UserNotificationService } from '@app/shared/users/user-notification.service'
9 8
10@Component({ 9@Component({
11 selector: 'my-account-notification-preferences', 10 selector: 'my-account-notification-preferences',
diff --git a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
index fcad5a6c2..b0d8494e7 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-profile/my-account-profile.component.ts
@@ -1,11 +1,8 @@
1import { Subject } from 'rxjs'
1import { Component, Input, OnInit } from '@angular/core' 2import { Component, Input, OnInit } from '@angular/core'
2import { Notifier } from '@app/core' 3import { Notifier, User, UserService } from '@app/core'
3import { FormReactive, UserService } from '../../../shared' 4import { FormReactive, FormValidatorService, UserValidatorsService } from '@app/shared/shared-forms'
4import { User } from '@app/shared'
5import { I18n } from '@ngx-translate/i18n-polyfill' 5import { I18n } from '@ngx-translate/i18n-polyfill'
6import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
7import { Subject } from 'rxjs'
8import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
9 6
10@Component({ 7@Component({
11 selector: 'my-account-profile', 8 selector: 'my-account-profile',
diff --git a/client/src/app/+my-account/my-account-settings/my-account-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-settings.component.html
index 040b2130f..2826d8d83 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-settings.component.html
+++ b/client/src/app/+my-account/my-account-settings/my-account-settings.component.html
@@ -34,7 +34,7 @@
34 </div> 34 </div>
35 35
36 <div class="form-group form-group-right col-12 col-lg-8 col-xl-9"> 36 <div class="form-group form-group-right col-12 col-lg-8 col-xl-9">
37 <my-account-video-settings [user]="user" [userInformationLoaded]="userInformationLoaded"></my-account-video-settings> 37 <my-user-video-settings [user]="user" [userInformationLoaded]="userInformationLoaded"></my-user-video-settings>
38 </div> 38 </div>
39</div> 39</div>
40 40
@@ -55,7 +55,7 @@
55 </div> 55 </div>
56 56
57 <div class="form-group form-group-right col-12 col-lg-8 col-xl-9"> 57 <div class="form-group form-group-right col-12 col-lg-8 col-xl-9">
58 <my-account-interface-settings [user]="user" [userInformationLoaded]="userInformationLoaded"></my-account-interface-settings> 58 <my-user-interface-settings [user]="user" [userInformationLoaded]="userInformationLoaded"></my-user-interface-settings>
59 </div> 59 </div>
60</div> 60</div>
61 61
diff --git a/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
index f73f3aa1e..4800be24b 100644
--- a/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
+++ b/client/src/app/+my-account/my-account-settings/my-account-settings.component.ts
@@ -1,11 +1,8 @@
1import { Component, OnInit, AfterViewChecked } from '@angular/core'
2import { Notifier } from '@app/core'
3import { BytesPipe } from 'ngx-pipes' 1import { BytesPipe } from 'ngx-pipes'
4import { AuthService } from '../../core'
5import { User } from '../../shared'
6import { UserService } from '../../shared/users'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { ViewportScroller } from '@angular/common' 2import { ViewportScroller } from '@angular/common'
3import { AfterViewChecked, Component, OnInit } from '@angular/core'
4import { AuthService, Notifier, User, UserService } from '@app/core'
5import { I18n } from '@ngx-translate/i18n-polyfill'
9 6
10@Component({ 7@Component({
11 selector: 'my-account-settings', 8 selector: 'my-account-settings',
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/index.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/index.ts
deleted file mode 100644
index 1253bd369..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/index.ts
+++ /dev/null
@@ -1 +0,0 @@
1export * from './my-account-video-settings.component'
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
deleted file mode 100644
index 0dda33af2..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.html
+++ /dev/null
@@ -1,75 +0,0 @@
1<form role="form" (ngSubmit)="updateDetails()" [formGroup]="form">
2 <div class="form-group form-group-select">
3 <label i18n for="nsfwPolicy">Default policy on videos containing sensitive content</label>
4 <my-help>
5 <ng-template ptTemplate="customHtml">
6 <ng-container i18n>
7 With <strong>Do not list</strong> or <strong>Blur thumbnails</strong>, a confirmation will be requested to watch the video.
8 </ng-container>
9 </ng-template>
10 </my-help>
11
12 <div class="peertube-select-container">
13 <select id="nsfwPolicy" formControlName="nsfwPolicy" class="form-control">
14 <option i18n value="undefined" disabled>Policy for sensitive videos</option>
15 <option i18n value="do_not_list">Do not list</option>
16 <option i18n value="blur">Blur thumbnails</option>
17 <option i18n value="display">Display</option>
18 </select>
19 </div>
20 </div>
21
22 <div class="form-group form-group-select">
23 <label i18n for="videoLanguages">Only display videos in the following languages/subtitles</label>
24 <my-help>
25 <ng-template ptTemplate="customHtml">
26 <ng-container i18n>In Recently added, Trending, Local, Most liked and Search pages</ng-container>
27 </ng-template>
28 </my-help>
29
30 <div>
31 <p-multiSelect
32 inputId="videoLanguages" [options]="languageItems" formControlName="videoLanguages" [showToggleAll]="true"
33 [defaultLabel]="getDefaultVideoLanguageLabel()" [selectedItemsLabel]="getSelectedVideoLanguageLabel()"
34 emptyFilterMessage="No results found" i18n-emptyFilterMessage
35 ></p-multiSelect>
36 </div>
37 </div>
38
39 <ng-content select="inner-title"></ng-content>
40
41 <div class="form-group">
42 <my-peertube-checkbox
43 inputName="webTorrentEnabled" formControlName="webTorrentEnabled" [recommended]="true"
44 i18n-labelText labelText="Help share videos being played"
45 >
46 <ng-container ngProjectAs="description">
47 <span i18n>The <a routerLink="/about/peertube" fragment="privacy">sharing system</a> implies that some technical information about your system (such as a public IP address) can be sent to other peers, but greatly helps to reduce server load.</span>
48 </ng-container>
49 </my-peertube-checkbox>
50 </div>
51
52 <div class="form-group">
53 <my-peertube-checkbox
54 inputName="autoPlayVideo" formControlName="autoPlayVideo"
55 i18n-labelText labelText="Automatically play videos"
56 >
57 <ng-container ngProjectAs="description">
58 <span i18n>When on a video page, directly start playing the video.</span>
59 </ng-container>
60 </my-peertube-checkbox>
61 </div>
62
63 <div class="form-group">
64 <my-peertube-checkbox
65 inputName="autoPlayNextVideo" formControlName="autoPlayNextVideo"
66 i18n-labelText labelText="Automatically start playing the next video"
67 >
68 <ng-container ngProjectAs="description">
69 <span i18n>When a video ends, follow up with the next suggested video.</span>
70 </ng-container>
71 </my-peertube-checkbox>
72 </div>
73
74 <input *ngIf="!reactiveUpdate" type="submit" i18n-value value="Save" [disabled]="!form.valid">
75</form>
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scss b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scss
deleted file mode 100644
index 430250b87..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.scss
+++ /dev/null
@@ -1,24 +0,0 @@
1@import '_variables';
2@import '_mixins';
3
4label {
5 font-weight: $font-regular;
6 font-size: 100%;
7}
8
9input[type=submit] {
10 @include peertube-button;
11 @include orange-button;
12
13 margin-top: 15px;
14}
15
16.peertube-select-container {
17 @include peertube-select-container(340px);
18
19 margin-bottom: 30px;
20}
21
22.form-group-select {
23 margin-bottom: 30px;
24}
diff --git a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts b/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
deleted file mode 100644
index 0aaa54cd7..000000000
--- a/client/src/app/+my-account/my-account-settings/my-account-video-settings/my-account-video-settings.component.ts
+++ /dev/null
@@ -1,142 +0,0 @@
1import { Component, Input, OnInit, OnDestroy } from '@angular/core'
2import { Notifier, ServerService } from '@app/core'
3import { UserUpdateMe } from '../../../../../../shared/models/users'
4import { User, UserService } from '@app/shared/users'
5import { AuthService } from '../../../core'
6import { FormReactive } from '@app/shared/forms/form-reactive'
7import { I18n } from '@ngx-translate/i18n-polyfill'
8import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
9import { forkJoin, Subject, Subscription } from 'rxjs'
10import { SelectItem } from 'primeng/api'
11import { first } from 'rxjs/operators'
12import { NSFWPolicyType } from '@shared/models/videos/nsfw-policy.type'
13import { pick } from 'lodash-es'
14
15@Component({
16 selector: 'my-account-video-settings',
17 templateUrl: './my-account-video-settings.component.html',
18 styleUrls: [ './my-account-video-settings.component.scss' ]
19})
20export class MyAccountVideoSettingsComponent extends FormReactive implements OnInit, OnDestroy {
21 @Input() user: User = null
22 @Input() reactiveUpdate = false
23 @Input() notifyOnUpdate = true
24 @Input() userInformationLoaded: Subject<any>
25
26 languageItems: SelectItem[] = []
27 defaultNSFWPolicy: NSFWPolicyType
28 formValuesWatcher: Subscription
29
30 constructor (
31 protected formValidatorService: FormValidatorService,
32 private authService: AuthService,
33 private notifier: Notifier,
34 private userService: UserService,
35 private serverService: ServerService,
36 private i18n: I18n
37 ) {
38 super()
39 }
40
41 ngOnInit () {
42 let oldForm: any
43
44 this.buildForm({
45 nsfwPolicy: null,
46 webTorrentEnabled: null,
47 autoPlayVideo: null,
48 autoPlayNextVideo: null,
49 videoLanguages: null
50 })
51
52 forkJoin([
53 this.serverService.getVideoLanguages(),
54 this.serverService.getConfig(),
55 this.userInformationLoaded.pipe(first())
56 ]).subscribe(([ languages, config ]) => {
57 this.languageItems = [ { label: this.i18n('Unknown language'), value: '_unknown' } ]
58 this.languageItems = this.languageItems
59 .concat(languages.map(l => ({ label: l.label, value: l.id })))
60
61 const videoLanguages = this.user.videoLanguages
62 ? this.user.videoLanguages
63 : this.languageItems.map(l => l.value)
64
65 this.defaultNSFWPolicy = config.instance.defaultNSFWPolicy
66
67 this.form.patchValue({
68 nsfwPolicy: this.user.nsfwPolicy || this.defaultNSFWPolicy,
69 webTorrentEnabled: this.user.webTorrentEnabled,
70 autoPlayVideo: this.user.autoPlayVideo === true,
71 autoPlayNextVideo: this.user.autoPlayNextVideo,
72 videoLanguages
73 })
74
75 if (this.reactiveUpdate) {
76 oldForm = { ...this.form.value }
77 this.formValuesWatcher = this.form.valueChanges.subscribe((formValue: any) => {
78 const updatedKey = Object.keys(formValue).find(k => formValue[k] !== oldForm[k])
79 oldForm = { ...this.form.value }
80 this.updateDetails([updatedKey])
81 })
82 }
83 })
84 }
85
86 ngOnDestroy () {
87 this.formValuesWatcher?.unsubscribe()
88 }
89
90 updateDetails (onlyKeys?: string[]) {
91 const nsfwPolicy = this.form.value[ 'nsfwPolicy' ]
92 const webTorrentEnabled = this.form.value['webTorrentEnabled']
93 const autoPlayVideo = this.form.value['autoPlayVideo']
94 const autoPlayNextVideo = this.form.value['autoPlayNextVideo']
95
96 let videoLanguages: string[] = this.form.value['videoLanguages']
97 if (Array.isArray(videoLanguages)) {
98 if (videoLanguages.length === this.languageItems.length) {
99 videoLanguages = null // null means "All"
100 } else if (videoLanguages.length > 20) {
101 this.notifier.error('Too many languages are enabled. Please enable them all or stay below 20 enabled languages.')
102 return
103 } else if (videoLanguages.length === 0) {
104 this.notifier.error('You need to enabled at least 1 video language.')
105 return
106 }
107 }
108
109 let details: UserUpdateMe = {
110 nsfwPolicy,
111 webTorrentEnabled,
112 autoPlayVideo,
113 autoPlayNextVideo,
114 videoLanguages
115 }
116
117 if (onlyKeys) details = pick(details, onlyKeys)
118
119 if (this.authService.isLoggedIn()) {
120 this.userService.updateMyProfile(details).subscribe(
121 () => {
122 this.authService.refreshUserInformation()
123
124 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Video settings updated.'))
125 },
126
127 err => this.notifier.error(err.message)
128 )
129 } else {
130 this.userService.updateMyAnonymousProfile(details)
131 if (this.notifyOnUpdate) this.notifier.success(this.i18n('Display/Video settings updated.'))
132 }
133 }
134
135 getDefaultVideoLanguageLabel () {
136 return this.i18n('No language')
137 }
138
139 getSelectedVideoLanguageLabel () {
140 return this.i18n('{{\'{0} languages selected')
141 }
142}