]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+accounts/account-video-channels/account-video-channels.component.ts
Fix HTML in account/channel description
[github/Chocobozzz/PeerTube.git] / client / src / app / +accounts / account-video-channels / account-video-channels.component.ts
CommitLineData
5c20a455
C
1import { from, Subject, Subscription } from 'rxjs'
2import { concatMap, map, switchMap, tap } from 'rxjs/operators'
734a5ceb 3import { Component, OnDestroy, OnInit } from '@angular/core'
9df52d66 4import { ComponentPagination, hasMoreItems, MarkdownService, User, UserService } from '@app/core'
67ed6552 5import { Account, AccountService, Video, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
900f7820 6import { MiniatureDisplayOptions } from '@app/shared/shared-video-miniature'
9df52d66 7import { NSFWPolicyType, VideoSortField } from '@shared/models'
d3e91a5f
C
8
9@Component({
10 selector: 'my-account-video-channels',
11 templateUrl: './account-video-channels.component.html',
12 styleUrls: [ './account-video-channels.component.scss' ]
13})
734a5ceb 14export class AccountVideoChannelsComponent implements OnInit, OnDestroy {
d3e91a5f
C
15 account: Account
16 videoChannels: VideoChannel[] = []
900f7820
C
17
18 videos: { [id: number]: { total: number, videos: Video[] } } = {}
19
20 channelsDescriptionHTML: { [ id: number ]: string } = {}
c8487f3f
C
21
22 channelPagination: ComponentPagination = {
23 currentPage: 1,
440d39c5
C
24 itemsPerPage: 2,
25 totalItems: null
c8487f3f
C
26 }
27
28 videosPagination: ComponentPagination = {
29 currentPage: 1,
900f7820 30 itemsPerPage: 5,
440d39c5 31 totalItems: null
c8487f3f
C
32 }
33 videosSort: VideoSortField = '-publishedAt'
d3e91a5f 34
ad453580
C
35 onChannelDataSubject = new Subject<any>()
36
5c20a455 37 userMiniature: User
0aa52e17 38 nsfwPolicy: NSFWPolicyType
900f7820
C
39 miniatureDisplayOptions: MiniatureDisplayOptions = {
40 date: true,
41 views: true,
42 by: false,
43 avatar: false,
44 privacyLabel: false,
45 privacyText: false,
46 state: false,
47 blacklistInfo: false
48 }
5c20a455 49
734a5ceb
C
50 private accountSub: Subscription
51
d3e91a5f 52 constructor (
d3e91a5f 53 private accountService: AccountService,
c8487f3f 54 private videoChannelService: VideoChannelService,
6eb62c33 55 private videoService: VideoService,
900f7820 56 private markdown: MarkdownService,
5c20a455 57 private userService: UserService
d3e91a5f
C
58 ) { }
59
60 ngOnInit () {
61 // Parent get the account for us
734a5ceb 62 this.accountSub = this.accountService.accountLoaded
c8487f3f
C
63 .subscribe(account => {
64 this.account = account
50fe0eac 65 this.videoChannels = []
c8487f3f
C
66
67 this.loadMoreChannels()
68 })
5c20a455
C
69
70 this.userService.getAnonymousOrLoggedUser()
0aa52e17
C
71 .subscribe(user => {
72 this.userMiniature = user
73
74 this.nsfwPolicy = user.nsfwPolicy
75 })
d3e91a5f 76 }
734a5ceb
C
77
78 ngOnDestroy () {
79 if (this.accountSub) this.accountSub.unsubscribe()
80 }
c8487f3f
C
81
82 loadMoreChannels () {
dc2b2938
C
83 const options = {
84 account: this.account,
85 componentPagination: this.channelPagination,
86 sort: '-updatedAt'
87 }
88
89 this.videoChannelService.listAccountVideoChannels(options)
c8487f3f 90 .pipe(
9df52d66
C
91 tap(res => {
92 this.channelPagination.totalItems = res.total
93 }),
c8487f3f
C
94 switchMap(res => from(res.data)),
95 concatMap(videoChannel => {
0aa52e17
C
96 const options = {
97 videoChannel,
98 videoPagination: this.videosPagination,
99 sort: this.videosSort,
100 nsfwPolicy: this.nsfwPolicy
101 }
102
103 return this.videoService.getVideoChannelVideos(options)
900f7820 104 .pipe(map(data => ({ videoChannel, videos: data.data, total: data.total })))
c8487f3f
C
105 })
106 )
900f7820 107 .subscribe(async ({ videoChannel, videos, total }) => {
0e45e336
C
108 this.channelsDescriptionHTML[videoChannel.id] = await this.markdown.textMarkdownToHTML({
109 markdown: videoChannel.description,
110 withEmoji: true,
111 withHtml: true
112 })
900f7820 113
c8487f3f
C
114 this.videoChannels.push(videoChannel)
115
900f7820 116 this.videos[videoChannel.id] = { videos, total }
ad453580
C
117
118 this.onChannelDataSubject.next([ videoChannel ])
c8487f3f
C
119 })
120 }
121
122 getVideosOf (videoChannel: VideoChannel) {
9df52d66 123 const obj = this.videos[videoChannel.id]
900f7820
C
124 if (!obj) return []
125
126 return obj.videos
127 }
128
129 getTotalVideosOf (videoChannel: VideoChannel) {
9df52d66 130 const obj = this.videos[videoChannel.id]
900f7820
C
131 if (!obj) return undefined
132
133 return obj.total
134 }
6eb62c33 135
900f7820
C
136 getChannelDescription (videoChannel: VideoChannel) {
137 return this.channelsDescriptionHTML[videoChannel.id]
c8487f3f
C
138 }
139
140 onNearOfBottom () {
141 if (!hasMoreItems(this.channelPagination)) return
142
143 this.channelPagination.currentPage += 1
144
145 this.loadMoreChannels()
146 }
dc890263
C
147
148 getVideoChannelLink (videoChannel: VideoChannel) {
71887396 149 return [ '/c', videoChannel.nameWithHost ]
dc890263 150 }
d3e91a5f 151}