1
0
Fork 0
peertube/client/src/app/+video-channels/video-channels.component.ts

99 lines
3.6 KiB
TypeScript
Raw Normal View History

2020-06-23 12:10:17 +00:00
import { Hotkey, HotkeysService } from 'angular2-hotkeys'
import { Subscription } from 'rxjs'
import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators'
import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core'
2018-04-25 14:56:13 +00:00
import { ActivatedRoute } from '@angular/router'
2020-06-23 12:10:17 +00:00
import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core'
import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main'
import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes'
2018-04-25 14:56:13 +00:00
@Component({
templateUrl: './video-channels.component.html',
styleUrls: [ './video-channels.component.scss' ]
})
export class VideoChannelsComponent implements OnInit, OnDestroy {
2020-02-07 09:00:34 +00:00
@ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent
2018-04-25 14:56:13 +00:00
videoChannel: VideoChannel
hotkeys: Hotkey[]
links: ListOverflowItem[] = []
2020-01-22 14:01:38 +00:00
isChannelManageable = false
2018-04-25 14:56:13 +00:00
private routeSub: Subscription
2018-04-25 14:56:13 +00:00
constructor (
private route: ActivatedRoute,
private notifier: Notifier,
2018-08-30 12:58:00 +00:00
private authService: AuthService,
2018-05-31 09:35:01 +00:00
private videoChannelService: VideoChannelService,
private restExtractor: RestExtractor,
private hotkeysService: HotkeysService,
2020-03-10 13:08:42 +00:00
private screenService: ScreenService
) { }
2018-04-25 14:56:13 +00:00
ngOnInit () {
this.routeSub = this.route.params
.pipe(
2019-01-08 10:26:41 +00:00
map(params => params[ 'videoChannelName' ]),
distinctUntilChanged(),
2019-01-08 10:26:41 +00:00
switchMap(videoChannelName => this.videoChannelService.getVideoChannel(videoChannelName)),
catchError(err => this.restExtractor.redirectTo404IfNotFound(err, 'other', [
HttpStatusCode.BAD_REQUEST_400,
HttpStatusCode.NOT_FOUND_404
]))
)
2020-01-22 14:01:38 +00:00
.subscribe(videoChannel => {
this.videoChannel = videoChannel
if (this.authService.isLoggedIn()) {
this.authService.userInformationLoaded
.subscribe(() => {
const channelUserId = this.videoChannel.ownerAccount.userId
this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id
})
}
})
this.hotkeys = [
new Hotkey('S', (event: KeyboardEvent): boolean => {
this.subscribeButton.subscribed ?
this.subscribeButton.unsubscribe() :
this.subscribeButton.subscribe()
return false
}, undefined, $localize`Subscribe to the account`)
]
if (this.isUserLoggedIn()) this.hotkeysService.add(this.hotkeys)
this.links = [
{ label: $localize`VIDEOS`, routerLink: 'videos' },
{ label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' },
{ label: $localize`ABOUT`, routerLink: 'about' }
]
}
2018-04-25 14:56:13 +00:00
ngOnDestroy () {
if (this.routeSub) this.routeSub.unsubscribe()
// Unbind hotkeys
if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys)
2018-04-25 14:56:13 +00:00
}
2018-08-30 12:58:00 +00:00
get isInSmallView () {
return this.screenService.isInSmallView()
}
2018-08-30 12:58:00 +00:00
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
get isManageable () {
if (!this.isUserLoggedIn()) return false
return this.videoChannel.ownerAccount.userId === this.authService.getUser().id
}
activateCopiedMessage () {
this.notifier.success($localize`Username copied`)
}
2018-04-25 14:56:13 +00:00
}