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

150 lines
5.2 KiB
TypeScript
Raw Normal View History

2020-06-23 12:10:17 +00:00
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'
import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService, Hotkey, HotkeysService } from '@app/core'
import { Account, ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main'
import { BlocklistService } from '@app/shared/shared-moderation'
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'
import { HttpStatusCode, UserRight } from '@peertube/peertube-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
ownerAccount: Account
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,
private blocklist: BlocklistService
) { }
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({
markdown: videoChannel.description,
withEmoji: true,
withHtml: true
})
this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML({
markdown: videoChannel.ownerAccount.description,
withEmoji: true,
withHtml: true
})
2021-03-25 12:42:55 +00:00
// After the markdown renderer to avoid layout changes
2020-01-22 14:01:38 +00:00
this.videoChannel = videoChannel
this.ownerAccount = new Account(this.videoChannel.ownerAccount)
2020-01-22 14:01:38 +00:00
2021-03-25 12:42:55 +00:00
this.loadChannelVideosCount()
this.loadOwnerBlockStatus()
2020-01-22 14:01:38 +00:00
})
this.hotkeys = [
new Hotkey('Shift+s', () => {
if (this.subscribeButton.isSubscribedToAll()) this.subscribeButton.unsubscribe()
2021-08-17 12:42:53 +00:00
else this.subscribeButton.subscribe()
return false
}, $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()
}
isOwner () {
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
}
isManageable () {
2022-02-10 09:41:22 +00:00
if (!this.videoChannel.isLocal) return false
if (!this.isUserLoggedIn()) return false
return this.isOwner() || this.authService.getUser().hasRight(UserRight.MANAGE_ANY_VIDEO_CHANNEL)
}
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)
}
private loadOwnerBlockStatus () {
this.blocklist.getStatus({ accounts: [ this.ownerAccount.nameWithHostForced ], hosts: [ this.ownerAccount.host ] })
.subscribe(status => this.ownerAccount.updateBlockStatus(status))
}
2018-04-25 14:56:13 +00:00
}