X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fhelpers%2Futils.ts;h=94f6def2676c0b84a907e9f8fe8cb48067aaa6db;hb=ad35265d743e621d86f3f0796dd9d8795c599dca;hp=6d7e76b1168d7de3b20900ac61eecc0cb5826a04;hpb=21e493d4d8acb7a650eff3a30cd7e086b3cb8a28;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/helpers/utils.ts b/client/src/app/helpers/utils.ts index 6d7e76b11..94f6def26 100644 --- a/client/src/app/helpers/utils.ts +++ b/client/src/app/helpers/utils.ts @@ -1,3 +1,4 @@ +import { first, 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,31 @@ function getParameterByName (name: string, url: string) { return decodeURIComponent(results[2].replace(/\+/g, ' ')) } -function populateAsyncUserVideoChannels ( - authService: AuthService, - channel: SelectChannelItem[] -) { - return new Promise(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({ +function listUserChannels (authService: AuthService) { + return authService.userInformationLoaded + .pipe( + first(), + map(() => { + const user = authService.getUser() + if (!user) return undefined + + const videoChannels = user.videoChannels + if (Array.isArray(videoChannels) === false) return undefined + + return videoChannels + .sort((a, b) => { + if (a.updatedAt < b.updatedAt) return 1 + if (a.updatedAt > b.updatedAt) return -1 + return 0 + }) + .map(c => ({ id: c.id, label: c.displayName, support: c.support, avatarPath: c.avatar?.path - })) - - return res() - } - ) - }) + }) as SelectChannelItem) + }) + ) } function getAbsoluteAPIUrl () { @@ -175,8 +176,8 @@ function isXPercentInViewport (el: HTMLElement, percentVisible: number) { ) } -function uploadErrorHandler (parameters: { - err: HttpErrorResponse +function genericUploadErrorHandler (parameters: { + err: Pick name: string notifier: Notifier sticky?: boolean @@ -188,6 +189,9 @@ function uploadErrorHandler (parameters: { if (err instanceof ErrorEvent) { // network error message = $localize`The connection was interrupted` notifier.error(message, title, null, sticky) + } else if (err.status === HttpStatusCode.INTERNAL_SERVER_ERROR_500) { + message = $localize`The server encountered an error` + notifier.error(message, title, null, sticky) } else if (err.status === HttpStatusCode.REQUEST_TIMEOUT_408) { message = $localize`Your ${name} file couldn't be transferred before the set timeout (usually 10min)` notifier.error(message, title, null, sticky) @@ -207,7 +211,6 @@ export { durationToString, lineFeedToHtml, getParameterByName, - populateAsyncUserVideoChannels, getAbsoluteAPIUrl, dateToHuman, immutableAssign, @@ -218,5 +221,6 @@ export { scrollToTop, isInViewport, isXPercentInViewport, - uploadErrorHandler + listUserChannels, + genericUploadErrorHandler }