X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Baccounts%2Faccount-video-channels%2Faccount-video-channels.component.ts;h=631444398cc73e889fe1fc0a3966bad150dfb356;hb=cb0eda5602a21d1626a7face32de6153ed07b5f9;hp=29d2991fddbabca192aedd94c081e381ca40adaa;hpb=d5c8932a601c1854db0a2e399ccaf26e17385f1a;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts index 29d2991fd..631444398 100644 --- a/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts +++ b/client/src/app/+accounts/account-video-channels/account-video-channels.component.ts @@ -1,17 +1,11 @@ -import { Component, OnDestroy, OnInit } from '@angular/core' -import { ActivatedRoute } from '@angular/router' -import { Account } from '@app/shared/account/account.model' -import { AccountService } from '@app/shared/account/account.service' -import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' -import { concatMap, map, switchMap, tap } from 'rxjs/operators' import { from, Subject, Subscription } from 'rxjs' -import { VideoChannel } from '@app/shared/video-channel/video-channel.model' -import { Video } from '@app/shared/video/video.model' -import { AuthService } from '@app/core' -import { VideoService } from '@app/shared/video/video.service' -import { VideoSortField } from '@app/shared/video/sort-field.type' -import { ComponentPagination, hasMoreItems } from '@app/shared/rest/component-pagination.model' -import { ScreenService } from '@app/shared/misc/screen.service' +import { concatMap, map, switchMap, tap } from 'rxjs/operators' +import { Component, OnDestroy, OnInit } from '@angular/core' +import { ComponentPagination, hasMoreItems, MarkdownService, User, UserService } from '@app/core' +import { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' +import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature' +import { NSFWPolicyType, VideoSortField } from '@shared/models' +import { SimpleMemoize } from '@app/helpers' @Component({ selector: 'my-account-video-channels', @@ -21,44 +15,65 @@ import { ScreenService } from '@app/shared/misc/screen.service' 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, - itemsPerPage: 2 + itemsPerPage: 2, + totalItems: null } videosPagination: ComponentPagination = { currentPage: 1, - itemsPerPage: 12 + itemsPerPage: 5, + totalItems: null } videosSort: VideoSortField = '-publishedAt' onChannelDataSubject = new Subject() + 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 constructor ( - private route: ActivatedRoute, - private authService: AuthService, private accountService: AccountService, private videoChannelService: VideoChannelService, private videoService: VideoService, - private screenService: ScreenService + private markdown: MarkdownService, + private userService: UserService ) { } - get user () { - return this.authService.getUser() - } - ngOnInit () { // Parent get the account for us this.accountSub = this.accountService.accountLoaded .subscribe(account => { this.account = account + this.videoChannels = [] this.loadMoreChannels() }) + + this.userService.getAnonymousOrLoggedUser() + .subscribe(user => { + this.userMiniature = user + + this.nsfwPolicy = user.nsfwPolicy + }) } ngOnDestroy () { @@ -66,29 +81,61 @@ 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), + 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({ + markdown: videoChannel.description, + withEmoji: true, + withHtml: true + }) + 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 () { @@ -99,7 +146,8 @@ export class AccountVideoChannelsComponent implements OnInit, OnDestroy { this.loadMoreChannels() } + @SimpleMemoize() getVideoChannelLink (videoChannel: VideoChannel) { - return [ '/video-channels', videoChannel.nameWithHost ] + return [ '/c', videoChannel.nameWithHost ] } }