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

129 lines
4.3 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'
2021-03-25 12:42:55 +00:00
import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService } from '@app/core'
import { ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
2021-03-29 13:56:01 +00:00
import { SupportModalComponent } from '@app/shared/shared-support-modal'
2020-06-23 12:10:17 +00:00
import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription'
2021-07-16 08:42:24 +00:00
import { HttpStatusCode } from '@shared/models'
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
2021-03-29 13:56:01 +00:00
@ViewChild('supportModal') supportModal: SupportModalComponent
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
2021-03-25 12:42:55 +00:00
channelVideosCount: number
ownerDescriptionHTML = ''
channelDescriptionHTML = ''
channelDescriptionExpanded = false
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,
2021-03-25 12:42:55 +00:00
private videoService: VideoService,
private restExtractor: RestExtractor,
private hotkeysService: HotkeysService,
2021-03-25 12:42:55 +00:00
private screenService: ScreenService,
private markdown: MarkdownService
) { }
2018-04-25 14:56:13 +00:00
ngOnInit () {
this.routeSub = this.route.params
.pipe(
2021-08-17 12:42:53 +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
]))
)
2021-03-25 12:42:55 +00:00
.subscribe(async videoChannel => {
this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.description)
this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.ownerAccount.description)
// After the markdown renderer to avoid layout changes
2020-01-22 14:01:38 +00:00
this.videoChannel = videoChannel
2021-03-25 12:42:55 +00:00
this.loadChannelVideosCount()
2020-01-22 14:01:38 +00:00
})
this.hotkeys = [
new Hotkey('S', (event: KeyboardEvent): boolean => {
2021-08-17 12:42:53 +00:00
if (this.subscribeButton.subscribed) this.subscribeButton.unsubscribe()
else 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`PLAYLISTS`, routerLink: 'video-playlists' }
]
}
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
2021-03-25 12:42:55 +00:00
isInSmallView () {
return this.screenService.isInSmallView()
}
2018-08-30 12:58:00 +00:00
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
2021-03-25 12:42:55 +00:00
isManageable () {
if (!this.isUserLoggedIn()) return false
2021-03-25 12:42:55 +00:00
2021-03-26 12:20:37 +00:00
return this.videoChannel?.ownerAccount.userId === this.authService.getUser().id
}
activateCopiedMessage () {
this.notifier.success($localize`Username copied`)
}
2021-03-25 12:42:55 +00:00
hasShowMoreDescription () {
return !this.channelDescriptionExpanded && this.channelDescriptionHTML.length > 100
}
2021-03-29 13:56:01 +00:00
showSupportModal () {
this.supportModal.show()
}
getAccountUrl () {
return [ '/a', this.videoChannel.ownerBy ]
}
2021-03-25 12:42:55 +00:00
private loadChannelVideosCount () {
this.videoService.getVideoChannelVideos({
videoChannel: this.videoChannel,
videoPagination: {
currentPage: 1,
itemsPerPage: 0
},
sort: '-publishedAt'
}).subscribe(res => this.channelVideosCount = res.total)
}
2018-04-25 14:56:13 +00:00
}