Fix async issues with channels list

This commit is contained in:
Chocobozzz 2021-02-25 09:09:41 +01:00
parent 9514bb3bc0
commit 9556ce48e7
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
5 changed files with 30 additions and 33 deletions

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core' import { Component, OnInit } from '@angular/core'
import { Router } from '@angular/router' import { Router } from '@angular/router'
import { AuthService, Notifier, ServerService } from '@app/core' import { AuthService, Notifier, ServerService } from '@app/core'
import { populateAsyncUserVideoChannels } from '@app/helpers' import { listUserChannels } from '@app/helpers'
import { import {
setPlaylistChannelValidator, setPlaylistChannelValidator,
VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@ -46,8 +46,8 @@ export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implemen
setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
}) })
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) listUserChannels(this.authService)
.catch(err => console.error('Cannot populate user video channels.', err)) .subscribe(channels => this.userVideoChannels = channels)
this.serverService.getVideoPlaylistPrivacies() this.serverService.getVideoPlaylistPrivacies()
.subscribe(videoPlaylistPrivacies => { .subscribe(videoPlaylistPrivacies => {

View File

@ -3,7 +3,7 @@ import { map, switchMap } from 'rxjs/operators'
import { Component, OnDestroy, OnInit } from '@angular/core' import { Component, OnDestroy, OnInit } from '@angular/core'
import { ActivatedRoute, Router } from '@angular/router' import { ActivatedRoute, Router } from '@angular/router'
import { AuthService, Notifier, ServerService } from '@app/core' import { AuthService, Notifier, ServerService } from '@app/core'
import { populateAsyncUserVideoChannels } from '@app/helpers' import { listUserChannels } from '@app/helpers'
import { import {
setPlaylistChannelValidator, setPlaylistChannelValidator,
VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR, VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@ -51,8 +51,8 @@ export class MyVideoPlaylistUpdateComponent extends MyVideoPlaylistEdit implemen
setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy) setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
}) })
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) listUserChannels(this.authService)
.catch(err => console.error('Cannot populate user video channels.', err)) .subscribe(channels => this.userVideoChannels = channels)
this.paramsSub = this.route.params this.paramsSub = this.route.params
.pipe( .pipe(

View File

@ -2,7 +2,7 @@ import { catchError, switchMap, tap } from 'rxjs/operators'
import { SelectChannelItem } from 'src/types/select-options-item.model' import { SelectChannelItem } from 'src/types/select-options-item.model'
import { Directive, EventEmitter, OnInit } from '@angular/core' import { Directive, EventEmitter, OnInit } from '@angular/core'
import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core' import { AuthService, CanComponentDeactivateResult, Notifier, ServerService } from '@app/core'
import { populateAsyncUserVideoChannels } from '@app/helpers' import { listUserChannels } from '@app/helpers'
import { FormReactive } from '@app/shared/shared-forms' import { FormReactive } from '@app/shared/shared-forms'
import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main' import { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
import { LoadingBarService } from '@ngx-loading-bar/core' import { LoadingBarService } from '@ngx-loading-bar/core'
@ -35,8 +35,11 @@ export abstract class VideoSend extends FormReactive implements OnInit {
ngOnInit () { ngOnInit () {
this.buildForm({}) this.buildForm({})
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) listUserChannels(this.authService)
.then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id) .subscribe(channels => {
this.userVideoChannels = channels
this.firstStepChannelId = this.userVideoChannels[0].id
})
this.serverConfig = this.serverService.getTmpConfig() this.serverConfig = this.serverService.getTmpConfig()
this.serverService.getConfig() this.serverService.getConfig()

View File

@ -1,3 +1,4 @@
import { map } from 'rxjs/operators'
import { SelectChannelItem } from 'src/types/select-options-item.model' import { SelectChannelItem } from 'src/types/select-options-item.model'
import { DatePipe } from '@angular/common' import { DatePipe } from '@angular/common'
import { HttpErrorResponse } from '@angular/common/http' import { HttpErrorResponse } from '@angular/common/http'
@ -20,31 +21,22 @@ function getParameterByName (name: string, url: string) {
return decodeURIComponent(results[2].replace(/\+/g, ' ')) return decodeURIComponent(results[2].replace(/\+/g, ' '))
} }
function populateAsyncUserVideoChannels ( function listUserChannels (authService: AuthService) {
authService: AuthService, return authService.userInformationLoaded
channel: SelectChannelItem[] .pipe(map(() => {
) {
return new Promise<void>(res => {
authService.userInformationLoaded
.subscribe(
() => {
const user = authService.getUser() const user = authService.getUser()
if (!user) return if (!user) return undefined
const videoChannels = user.videoChannels const videoChannels = user.videoChannels
if (Array.isArray(videoChannels) === false) return if (Array.isArray(videoChannels) === false) return undefined
videoChannels.forEach(c => channel.push({ return videoChannels.map(c => ({
id: c.id, id: c.id,
label: c.displayName, label: c.displayName,
support: c.support, support: c.support,
avatarPath: c.avatar?.path avatarPath: c.avatar?.path
}) as SelectChannelItem)
})) }))
return res()
}
)
})
} }
function getAbsoluteAPIUrl () { function getAbsoluteAPIUrl () {
@ -207,7 +199,6 @@ export {
durationToString, durationToString,
lineFeedToHtml, lineFeedToHtml,
getParameterByName, getParameterByName,
populateAsyncUserVideoChannels,
getAbsoluteAPIUrl, getAbsoluteAPIUrl,
dateToHuman, dateToHuman,
immutableAssign, immutableAssign,
@ -218,5 +209,6 @@ export {
scrollToTop, scrollToTop,
isInViewport, isInViewport,
isXPercentInViewport, isXPercentInViewport,
listUserChannels,
uploadErrorHandler uploadErrorHandler
} }

View File

@ -439,6 +439,8 @@ const MIMETYPES = {
'audio/x-flac': '.flac', 'audio/x-flac': '.flac',
'audio/flac': '.flac', 'audio/flac': '.flac',
'audio/aac': '.aac', 'audio/aac': '.aac',
'audio/m4a': '.m4a',
'audio/x-m4a': '.m4a',
'audio/ac3': '.ac3' 'audio/ac3': '.ac3'
}, },
EXT_MIMETYPE: null as { [ id: string ]: string } EXT_MIMETYPE: null as { [ id: string ]: string }