]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/shared-custom-markup/peertube-custom-tags/channel-miniature-markup.component.ts
Fix HTML in account/channel description
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / shared-custom-markup / peertube-custom-tags / channel-miniature-markup.component.ts
index a91debbef7695b55a5e6fb957a3c7363b3ab0ed1..ba12b713945da2d804d5f430b7c44abc6414119b 100644 (file)
@@ -1,8 +1,10 @@
-import { map, switchMap } from 'rxjs/operators'
+import { from } from 'rxjs'
+import { finalize, map, switchMap, tap } from 'rxjs/operators'
 import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'
-import { MarkdownService, UserService } from '@app/core'
-import { Video, VideoSortField } from '@shared/models/videos'
-import { VideoChannel, VideoChannelService, VideoService } from '../../shared-main'
+import { MarkdownService, Notifier, UserService } from '@app/core'
+import { FindInBulkService } from '@app/shared/shared-search'
+import { VideoSortField } from '@shared/models'
+import { Video, VideoChannel, VideoService } from '../../shared-main'
 import { CustomMarkupComponent } from './shared'
 
 /*
@@ -28,19 +30,35 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
 
   constructor (
     private markdown: MarkdownService,
-    private channelService: VideoChannelService,
+    private findInBulk: FindInBulkService,
     private videoService: VideoService,
-    private userService: UserService
+    private userService: UserService,
+    private notifier: Notifier
   ) { }
 
   ngOnInit () {
-    this.channelService.getVideoChannel(this.name)
-      .subscribe(async channel => {
-        this.channel = channel
-
-        this.descriptionHTML = await this.markdown.textMarkdownToHTML(channel.description)
+    this.findInBulk.getChannel(this.name)
+      .pipe(
+        tap(channel => {
+          this.channel = channel
+        }),
+        switchMap(() => from(this.markdown.textMarkdownToHTML({
+          markdown: this.channel.description,
+          withEmoji: true,
+          withHtml: true
+        }))),
+        tap(html => {
+          this.descriptionHTML = html
+        }),
+        switchMap(() => this.loadVideosObservable()),
+        finalize(() => this.loaded.emit(true))
+      ).subscribe({
+        next: ({ total, data }) => {
+          this.totalVideos = total
+          this.video = data[0]
+        },
 
-        this.loadVideos()
+        error: err => this.notifier.error($localize`Error in channel miniature component: ${err.message}`)
       })
   }
 
@@ -48,7 +66,7 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
     return [ '/c', this.channel.nameWithHost ]
   }
 
-  private loadVideos () {
+  private loadVideosObservable () {
     const videoOptions = {
       videoChannel: this.channel,
       videoPagination: {
@@ -59,18 +77,10 @@ export class ChannelMiniatureMarkupComponent implements CustomMarkupComponent, O
       count: 1
     }
 
-    this.userService.getAnonymousOrLoggedUser()
+    return this.userService.getAnonymousOrLoggedUser()
       .pipe(
         map(user => user.nsfwPolicy),
         switchMap(nsfwPolicy => this.videoService.getVideoChannelVideos({ ...videoOptions, nsfwPolicy }))
       )
-      .subscribe({
-        next: ({ total, data }) => {
-          this.totalVideos = total
-          this.video = data[0]
-        },
-
-        complete: () => this.loaded.emit(true)
-      })
   }
 }