]>
Commit | Line | Data |
---|---|---|
9abd170d | 1 | import { forkJoin } from 'rxjs' |
67ed6552 | 2 | import { map } from 'rxjs/operators' |
f443a746 | 3 | import { SelectChannelItem, SelectOptionsItem } from 'src/types/select-options-item.model' |
3c065fe3 | 4 | import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' |
cc4bf76c | 5 | import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms' |
7294aab0 | 6 | import { HooksService, PluginService, ServerService } from '@app/core' |
67ed6552 | 7 | import { removeElementFromArray } from '@app/helpers' |
3c065fe3 | 8 | import { BuildFormValidator } from '@app/shared/form-validators' |
7ed1edbb C |
9 | import { |
10 | VIDEO_CATEGORY_VALIDATOR, | |
11 | VIDEO_CHANNEL_VALIDATOR, | |
12 | VIDEO_DESCRIPTION_VALIDATOR, | |
13 | VIDEO_LANGUAGE_VALIDATOR, | |
14 | VIDEO_LICENCE_VALIDATOR, | |
15 | VIDEO_NAME_VALIDATOR, | |
16 | VIDEO_ORIGINALLY_PUBLISHED_AT_VALIDATOR, | |
17 | VIDEO_PRIVACY_VALIDATOR, | |
18 | VIDEO_SCHEDULE_PUBLICATION_AT_VALIDATOR, | |
19 | VIDEO_SUPPORT_VALIDATOR, | |
20 | VIDEO_TAGS_ARRAY_VALIDATOR | |
21 | } from '@app/shared/form-validators/video-validators' | |
21e493d4 | 22 | import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms' |
9abd170d | 23 | import { InstanceService } from '@app/shared/shared-instance' |
57d74ec8 | 24 | import { VideoCaptionEdit, VideoCaptionWithPathEdit, VideoEdit, VideoService } from '@app/shared/shared-main' |
080f1402 C |
25 | import { NgbModal } from '@ng-bootstrap/ng-bootstrap' |
26 | import { logger } from '@root-helpers/logger' | |
fb3c9e2b | 27 | import { PluginInfo } from '@root-helpers/plugins-manager' |
428ccb8b | 28 | import { |
2989628b | 29 | HTMLServerConfig, |
428ccb8b | 30 | LiveVideo, |
f443a746 | 31 | LiveVideoLatencyMode, |
428ccb8b C |
32 | RegisterClientFormFieldOptions, |
33 | RegisterClientVideoFieldOptions, | |
428ccb8b C |
34 | VideoConstant, |
35 | VideoDetails, | |
36 | VideoPrivacy | |
37 | } from '@shared/models' | |
080f1402 | 38 | import { VideoSource } from '@shared/models/videos/video-source' |
67ed6552 C |
39 | import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service' |
40 | import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component' | |
2873a53e | 41 | import { VideoCaptionEditModalContentComponent } from './video-caption-edit-modal-content/video-caption-edit-modal-content.component' |
c6c0fa6c | 42 | import { VideoEditType } from './video-edit.type' |
02c01341 RK |
43 | |
44 | type VideoLanguages = VideoConstant<string> & { group?: string } | |
0f319334 | 45 | type PluginField = { |
fb3c9e2b | 46 | pluginInfo: PluginInfo |
0f319334 C |
47 | commonOptions: RegisterClientFormFieldOptions |
48 | videoFormOptions: RegisterClientVideoFieldOptions | |
49 | } | |
ff249f49 C |
50 | |
51 | @Component({ | |
52 | selector: 'my-video-edit', | |
53 | styleUrls: [ './video-edit.component.scss' ], | |
54 | templateUrl: './video-edit.component.html' | |
55 | }) | |
40e87e9e | 56 | export class VideoEditComponent implements OnInit, OnDestroy { |
ff249f49 C |
57 | @Input() form: FormGroup |
58 | @Input() formErrors: { [ id: string ]: string } = {} | |
e309822b | 59 | @Input() validationMessages: FormReactiveValidationMessages = {} |
0f319334 C |
60 | |
61 | @Input() videoToUpdate: VideoDetails | |
62 | ||
9abd170d | 63 | @Input() userVideoChannels: SelectChannelItem[] = [] |
4afec735 | 64 | @Input() forbidScheduledPublication = true |
0f319334 | 65 | |
70a8e50a | 66 | @Input() videoCaptions: VideoCaptionWithPathEdit[] = [] |
2e401e85 | 67 | @Input() videoSource: VideoSource |
0f319334 | 68 | |
080f1402 C |
69 | @Input() hideWaitTranscoding = false |
70 | ||
c6c0fa6c | 71 | @Input() type: VideoEditType |
a5cf76af | 72 | @Input() liveVideo: LiveVideo |
40e87e9e | 73 | |
f36da21e | 74 | @ViewChild('videoCaptionAddModal', { static: true }) videoCaptionAddModal: VideoCaptionAddModalComponent |
bbe0f064 | 75 | |
0ba9696c | 76 | @Output() formBuilt = new EventEmitter<void>() |
7294aab0 C |
77 | @Output() pluginFieldsAdded = new EventEmitter<void>() |
78 | ||
bbe0f064 C |
79 | // So that it can be accessed in the template |
80 | readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY | |
ff249f49 | 81 | |
851f5daa | 82 | videoPrivacies: VideoConstant<VideoPrivacy>[] = [] |
8cd7faaa C |
83 | videoCategories: VideoConstant<number>[] = [] |
84 | videoLicences: VideoConstant<number>[] = [] | |
02c01341 | 85 | videoLanguages: VideoLanguages[] = [] |
f443a746 C |
86 | latencyModes: SelectOptionsItem[] = [ |
87 | { | |
88 | id: LiveVideoLatencyMode.SMALL_LATENCY, | |
89 | label: $localize`Small latency`, | |
90 | description: $localize`Reduce latency to ~15s disabling P2P` | |
91 | }, | |
92 | { | |
93 | id: LiveVideoLatencyMode.DEFAULT, | |
94 | label: $localize`Default`, | |
95 | description: $localize`Average latency of 30s` | |
96 | }, | |
97 | { | |
98 | id: LiveVideoLatencyMode.HIGH_LATENCY, | |
99 | label: $localize`High latency`, | |
100 | description: $localize`Average latency of 60s increasing P2P ratio` | |
101 | } | |
102 | ] | |
ff249f49 | 103 | |
7294aab0 C |
104 | pluginDataFormGroup: FormGroup |
105 | ||
bbe0f064 C |
106 | schedulePublicationEnabled = false |
107 | ||
bbe0f064 C |
108 | calendarLocale: any = {} |
109 | minScheduledDate = new Date() | |
1e74f19a | 110 | myYearRange = '1880:' + (new Date()).getFullYear() |
bbe0f064 C |
111 | |
112 | calendarTimezone: string | |
113 | calendarDateFormat: string | |
ff249f49 | 114 | |
2989628b | 115 | serverConfig: HTMLServerConfig |
ba430d75 | 116 | |
0f319334 | 117 | pluginFields: PluginField[] = [] |
7294aab0 | 118 | |
244b4ae3 | 119 | private schedulerInterval: any |
0f7fedc3 | 120 | private firstPatchDone = false |
772d5642 | 121 | private initialVideoCaptions: string[] = [] |
40e87e9e | 122 | |
ff249f49 | 123 | constructor ( |
d18d6478 | 124 | private formValidatorService: FormValidatorService, |
851f5daa | 125 | private videoService: VideoService, |
bbe0f064 | 126 | private serverService: ServerService, |
7294aab0 | 127 | private pluginService: PluginService, |
02c01341 | 128 | private instanceService: InstanceService, |
84c7cde6 | 129 | private i18nPrimengCalendarService: I18nPrimengCalendarService, |
7294aab0 | 130 | private ngZone: NgZone, |
3c065fe3 | 131 | private hooks: HooksService, |
2873a53e | 132 | private cd: ChangeDetectorRef, |
133 | private modalService: NgbModal | |
e309822b | 134 | ) { |
bbe0f064 C |
135 | this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone() |
136 | this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat() | |
e309822b | 137 | } |
ff249f49 C |
138 | |
139 | updateForm () { | |
244b4ae3 | 140 | const defaultValues: any = { |
d18d6478 | 141 | nsfw: 'false', |
3cf68b86 C |
142 | commentsEnabled: this.serverConfig.defaults.publish.commentsEnabled, |
143 | downloadEnabled: this.serverConfig.defaults.publish.downloadEnabled, | |
080f1402 | 144 | waitTranscoding: true, |
3cf68b86 | 145 | licence: this.serverConfig.defaults.publish.licence, |
d18d6478 C |
146 | tags: [] |
147 | } | |
3c065fe3 | 148 | const obj: { [ id: string ]: BuildFormValidator } = { |
7ed1edbb C |
149 | name: VIDEO_NAME_VALIDATOR, |
150 | privacy: VIDEO_PRIVACY_VALIDATOR, | |
151 | channelId: VIDEO_CHANNEL_VALIDATOR, | |
d18d6478 C |
152 | nsfw: null, |
153 | commentsEnabled: null, | |
7f2cfe3a | 154 | downloadEnabled: null, |
2186386c | 155 | waitTranscoding: null, |
7ed1edbb C |
156 | category: VIDEO_CATEGORY_VALIDATOR, |
157 | licence: VIDEO_LICENCE_VALIDATOR, | |
158 | language: VIDEO_LANGUAGE_VALIDATOR, | |
159 | description: VIDEO_DESCRIPTION_VALIDATOR, | |
160 | tags: VIDEO_TAGS_ARRAY_VALIDATOR, | |
d18d6478 | 161 | previewfile: null, |
7ed1edbb C |
162 | support: VIDEO_SUPPORT_VALIDATOR, |
163 | schedulePublicationAt: VIDEO_SCHEDULE_PUBLICATION_AT_VALIDATOR, | |
c6c0fa6c | 164 | originallyPublishedAt: VIDEO_ORIGINALLY_PUBLISHED_AT_VALIDATOR, |
b5b68755 | 165 | liveStreamKey: null, |
bb4ba6d9 | 166 | permanentLive: null, |
f443a746 | 167 | latencyMode: null, |
b5b68755 | 168 | saveReplay: null |
d18d6478 | 169 | } |
ff249f49 | 170 | |
3c065fe3 | 171 | this.formValidatorService.updateFormGroup( |
d18d6478 C |
172 | this.form, |
173 | this.formErrors, | |
174 | this.validationMessages, | |
175 | obj, | |
176 | defaultValues | |
177 | ) | |
74af5145 | 178 | |
40e87e9e C |
179 | this.form.addControl('captions', new FormArray([ |
180 | new FormGroup({ | |
181 | language: new FormControl(), | |
182 | captionfile: new FormControl() | |
183 | }) | |
184 | ])) | |
185 | ||
bbe0f064 C |
186 | this.trackChannelChange() |
187 | this.trackPrivacyChange() | |
0ba9696c C |
188 | |
189 | this.formBuilt.emit() | |
bbe0f064 C |
190 | } |
191 | ||
192 | ngOnInit () { | |
3cf68b86 C |
193 | this.serverConfig = this.serverService.getHTMLConfig() |
194 | ||
bbe0f064 C |
195 | this.updateForm() |
196 | ||
7294aab0 C |
197 | this.pluginService.ensurePluginsAreLoaded('video-edit') |
198 | .then(() => this.updatePluginFields()) | |
199 | ||
ba430d75 C |
200 | this.serverService.getVideoCategories() |
201 | .subscribe(res => this.videoCategories = res) | |
7294aab0 | 202 | |
ba430d75 C |
203 | this.serverService.getVideoLicences() |
204 | .subscribe(res => this.videoLicences = res) | |
7294aab0 | 205 | |
02c01341 RK |
206 | forkJoin([ |
207 | this.instanceService.getAbout(), | |
208 | this.serverService.getVideoLanguages() | |
209 | ]).pipe(map(([ about, languages ]) => ({ about, languages }))) | |
210 | .subscribe(res => { | |
211 | this.videoLanguages = res.languages | |
7294aab0 | 212 | .map(l => { |
81547acb FC |
213 | if (l.id === 'zxx') return { ...l, group: $localize`Other`, groupOrder: 1 } |
214 | ||
7294aab0 C |
215 | return res.about.instance.languages.includes(l.id) |
216 | ? { ...l, group: $localize`Instance languages`, groupOrder: 0 } | |
81547acb | 217 | : { ...l, group: $localize`All languages`, groupOrder: 2 } |
7294aab0 | 218 | }) |
02c01341 RK |
219 | .sort((a, b) => a.groupOrder - b.groupOrder) |
220 | }) | |
ba430d75 C |
221 | |
222 | this.serverService.getVideoPrivacies() | |
02c01341 | 223 | .subscribe(privacies => { |
29510651 | 224 | this.videoPrivacies = this.videoService.explainedPrivacyLabels(privacies).videoPrivacies |
a3f45a2a | 225 | |
4afec735 C |
226 | // Can't schedule publication if private privacy is not available (could be deleted by a plugin) |
227 | const hasPrivatePrivacy = this.videoPrivacies.some(p => p.id === VideoPrivacy.PRIVATE) | |
228 | if (this.forbidScheduledPublication || !hasPrivatePrivacy) return | |
229 | ||
230 | this.videoPrivacies.push({ | |
231 | id: this.SPECIAL_SCHEDULED_PRIVACY, | |
232 | label: $localize`Scheduled`, | |
233 | description: $localize`Hide the video until a specific date` | |
234 | }) | |
02c01341 | 235 | }) |
bbe0f064 | 236 | |
772d5642 | 237 | this.initialVideoCaptions = this.videoCaptions.map(c => c.language.id) |
84c7cde6 C |
238 | |
239 | this.ngZone.runOutsideAngular(() => { | |
240 | this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute | |
241 | }) | |
7294aab0 | 242 | |
085aba61 C |
243 | const updateForm = (values: any) => { |
244 | this.form.patchValue(values) | |
245 | this.cd.detectChanges() | |
246 | } | |
247 | this.hooks.runAction('action:video-edit.init', 'video-edit', { type: this.type, updateForm }) | |
248 | ||
249 | this.form.valueChanges.subscribe(() => { | |
250 | this.hooks.runAction('action:video-edit.form.updated', 'video-edit', { type: this.type, formValues: this.form.value }) | |
251 | }) | |
40e87e9e C |
252 | } |
253 | ||
254 | ngOnDestroy () { | |
255 | if (this.schedulerInterval) clearInterval(this.schedulerInterval) | |
256 | } | |
257 | ||
ddb62a85 C |
258 | getExistingCaptions () { |
259 | return this.videoCaptions | |
260 | .filter(c => c.action !== 'REMOVE') | |
261 | .map(c => c.language.id) | |
262 | } | |
263 | ||
57d74ec8 | 264 | onCaptionEdited (caption: VideoCaptionEdit) { |
f4001cf4 C |
265 | const existingCaption = this.videoCaptions.find(c => c.language.id === caption.language.id) |
266 | ||
267 | // Replace existing caption? | |
268 | if (existingCaption) { | |
57d74ec8 | 269 | Object.assign(existingCaption, caption) |
ad774752 C |
270 | } else { |
271 | this.videoCaptions.push( | |
272 | Object.assign(caption, { action: 'CREATE' as 'CREATE' }) | |
273 | ) | |
f4001cf4 C |
274 | } |
275 | ||
ad774752 | 276 | this.sortVideoCaptions() |
40e87e9e C |
277 | } |
278 | ||
98ab5dc8 | 279 | deleteCaption (caption: VideoCaptionEdit) { |
772d5642 | 280 | // Caption recovers his former state |
9df52d66 | 281 | if (caption.action && this.initialVideoCaptions.includes(caption.language.id)) { |
772d5642 C |
282 | caption.action = undefined |
283 | return | |
284 | } | |
285 | ||
40e87e9e | 286 | // This caption is not on the server, just remove it from our array |
57d74ec8 | 287 | if (caption.action === 'CREATE' || caption.action === 'UPDATE') { |
40e87e9e C |
288 | removeElementFromArray(this.videoCaptions, caption) |
289 | return | |
290 | } | |
291 | ||
292 | caption.action = 'REMOVE' as 'REMOVE' | |
293 | } | |
294 | ||
295 | openAddCaptionModal () { | |
296 | this.videoCaptionAddModal.show() | |
bbe0f064 C |
297 | } |
298 | ||
2873a53e | 299 | openEditCaptionModal (videoCaption: VideoCaptionWithPathEdit) { |
300 | const modalRef = this.modalService.open(VideoCaptionEditModalContentComponent, { centered: true, keyboard: false }) | |
301 | modalRef.componentInstance.videoCaption = videoCaption | |
302 | modalRef.componentInstance.serverConfig = this.serverConfig | |
303 | modalRef.componentInstance.captionEdited.subscribe(this.onCaptionEdited.bind(this)) | |
304 | } | |
305 | ||
b5b68755 C |
306 | isSaveReplayEnabled () { |
307 | return this.serverConfig.live.allowReplay | |
308 | } | |
309 | ||
bb4ba6d9 C |
310 | isPermanentLiveEnabled () { |
311 | return this.form.value['permanentLive'] === true | |
312 | } | |
313 | ||
f443a746 C |
314 | isLatencyModeEnabled () { |
315 | return this.serverConfig.live.latencySetting.enabled | |
316 | } | |
317 | ||
0f319334 C |
318 | isPluginFieldHidden (pluginField: PluginField) { |
319 | if (typeof pluginField.commonOptions.hidden !== 'function') return false | |
320 | ||
321 | return pluginField.commonOptions.hidden({ | |
322 | formValues: this.form.value, | |
323 | videoToUpdate: this.videoToUpdate, | |
324 | liveVideo: this.liveVideo | |
325 | }) | |
326 | } | |
327 | ||
3c065fe3 C |
328 | getPluginsFields (tab: 'main' | 'plugin-settings') { |
329 | return this.pluginFields.filter(p => { | |
330 | const wanted = p.videoFormOptions.tab ?? 'plugin-settings' | |
331 | ||
332 | return wanted === tab | |
333 | }) | |
334 | } | |
335 | ||
ad774752 C |
336 | private sortVideoCaptions () { |
337 | this.videoCaptions.sort((v1, v2) => { | |
338 | if (v1.language.label < v2.language.label) return -1 | |
339 | if (v1.language.label === v2.language.label) return 0 | |
340 | ||
341 | return 1 | |
342 | }) | |
343 | } | |
344 | ||
fb3c9e2b | 345 | private async updatePluginFields () { |
7294aab0 C |
346 | this.pluginFields = this.pluginService.getRegisteredVideoFormFields(this.type) |
347 | ||
348 | if (this.pluginFields.length === 0) return | |
349 | ||
3c065fe3 C |
350 | const pluginObj: { [ id: string ]: BuildFormValidator } = {} |
351 | const pluginValidationMessages: FormReactiveValidationMessages = {} | |
352 | const pluginFormErrors: any = {} | |
353 | const pluginDefaults: any = {} | |
7294aab0 C |
354 | |
355 | for (const setting of this.pluginFields) { | |
fb3c9e2b C |
356 | await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions) |
357 | ||
cc4bf76c | 358 | const validator = async (control: AbstractControl) => { |
3c065fe3 C |
359 | if (!setting.commonOptions.error) return null |
360 | ||
cc4bf76c | 361 | const error = await setting.commonOptions.error({ formValues: this.form.value, value: control.value }) |
3c065fe3 C |
362 | |
363 | return error?.error ? { [setting.commonOptions.name]: error.text } : null | |
364 | } | |
365 | ||
366 | const name = setting.commonOptions.name | |
367 | ||
368 | pluginObj[name] = { | |
cc4bf76c C |
369 | ASYNC_VALIDATORS: [ validator ], |
370 | VALIDATORS: [], | |
3c065fe3 C |
371 | MESSAGES: {} |
372 | } | |
373 | ||
374 | pluginDefaults[name] = setting.commonOptions.default | |
7294aab0 C |
375 | } |
376 | ||
3c065fe3 C |
377 | this.pluginDataFormGroup = new FormGroup({}) |
378 | this.formValidatorService.updateFormGroup( | |
379 | this.pluginDataFormGroup, | |
380 | pluginFormErrors, | |
381 | pluginValidationMessages, | |
382 | pluginObj, | |
383 | pluginDefaults | |
384 | ) | |
385 | ||
7294aab0 | 386 | this.form.addControl('pluginData', this.pluginDataFormGroup) |
3c065fe3 C |
387 | this.formErrors['pluginData'] = pluginFormErrors |
388 | this.validationMessages['pluginData'] = pluginValidationMessages | |
7294aab0 | 389 | |
3c065fe3 | 390 | this.cd.detectChanges() |
7294aab0 | 391 | this.pluginFieldsAdded.emit() |
cc4bf76c C |
392 | |
393 | // Plugins may need other control values to calculate potential errors | |
394 | this.form.valueChanges.subscribe(() => this.formValidatorService.updateTreeValidity(this.pluginDataFormGroup)) | |
7294aab0 C |
395 | } |
396 | ||
bbe0f064 | 397 | private trackPrivacyChange () { |
4adf2673 | 398 | // We will update the schedule input and the wait transcoding checkbox validators |
9df52d66 | 399 | this.form.controls['privacy'] |
bbe0f064 C |
400 | .valueChanges |
401 | .pipe(map(res => parseInt(res.toString(), 10))) | |
402 | .subscribe( | |
403 | newPrivacyId => { | |
0f7fedc3 | 404 | |
bbe0f064 C |
405 | this.schedulePublicationEnabled = newPrivacyId === this.SPECIAL_SCHEDULED_PRIVACY |
406 | ||
407 | // Value changed | |
408 | const scheduleControl = this.form.get('schedulePublicationAt') | |
409 | const waitTranscodingControl = this.form.get('waitTranscoding') | |
410 | ||
411 | if (this.schedulePublicationEnabled) { | |
412 | scheduleControl.setValidators([ Validators.required ]) | |
413 | ||
414 | waitTranscodingControl.disable() | |
415 | waitTranscodingControl.setValue(false) | |
416 | } else { | |
417 | scheduleControl.clearValidators() | |
418 | ||
419 | waitTranscodingControl.enable() | |
0f7fedc3 C |
420 | |
421 | // Do not update the control value on first patch (values come from the server) | |
422 | if (this.firstPatchDone === true) { | |
423 | waitTranscodingControl.setValue(true) | |
424 | } | |
bbe0f064 C |
425 | } |
426 | ||
427 | scheduleControl.updateValueAndValidity() | |
428 | waitTranscodingControl.updateValueAndValidity() | |
0f7fedc3 C |
429 | |
430 | this.firstPatchDone = true | |
431 | ||
bbe0f064 C |
432 | } |
433 | ) | |
434 | } | |
435 | ||
436 | private trackChannelChange () { | |
74af5145 | 437 | // We will update the "support" field depending on the channel |
9df52d66 | 438 | this.form.controls['channelId'] |
74af5145 C |
439 | .valueChanges |
440 | .pipe(map(res => parseInt(res.toString(), 10))) | |
441 | .subscribe( | |
442 | newChannelId => { | |
9df52d66 | 443 | const oldChannelId = parseInt(this.form.value['channelId'], 10) |
74af5145 C |
444 | |
445 | // Not initialized yet | |
446 | if (isNaN(newChannelId)) return | |
447 | const newChannel = this.userVideoChannels.find(c => c.id === newChannelId) | |
d18d6478 | 448 | if (!newChannel) return |
74af5145 | 449 | |
6f79be11 C |
450 | // Wait support field update |
451 | setTimeout(() => { | |
9df52d66 | 452 | const currentSupport = this.form.value['support'] |
74af5145 | 453 | |
6f79be11 | 454 | // First time we set the channel? |
c6c0fa6c C |
455 | if (isNaN(oldChannelId)) { |
456 | // Fill support if it's empty | |
457 | if (!currentSupport) this.updateSupportField(newChannel.support) | |
458 | ||
459 | return | |
460 | } | |
6f79be11 C |
461 | |
462 | const oldChannel = this.userVideoChannels.find(c => c.id === oldChannelId) | |
463 | if (!newChannel || !oldChannel) { | |
42b40636 | 464 | logger.error('Cannot find new or old channel.') |
6f79be11 C |
465 | return |
466 | } | |
74af5145 | 467 | |
6f79be11 C |
468 | // If the current support text is not the same than the old channel, the user updated it. |
469 | // We don't want the user to lose his text, so stop here | |
470 | if (currentSupport && currentSupport !== oldChannel.support) return | |
74af5145 | 471 | |
6f79be11 C |
472 | // Update the support text with our new channel |
473 | this.updateSupportField(newChannel.support) | |
474 | }) | |
74af5145 C |
475 | } |
476 | ) | |
ff249f49 C |
477 | } |
478 | ||
74af5145 C |
479 | private updateSupportField (support: string) { |
480 | return this.form.patchValue({ support: support || '' }) | |
481 | } | |
ff249f49 | 482 | } |