]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
Merge branch 'master' into release/3.3.0
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-video-channels / account-video-channels.component.ts
index 205245675af0d19b483b809df2969f93fa4a23e9..e146a5cd2c4075b53ab19d08f88faab160d7f3a9 100644 (file)
@@ -1,9 +1,10 @@
 import { from, Subject, Subscription } from 'rxjs'
 import { concatMap, map, switchMap, tap } from 'rxjs/operators'
 import { Component, OnDestroy, OnInit } from '@angular/core'
-import { ComponentPagination, hasMoreItems, ScreenService, User, UserService } from '@app/core'
+import { ComponentPagination, hasMoreItems, MarkdownService, ScreenService, User, UserService } from '@app/core'
 import { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
-import { VideoSortField } from '@shared/models'
+import { NSFWPolicyType, VideoSortField } from '@shared/models'
+import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
 
 @Component({
   selector: 'my-account-video-channels',
@@ -13,7 +14,10 @@ import { VideoSortField } from '@shared/models'
 export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
   account: Account
   videoChannels: VideoChannel[] = []
-  videos: { [id: number]: Video[] } = {}
+
+  videos: { [id: number]: { total: number, videos: Video[] } } = {}
+
+  channelsDescriptionHTML: { [ id: number ]: string } = {}
 
   channelPagination: ComponentPagination = {
     currentPage: 1,
@@ -23,7 +27,7 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
 
   videosPagination: ComponentPagination = {
     currentPage: 1,
-    itemsPerPage: 12,
+    itemsPerPage: 5,
     totalItems: null
   }
   videosSort: VideoSortField = '-publishedAt'
@@ -31,6 +35,17 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
   onChannelDataSubject = new Subject<any>()
 
   userMiniature: User
+  nsfwPolicy: NSFWPolicyType
+  miniatureDisplayOptions: MiniatureDisplayOptions = {
+    date: true,
+    views: true,
+    by: false,
+    avatar: false,
+    privacyLabel: false,
+    privacyText: false,
+    state: false,
+    blacklistInfo: false
+  }
 
   private accountSub: Subscription
 
@@ -38,7 +53,7 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
     private accountService: AccountService,
     private videoChannelService: VideoChannelService,
     private videoService: VideoService,
-    private screenService: ScreenService,
+    private markdown: MarkdownService,
     private userService: UserService
   ) { }
 
@@ -52,7 +67,11 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
         })
 
     this.userService.getAnonymousOrLoggedUser()
-      .subscribe(user => this.userMiniature = user)
+      .subscribe(user => {
+        this.userMiniature = user
+
+        this.nsfwPolicy = user.nsfwPolicy
+      })
   }
 
   ngOnDestroy () {
@@ -60,29 +79,55 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
   }
 
   loadMoreChannels () {
-    this.videoChannelService.listAccountVideoChannels(this.account, this.channelPagination)
+    const options = {
+      account: this.account,
+      componentPagination: this.channelPagination,
+      sort: '-updatedAt'
+    }
+
+    this.videoChannelService.listAccountVideoChannels(options)
       .pipe(
         tap(res => this.channelPagination.totalItems = res.total),
         switchMap(res => from(res.data)),
         concatMap(videoChannel => {
-          return this.videoService.getVideoChannelVideos(videoChannel, this.videosPagination, this.videosSort)
-            .pipe(map(data => ({ videoChannel, videos: data.data })))
+          const options = {
+            videoChannel,
+            videoPagination: this.videosPagination,
+            sort: this.videosSort,
+            nsfwPolicy: this.nsfwPolicy
+          }
+
+          return this.videoService.getVideoChannelVideos(options)
+            .pipe(map(data => ({ videoChannel, videos: data.data, total: data.total })))
         })
       )
-      .subscribe(({ videoChannel, videos }) => {
+      .subscribe(async ({ videoChannel, videos, total }) => {
+        this.channelsDescriptionHTML[videoChannel.id] = await this.markdown.textMarkdownToHTML(videoChannel.description)
+
         this.videoChannels.push(videoChannel)
 
-        this.videos[videoChannel.id] = videos
+        this.videos[videoChannel.id] = { videos, total }
 
         this.onChannelDataSubject.next([ videoChannel ])
       })
   }
 
   getVideosOf (videoChannel: VideoChannel) {
-    const numberOfVideos = this.screenService.getNumberOfAvailableMiniatures()
+    const obj = this.videos[ videoChannel.id ]
+    if (!obj) return []
+
+    return obj.videos
+  }
+
+  getTotalVideosOf (videoChannel: VideoChannel) {
+    const obj = this.videos[ videoChannel.id ]
+    if (!obj) return undefined
+
+    return obj.total
+  }
 
-    // 2 rows
-    return this.videos[ videoChannel.id ].slice(0, numberOfVideos * 2)
+  getChannelDescription (videoChannel: VideoChannel) {
+    return this.channelsDescriptionHTML[videoChannel.id]
   }
 
   onNearOfBottom () {
@@ -94,6 +139,6 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
   }
 
   getVideoChannelLink (videoChannel: VideoChannel) {
-    return [ '/video-channels', videoChannel.nameWithHost ]
+    return [ '/c', videoChannel.nameWithHost ]
   }
 }