]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+video-channels/video-channels.component.ts
Translated using Weblate (Spanish)
[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'
67ed6552
C
6import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core'
7import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main'
8import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
170726f5
C
9
10@Component({
11 templateUrl: './video-channels.component.html',
12 styleUrls: [ './video-channels.component.scss' ]
13})
734a5ceb 14export class VideoChannelsComponent implements OnInit, OnDestroy {
2f5d2ec5 15 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
20d21199 16
170726f5 17 videoChannel: VideoChannel
20d21199 18 hotkeys: Hotkey[]
24e7916c 19 links: ListOverflowItem[] = []
fef213ca 20 isChannelManageable = false
170726f5 21
734a5ceb
C
22 private routeSub: Subscription
23
170726f5
C
24 constructor (
25 private route: ActivatedRoute,
a0dedc02 26 private notifier: Notifier,
2d3741d6 27 private authService: AuthService,
a51bad1a 28 private videoChannelService: VideoChannelService,
20d21199 29 private restExtractor: RestExtractor,
937b7a6a 30 private hotkeysService: HotkeysService,
edb86865 31 private screenService: ScreenService
734a5ceb 32 ) { }
170726f5
C
33
34 ngOnInit () {
734a5ceb
C
35 this.routeSub = this.route.params
36 .pipe(
2f1548fd 37 map(params => params[ 'videoChannelName' ]),
734a5ceb 38 distinctUntilChanged(),
2f1548fd 39 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
734a5ceb
C
40 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
41 )
fef213ca
C
42 .subscribe(videoChannel => {
43 this.videoChannel = videoChannel
44
45 if (this.authService.isLoggedIn()) {
46 this.authService.userInformationLoaded
47 .subscribe(() => {
48 const channelUserId = this.videoChannel.ownerAccount.userId
49 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
50 })
51 }
52 })
734a5ceb 53
20d21199
RK
54 this.hotkeys = [
55 new Hotkey('S', (event: KeyboardEvent): boolean => {
56 this.subscribeButton.subscribed ?
57 this.subscribeButton.unsubscribe() :
58 this.subscribeButton.subscribe()
59 return false
66357162 60 }, undefined, $localize`Subscribe to the account`)
20d21199
RK
61 ]
62 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
24e7916c
RK
63
64 this.links = [
66357162
C
65 { label: $localize`VIDEOS`, routerLink: 'videos' },
66 { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' },
67 { label: $localize`ABOUT`, routerLink: 'about' }
24e7916c 68 ]
734a5ceb 69 }
170726f5 70
734a5ceb
C
71 ngOnDestroy () {
72 if (this.routeSub) this.routeSub.unsubscribe()
20d21199
RK
73
74 // Unbind hotkeys
75 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
170726f5 76 }
2d3741d6 77
937b7a6a
RK
78 get isInSmallView () {
79 return this.screenService.isInSmallView()
80 }
81
2d3741d6
C
82 isUserLoggedIn () {
83 return this.authService.isLoggedIn()
84 }
a0dedc02 85
aa0f1963
RK
86 get isManageable () {
87 if (!this.isUserLoggedIn()) return false
88 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
89 }
90
a0dedc02 91 activateCopiedMessage () {
66357162 92 this.notifier.success($localize`Username copied`)
a0dedc02 93 }
170726f5 94}