]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
Fix button height
[github/Chocobozzz/PeerTube.git] / client / src / app / +video-channels / video-channels.component.ts
CommitLineData
67ed6552
C
1import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2import { Subscription } from 'rxjs'
3import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
20d21199 4import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
170726f5 5import { ActivatedRoute } from '@angular/router'
60c35932 6import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService } from '@app/core'
80badf49
C
7import { Account, ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
8import { BlocklistService } from '@app/shared/shared-moderation'
100d9ce2 9import { SupportModalComponent } from '@app/shared/shared-support-modal'
67ed6552 10import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
a37e9e74 11import { HttpStatusCode, UserRight } from '@shared/models'
170726f5
C
12
13@Component({
14 templateUrl: './video-channels.component.html',
15 styleUrls: [ './video-channels.component.scss' ]
16})
734a5ceb 17export class VideoChannelsComponent implements OnInit, OnDestroy {
2f5d2ec5 18 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
100d9ce2 19 @ViewChild('supportModal') supportModal: SupportModalComponent
20d21199 20
170726f5 21 videoChannel: VideoChannel
80badf49 22 ownerAccount: Account
20d21199 23 hotkeys: Hotkey[]
24e7916c 24 links: ListOverflowItem[] = []
fef213ca 25 isChannelManageable = false
170726f5 26
60c35932
C
27 channelVideosCount: number
28 ownerDescriptionHTML = ''
29 channelDescriptionHTML = ''
30 channelDescriptionExpanded = false
31
734a5ceb
C
32 private routeSub: Subscription
33
170726f5
C
34 constructor (
35 private route: ActivatedRoute,
a0dedc02 36 private notifier: Notifier,
2d3741d6 37 private authService: AuthService,
a51bad1a 38 private videoChannelService: VideoChannelService,
60c35932 39 private videoService: VideoService,
20d21199 40 private restExtractor: RestExtractor,
937b7a6a 41 private hotkeysService: HotkeysService,
60c35932 42 private screenService: ScreenService,
80badf49
C
43 private markdown: MarkdownService,
44 private blocklist: BlocklistService
734a5ceb 45 ) { }
170726f5
C
46
47 ngOnInit () {
734a5ceb
C
48 this.routeSub = this.route.params
49 .pipe(
9df52d66 50 map(params => params['videoChannelName']),
734a5ceb 51 distinctUntilChanged(),
2f1548fd 52 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
ab398a05 53 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
f2eb23cd
RK
54 HttpStatusCode.BAD_REQUEST_400,
55 HttpStatusCode.NOT_FOUND_404
56 ]))
734a5ceb 57 )
60c35932 58 .subscribe(async videoChannel => {
0e45e336
C
59 this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML({
60 markdown: videoChannel.description,
61 withEmoji: true,
62 withHtml: true
63 })
64
65 this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML({
66 markdown: videoChannel.ownerAccount.description,
67 withEmoji: true,
68 withHtml: true
69 })
60c35932
C
70
71 // After the markdown renderer to avoid layout changes
fef213ca 72 this.videoChannel = videoChannel
80badf49 73 this.ownerAccount = new Account(this.videoChannel.ownerAccount)
fef213ca 74
60c35932 75 this.loadChannelVideosCount()
80badf49 76 this.loadOwnerBlockStatus()
fef213ca 77 })
734a5ceb 78
20d21199
RK
79 this.hotkeys = [
80 new Hotkey('S', (event: KeyboardEvent): boolean => {
9df52d66
C
81 if (this.subscribeButton.subscribed) this.subscribeButton.unsubscribe()
82 else this.subscribeButton.subscribe()
83
20d21199 84 return false
66357162 85 }, undefined, $localize`Subscribe to the account`)
20d21199
RK
86 ]
87 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
24e7916c
RK
88
89 this.links = [
66357162 90 { label: $localize`VIDEOS`, routerLink: 'videos' },
0a25749f 91 { label: $localize`PLAYLISTS`, routerLink: 'video-playlists' }
24e7916c 92 ]
734a5ceb 93 }
170726f5 94
734a5ceb
C
95 ngOnDestroy () {
96 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
97
98 // Unbind hotkeys
99 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 100 }
2d3741d6 101
60c35932 102 isInSmallView () {
937b7a6a
RK
103 return this.screenService.isInSmallView()
104 }
105
2d3741d6
C
106 isUserLoggedIn () {
107 return this.authService.isLoggedIn()
108 }
a0dedc02 109
a37e9e74 110 isOwner () {
aa0f1963 111 if (!this.isUserLoggedIn()) return false
60c35932 112
67264e06 113 return this.videoChannel?.ownerAccount.userId === this.authService.getUser().id
aa0f1963
RK
114 }
115
a37e9e74 116 isManageable () {
0ffa7a0e 117 if (!this.videoChannel.isLocal) return false
a37e9e74 118 if (!this.isUserLoggedIn()) return false
119
120 return this.isOwner() || this.authService.getUser().hasRight(UserRight.MANAGE_ANY_VIDEO_CHANNEL)
121 }
122
a0dedc02 123 activateCopiedMessage () {
66357162 124 this.notifier.success($localize`Username copied`)
a0dedc02 125 }
60c35932 126
733dbc53
C
127 hasShowMoreDescription () {
128 return !this.channelDescriptionExpanded && this.channelDescriptionHTML.length > 100
129 }
130
100d9ce2
C
131 showSupportModal () {
132 this.supportModal.show()
133 }
134
733dbc53 135 getAccountUrl () {
71887396 136 return [ '/a', this.videoChannel.ownerBy ]
733dbc53
C
137 }
138
60c35932
C
139 private loadChannelVideosCount () {
140 this.videoService.getVideoChannelVideos({
141 videoChannel: this.videoChannel,
142 videoPagination: {
143 currentPage: 1,
144 itemsPerPage: 0
145 },
146 sort: '-publishedAt'
147 }).subscribe(res => this.channelVideosCount = res.total)
148 }
80badf49
C
149
150 private loadOwnerBlockStatus () {
151 this.blocklist.getStatus({ accounts: [ this.ownerAccount.nameWithHostForced ], hosts: [ this.ownerAccount.host ] })
152 .subscribe(status => this.ownerAccount.updateBlockStatus(status))
153 }
170726f5 154}