]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
Don't manage remote channels
[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
C
58 .subscribe(async videoChannel => {
59 this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.description)
60 this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.ownerAccount.description)
61
62 // After the markdown renderer to avoid layout changes
fef213ca 63 this.videoChannel = videoChannel
80badf49 64 this.ownerAccount = new Account(this.videoChannel.ownerAccount)
fef213ca 65
60c35932 66 this.loadChannelVideosCount()
80badf49 67 this.loadOwnerBlockStatus()
fef213ca 68 })
734a5ceb 69
20d21199
RK
70 this.hotkeys = [
71 new Hotkey('S', (event: KeyboardEvent): boolean => {
9df52d66
C
72 if (this.subscribeButton.subscribed) this.subscribeButton.unsubscribe()
73 else this.subscribeButton.subscribe()
74
20d21199 75 return false
66357162 76 }, undefined, $localize`Subscribe to the account`)
20d21199
RK
77 ]
78 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
24e7916c
RK
79
80 this.links = [
66357162 81 { label: $localize`VIDEOS`, routerLink: 'videos' },
0a25749f 82 { label: $localize`PLAYLISTS`, routerLink: 'video-playlists' }
24e7916c 83 ]
734a5ceb 84 }
170726f5 85
734a5ceb
C
86 ngOnDestroy () {
87 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
88
89 // Unbind hotkeys
90 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 91 }
2d3741d6 92
60c35932 93 isInSmallView () {
937b7a6a
RK
94 return this.screenService.isInSmallView()
95 }
96
2d3741d6
C
97 isUserLoggedIn () {
98 return this.authService.isLoggedIn()
99 }
a0dedc02 100
a37e9e74 101 isOwner () {
aa0f1963 102 if (!this.isUserLoggedIn()) return false
60c35932 103
67264e06 104 return this.videoChannel?.ownerAccount.userId === this.authService.getUser().id
aa0f1963
RK
105 }
106
a37e9e74 107 isManageable () {
0ffa7a0e 108 if (!this.videoChannel.isLocal) return false
a37e9e74 109 if (!this.isUserLoggedIn()) return false
110
111 return this.isOwner() || this.authService.getUser().hasRight(UserRight.MANAGE_ANY_VIDEO_CHANNEL)
112 }
113
a0dedc02 114 activateCopiedMessage () {
66357162 115 this.notifier.success($localize`Username copied`)
a0dedc02 116 }
60c35932 117
733dbc53
C
118 hasShowMoreDescription () {
119 return !this.channelDescriptionExpanded && this.channelDescriptionHTML.length > 100
120 }
121
100d9ce2
C
122 showSupportModal () {
123 this.supportModal.show()
124 }
125
733dbc53 126 getAccountUrl () {
71887396 127 return [ '/a', this.videoChannel.ownerBy ]
733dbc53
C
128 }
129
60c35932
C
130 private loadChannelVideosCount () {
131 this.videoService.getVideoChannelVideos({
132 videoChannel: this.videoChannel,
133 videoPagination: {
134 currentPage: 1,
135 itemsPerPage: 0
136 },
137 sort: '-publishedAt'
138 }).subscribe(res => this.channelVideosCount = res.total)
139 }
80badf49
C
140
141 private loadOwnerBlockStatus () {
142 this.blocklist.getStatus({ accounts: [ this.ownerAccount.nameWithHostForced ], hosts: [ this.ownerAccount.host ] })
143 .subscribe(status => this.ownerAccount.updateBlockStatus(status))
144 }
170726f5 145}