diff options
Diffstat (limited to 'client/src/app/+video-channels/video-channels.component.ts')
-rw-r--r-- | client/src/app/+video-channels/video-channels.component.ts | 62 |
1 files changed, 46 insertions, 16 deletions
diff --git a/client/src/app/+video-channels/video-channels.component.ts b/client/src/app/+video-channels/video-channels.component.ts index bb601e227..41fdb5e79 100644 --- a/client/src/app/+video-channels/video-channels.component.ts +++ b/client/src/app/+video-channels/video-channels.component.ts | |||
@@ -3,8 +3,9 @@ import { Subscription } from 'rxjs' | |||
3 | import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators' | 3 | import { catchError, distinctUntilChanged, map, switchMap } from 'rxjs/operators' |
4 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' | 4 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
5 | import { ActivatedRoute } from '@angular/router' | 5 | import { ActivatedRoute } from '@angular/router' |
6 | import { AuthService, Notifier, RestExtractor, ScreenService } from '@app/core' | 6 | import { AuthService, MarkdownService, Notifier, RestExtractor, ScreenService } from '@app/core' |
7 | import { ListOverflowItem, VideoChannel, VideoChannelService } from '@app/shared/shared-main' | 7 | import { ListOverflowItem, VideoChannel, VideoChannelService, VideoService } from '@app/shared/shared-main' |
8 | import { SupportModalComponent } from '@app/shared/shared-support-modal' | ||
8 | import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' | 9 | import { SubscribeButtonComponent } from '@app/shared/shared-user-subscription' |
9 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | 10 | import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' |
10 | 11 | ||
@@ -14,12 +15,18 @@ import { HttpStatusCode } from '@shared/core-utils/miscs/http-error-codes' | |||
14 | }) | 15 | }) |
15 | export class VideoChannelsComponent implements OnInit, OnDestroy { | 16 | export class VideoChannelsComponent implements OnInit, OnDestroy { |
16 | @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent | 17 | @ViewChild('subscribeButton') subscribeButton: SubscribeButtonComponent |
18 | @ViewChild('supportModal') supportModal: SupportModalComponent | ||
17 | 19 | ||
18 | videoChannel: VideoChannel | 20 | videoChannel: VideoChannel |
19 | hotkeys: Hotkey[] | 21 | hotkeys: Hotkey[] |
20 | links: ListOverflowItem[] = [] | 22 | links: ListOverflowItem[] = [] |
21 | isChannelManageable = false | 23 | isChannelManageable = false |
22 | 24 | ||
25 | channelVideosCount: number | ||
26 | ownerDescriptionHTML = '' | ||
27 | channelDescriptionHTML = '' | ||
28 | channelDescriptionExpanded = false | ||
29 | |||
23 | private routeSub: Subscription | 30 | private routeSub: Subscription |
24 | 31 | ||
25 | constructor ( | 32 | constructor ( |
@@ -27,9 +34,11 @@ export class VideoChannelsComponent implements OnInit, OnDestroy { | |||
27 | private notifier: Notifier, | 34 | private notifier: Notifier, |
28 | private authService: AuthService, | 35 | private authService: AuthService, |
29 | private videoChannelService: VideoChannelService, | 36 | private videoChannelService: VideoChannelService, |
37 | private videoService: VideoService, | ||
30 | private restExtractor: RestExtractor, | 38 | private restExtractor: RestExtractor, |
31 | private hotkeysService: HotkeysService, | 39 | private hotkeysService: HotkeysService, |
32 | private screenService: ScreenService | 40 | private screenService: ScreenService, |
41 | private markdown: MarkdownService | ||
33 | ) { } | 42 | ) { } |
34 | 43 | ||
35 | ngOnInit () { | 44 | ngOnInit () { |
@@ -43,16 +52,14 @@ export class VideoChannelsComponent implements OnInit, OnDestroy { | |||
43 | HttpStatusCode.NOT_FOUND_404 | 52 | HttpStatusCode.NOT_FOUND_404 |
44 | ])) | 53 | ])) |
45 | ) | 54 | ) |
46 | .subscribe(videoChannel => { | 55 | .subscribe(async videoChannel => { |
56 | this.channelDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.description) | ||
57 | this.ownerDescriptionHTML = await this.markdown.textMarkdownToHTML(videoChannel.ownerAccount.description) | ||
58 | |||
59 | // After the markdown renderer to avoid layout changes | ||
47 | this.videoChannel = videoChannel | 60 | this.videoChannel = videoChannel |
48 | 61 | ||
49 | if (this.authService.isLoggedIn()) { | 62 | this.loadChannelVideosCount() |
50 | this.authService.userInformationLoaded | ||
51 | .subscribe(() => { | ||
52 | const channelUserId = this.videoChannel.ownerAccount.userId | ||
53 | this.isChannelManageable = channelUserId && channelUserId === this.authService.getUser().id | ||
54 | }) | ||
55 | } | ||
56 | }) | 63 | }) |
57 | 64 | ||
58 | this.hotkeys = [ | 65 | this.hotkeys = [ |
@@ -67,8 +74,7 @@ export class VideoChannelsComponent implements OnInit, OnDestroy { | |||
67 | 74 | ||
68 | this.links = [ | 75 | this.links = [ |
69 | { label: $localize`VIDEOS`, routerLink: 'videos' }, | 76 | { label: $localize`VIDEOS`, routerLink: 'videos' }, |
70 | { label: $localize`VIDEO PLAYLISTS`, routerLink: 'video-playlists' }, | 77 | { label: $localize`PLAYLISTS`, routerLink: 'video-playlists' } |
71 | { label: $localize`ABOUT`, routerLink: 'about' } | ||
72 | ] | 78 | ] |
73 | } | 79 | } |
74 | 80 | ||
@@ -79,7 +85,7 @@ export class VideoChannelsComponent implements OnInit, OnDestroy { | |||
79 | if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys) | 85 | if (this.isUserLoggedIn()) this.hotkeysService.remove(this.hotkeys) |
80 | } | 86 | } |
81 | 87 | ||
82 | get isInSmallView () { | 88 | isInSmallView () { |
83 | return this.screenService.isInSmallView() | 89 | return this.screenService.isInSmallView() |
84 | } | 90 | } |
85 | 91 | ||
@@ -87,12 +93,36 @@ export class VideoChannelsComponent implements OnInit, OnDestroy { | |||
87 | return this.authService.isLoggedIn() | 93 | return this.authService.isLoggedIn() |
88 | } | 94 | } |
89 | 95 | ||
90 | get isManageable () { | 96 | isManageable () { |
91 | if (!this.isUserLoggedIn()) return false | 97 | if (!this.isUserLoggedIn()) return false |
92 | return this.videoChannel.ownerAccount.userId === this.authService.getUser().id | 98 | |
99 | return this.videoChannel?.ownerAccount.userId === this.authService.getUser().id | ||
93 | } | 100 | } |
94 | 101 | ||
95 | activateCopiedMessage () { | 102 | activateCopiedMessage () { |
96 | this.notifier.success($localize`Username copied`) | 103 | this.notifier.success($localize`Username copied`) |
97 | } | 104 | } |
105 | |||
106 | hasShowMoreDescription () { | ||
107 | return !this.channelDescriptionExpanded && this.channelDescriptionHTML.length > 100 | ||
108 | } | ||
109 | |||
110 | showSupportModal () { | ||
111 | this.supportModal.show() | ||
112 | } | ||
113 | |||
114 | getAccountUrl () { | ||
115 | return [ '/accounts', this.videoChannel.ownerBy ] | ||
116 | } | ||
117 | |||
118 | private loadChannelVideosCount () { | ||
119 | this.videoService.getVideoChannelVideos({ | ||
120 | videoChannel: this.videoChannel, | ||
121 | videoPagination: { | ||
122 | currentPage: 1, | ||
123 | itemsPerPage: 0 | ||
124 | }, | ||
125 | sort: '-publishedAt' | ||
126 | }).subscribe(res => this.channelVideosCount = res.total) | ||
127 | } | ||
98 | } | 128 | } |