1 import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
2 import { ActivatedRoute } from '@angular/router'
3 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
4 import { VideoChannelService } from '@app/shared/video-channel/video-channel.service'
5 import { RestExtractor } from '@app/shared'
6 import { catchError, distinctUntilChanged, map, switchMap, tap } from 'rxjs/operators'
7 import { Subscription } from 'rxjs'
8 import { AuthService, Notifier } from '@app/core'
9 import { Hotkey, HotkeysService } from 'angular2-hotkeys'
10 import { SubscribeButtonComponent } from '@app/shared/user-subscription/subscribe-button.component'
11 import { I18n } from '@ngx-translate/i18n-polyfill'
12 import { ListOverflowItem } from '@app/shared/misc/list-overflow.component'
13 import { ScreenService } from '@app/shared/misc/screen.service'
16 templateUrl: './video-channels.component.html',
17 styleUrls: [ './video-channels.component.scss' ]
19 export class VideoChannelsComponent implements OnInit, OnDestroy {
20 @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
22 videoChannel: VideoChannel
24 links: ListOverflowItem[] = []
25 isChannelManageable = false
27 private routeSub: Subscription
31 private route: ActivatedRoute,
32 private notifier: Notifier,
33 private authService: AuthService,
34 private videoChannelService: VideoChannelService,
35 private restExtractor: RestExtractor,
36 private hotkeysService: HotkeysService,
37 private screenService: ScreenService
41 this.routeSub = this.route.params
43 map(params => params[ 'videoChannelName' ]),
44 distinctUntilChanged(),
45 switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
46 catchError(err => this.restExtractor.redirectTo404IfNotFound(err, [ 400, 404 ]))
48 .subscribe(videoChannel => {
49 this.videoChannel = videoChannel
51 if (this.authService.isLoggedIn()) {
52 this.authService.userInformationLoaded
54 const channelUserId = this.videoChannel.ownerAccount.userId
55 this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
61 new Hotkey('S', (event: KeyboardEvent): boolean => {
62 this.subscribeButton.subscribed ?
63 this.subscribeButton.unsubscribe() :
64 this.subscribeButton.subscribe()
66 }, undefined, this.i18n('Subscribe to the account'))
68 if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
71 { label: this.i18n('VIDEOS'), routerLink: 'videos' },
72 { label: this.i18n('VIDEO PLAYLISTS'), routerLink: 'video-playlists' },
73 { label: this.i18n('ABOUT'), routerLink: 'about' }
78 if (this.routeSub) this.routeSub.unsubscribe()
81 if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
84 get isInSmallView () {
85 return this.screenService.isInSmallView()
89 return this.authService.isLoggedIn()
93 if (!this.isUserLoggedIn()) return false
94 return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
97 activateCopiedMessage () {
98 this.notifier.success(this.i18n('Username copied'))