]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Fix async issues with channels list
authorChocobozzz <me@florianbigard.com>
Thu, 25 Feb 2021 08:09:41 +0000 (09:09 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 25 Feb 2021 08:09:41 +0000 (09:09 +0100)
client/src/app/+my-library/my-video-playlists/my-video-playlist-create.component.ts
client/src/app/+my-library/my-video-playlists/my-video-playlist-update.component.ts
client/src/app/+videos/+video-edit/video-add-components/video-send.ts
client/src/app/helpers/utils.ts
server/initializers/constants.ts

index 5abea54b0a2a5c028924954400cf05f551d0b355..8606a875a4d5f43d4f21f25b6c66f446289e0bed 100644 (file)
@@ -1,7 +1,7 @@
 import { Component, OnInit } from '@angular/core'
 import { Router } from '@angular/router'
 import { AuthService, Notifier, ServerService } from '@app/core'
-import { populateAsyncUserVideoChannels } from '@app/helpers'
+import { listUserChannels } from '@app/helpers'
 import {
   setPlaylistChannelValidator,
   VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -46,8 +46,8 @@ export class MyVideoPlaylistCreateComponent extends MyVideoPlaylistEdit implemen
       setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
     })
 
-    populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
-      .catch(err => console.error('Cannot populate user video channels.', err))
+    listUserChannels(this.authService)
+      .subscribe(channels => this.userVideoChannels = channels)
 
     this.serverService.getVideoPlaylistPrivacies()
         .subscribe(videoPlaylistPrivacies => {
index 532423ba294a83c4da7ca999b81d28ff47d0a9c4..c554d37724a0b63a991dce0cc5b6377506560351 100644 (file)
@@ -3,7 +3,7 @@ import { map, switchMap } from 'rxjs/operators'
 import { Component, OnDestroy, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { AuthService, Notifier, ServerService } from '@app/core'
-import { populateAsyncUserVideoChannels } from '@app/helpers'
+import { listUserChannels } from '@app/helpers'
 import {
   setPlaylistChannelValidator,
   VIDEO_PLAYLIST_CHANNEL_ID_VALIDATOR,
@@ -51,8 +51,8 @@ export class MyVideoPlaylistUpdateComponent extends MyVideoPlaylistEdit implemen
       setPlaylistChannelValidator(this.form.get('videoChannelId'), privacy)
     })
 
-    populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
-      .catch(err => console.error('Cannot populate user video channels.', err))
+    listUserChannels(this.authService)
+      .subscribe(channels => this.userVideoChannels = channels)
 
     this.paramsSub = this.route.params
                          .pipe(
index 9a22024e5003581b6fd1da8fb338ac223a261004..3614499cdd27e856ed5487fc3205aeb427aa2448 100644 (file)
@@ -2,7 +2,7 @@ import { catchError, switchMap, tap } from 'rxjs/operators'
 import { SelectChannelItem } from 'src/types/select-options-item.model'
 import { Directive, EventEmitter, OnInit } from '@angular/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 { VideoCaptionEdit, VideoCaptionService, VideoEdit, VideoService } from '@app/shared/shared-main'
 import { LoadingBarService } from '@ngx-loading-bar/core'
@@ -35,8 +35,11 @@ export abstract class VideoSend extends FormReactive implements OnInit {
   ngOnInit () {
     this.buildForm({})
 
-    populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
-      .then(() => this.firstStepChannelId = this.userVideoChannels[ 0 ].id)
+    listUserChannels(this.authService)
+      .subscribe(channels => {
+        this.userVideoChannels = channels
+        this.firstStepChannelId = this.userVideoChannels[0].id
+      })
 
     this.serverConfig = this.serverService.getTmpConfig()
     this.serverService.getConfig()
index 6d7e76b1168d7de3b20900ac61eecc0cb5826a04..a1747af3cae1f17db516a00537b3ebfb1bbf80b7 100644 (file)
@@ -1,3 +1,4 @@
+import { map } from 'rxjs/operators'
 import { SelectChannelItem } from 'src/types/select-options-item.model'
 import { DatePipe } from '@angular/common'
 import { HttpErrorResponse } from '@angular/common/http'
@@ -20,31 +21,22 @@ function getParameterByName (name: string, url: string) {
   return decodeURIComponent(results[2].replace(/\+/g, ' '))
 }
 
-function populateAsyncUserVideoChannels (
-  authService: AuthService,
-  channel: SelectChannelItem[]
-) {
-  return new Promise<void>(res => {
-    authService.userInformationLoaded
-      .subscribe(
-        () => {
-          const user = authService.getUser()
-          if (!user) return
-
-          const videoChannels = user.videoChannels
-          if (Array.isArray(videoChannels) === false) return
-
-          videoChannels.forEach(c => channel.push({
-            id: c.id,
-            label: c.displayName,
-            support: c.support,
-            avatarPath: c.avatar?.path
-          }))
-
-          return res()
-        }
-      )
-  })
+function listUserChannels (authService: AuthService) {
+  return authService.userInformationLoaded
+    .pipe(map(() => {
+      const user = authService.getUser()
+      if (!user) return undefined
+
+      const videoChannels = user.videoChannels
+      if (Array.isArray(videoChannels) === false) return undefined
+
+      return videoChannels.map(c => ({
+        id: c.id,
+        label: c.displayName,
+        support: c.support,
+        avatarPath: c.avatar?.path
+      }) as SelectChannelItem)
+    }))
 }
 
 function getAbsoluteAPIUrl () {
@@ -207,7 +199,6 @@ export {
   durationToString,
   lineFeedToHtml,
   getParameterByName,
-  populateAsyncUserVideoChannels,
   getAbsoluteAPIUrl,
   dateToHuman,
   immutableAssign,
@@ -218,5 +209,6 @@ export {
   scrollToTop,
   isInViewport,
   isXPercentInViewport,
+  listUserChannels,
   uploadErrorHandler
 }
index f0123e87c7ede0737c5c2c3284452bdcf1af8cbc..6c87354b5bbe744fe5b8ac7fbfe8b54e5c8fcfcd 100644 (file)
@@ -439,6 +439,8 @@ const MIMETYPES = {
       'audio/x-flac': '.flac',
       'audio/flac': '.flac',
       '‎audio/aac': '.aac',
+      'audio/m4a': '.m4a',
+      'audio/x-m4a': '.m4a',
       'audio/ac3': '.ac3'
     },
     EXT_MIMETYPE: null as { [ id: string ]: string }