]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - 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
1 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
2 import { Subscription } from 'rxjs'
3 import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
4 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
5 import { ActivatedRoute } from '@angular/router'
6 import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core'
7 import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main'
8 import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
9
10 @Component({
11 templateUrl: './video-channels.component.html',
12 styleUrls: [ './video-channels.component.scss' ]
13 })
14 export class VideoChannelsComponent implements OnInit, OnDestroy {
15 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
16
17 videoChannel: VideoChannel
18 hotkeys: Hotkey[]
19 links: ListOverflowItem[] = []
20 isChannelManageable = false
21
22 private routeSub: Subscription
23
24 constructor (
25 private route: ActivatedRoute,
26 private notifier: Notifier,
27 private authService: AuthService,
28 private videoChannelService: VideoChannelService,
29 private restExtractor: RestExtractor,
30 private hotkeysService: HotkeysService,
31 private screenService: ScreenService
32 ) { }
33
34 ngOnInit () {
35 this.routeSub = this.route.params
36 .pipe(
37 map(params => params[ 'videoChannelName' ]),
38 distinctUntilChanged(),
39 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
40 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
41 )
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 })
53
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
60 }, undefined, $localize`Subscribe to the account`)
61 ]
62 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
63
64 this.links = [
65 { label: $localize`VIDEOS`, routerLink: 'videos' },
66 { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' },
67 { label: $localize`ABOUT`, routerLink: 'about' }
68 ]
69 }
70
71 ngOnDestroy () {
72 if (this.routeSub) this.routeSub.unsubscribe()
73
74 // Unbind hotkeys
75 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
76 }
77
78 get isInSmallView () {
79 return this.screenService.isInSmallView()
80 }
81
82 isUserLoggedIn () {
83 return this.authService.isLoggedIn()
84 }
85
86 get isManageable () {
87 if (!this.isUserLoggedIn()) return false
88 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
89 }
90
91 activateCopiedMessage () {
92 this.notifier.success($localize`Username copied`)
93 }
94 }