X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=client%2Fsrc%2Fapp%2Fshared%2Fuser-subscription%2Fsubscribe-button.component.ts;h=0407856cbd1d89827e404e99974a6fddcc23062d;hb=f332ffa2a2e9bd7d223c78b6123dbba272f21e84;hp=46d6dbaf7f861253e72b611fce629007ccc8dc27;hpb=22a16e36f6526887ed8f5e5d3c9f9e5da0b4a8cd;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/shared/user-subscription/subscribe-button.component.ts b/client/src/app/shared/user-subscription/subscribe-button.component.ts index 46d6dbaf7..0407856cb 100644 --- a/client/src/app/shared/user-subscription/subscribe-button.component.ts +++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts @@ -1,11 +1,11 @@ import { Component, Input, OnInit } from '@angular/core' -import { AuthService } from '@app/core' -import { RestExtractor } from '@app/shared/rest' -import { RedirectService } from '@app/core/routing/redirect.service' +import { Router } from '@angular/router' +import { AuthService, Notifier } from '@app/core' import { UserSubscriptionService } from '@app/shared/user-subscription/user-subscription.service' import { VideoChannel } from '@app/shared/video-channel/video-channel.model' -import { NotificationsService } from 'angular2-notifications' import { I18n } from '@ngx-translate/i18n-polyfill' +import { VideoService } from '@app/shared/video/video.service' +import { FeedFormat } from '../../../../../shared/models/feeds' @Component({ selector: 'my-subscribe-button', @@ -15,60 +15,99 @@ import { I18n } from '@ngx-translate/i18n-polyfill' export class SubscribeButtonComponent implements OnInit { @Input() videoChannel: VideoChannel @Input() displayFollowers = false + @Input() size: 'small' | 'normal' = 'normal' subscribed: boolean constructor ( private authService: AuthService, - private restExtractor: RestExtractor, - private redirectService: RedirectService, - private notificationsService: NotificationsService, + private router: Router, + private notifier: Notifier, private userSubscriptionService: UserSubscriptionService, - private i18n: I18n + private i18n: I18n, + private videoService: VideoService ) { } - get uri () { + get channelHandle () { return this.videoChannel.name + '@' + this.videoChannel.host } + get channelUri () { + return this.videoChannel.url + } + + get rssUri () { + const rssFeed = this.videoService + .getVideoChannelFeedUrls(this.videoChannel.id) + .find(i => i.format === FeedFormat.RSS) + + return rssFeed.url + } + ngOnInit () { - this.userSubscriptionService.isSubscriptionExists(this.uri) - .subscribe( - exists => this.subscribed = exists, + if (this.isUserLoggedIn()) { + this.userSubscriptionService.doesSubscriptionExist(this.channelHandle) + .subscribe( + res => this.subscribed = res[this.channelHandle], - err => this.notificationsService.error(this.i18n('Error'), err.message) - ) + err => this.notifier.error(err.message) + ) + } } subscribe () { - this.userSubscriptionService.addSubscription(this.uri) + if (this.isUserLoggedIn()) { + return this.localSubscribe() + } + + return this.gotoLogin() + } + + localSubscribe () { + this.userSubscriptionService.addSubscription(this.channelHandle) .subscribe( () => { this.subscribed = true - this.notificationsService.success( - this.i18n('Subscribed'), - this.i18n('Subscribed to {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }) + this.notifier.success( + this.i18n('Subscribed to {{nameWithHost}}. You will be notified of all their new videos.', + { nameWithHost: this.videoChannel.displayName } + ), + this.i18n('Subscribed') ) }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } unsubscribe () { - this.userSubscriptionService.deleteSubscription(this.uri) + if (this.isUserLoggedIn()) { + this.localUnsubscribe() + } + } + + localUnsubscribe () { + this.userSubscriptionService.deleteSubscription(this.channelHandle) .subscribe( () => { this.subscribed = false - this.notificationsService.success( - this.i18n('Unsubscribed'), - this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }) + this.notifier.success( + this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannel.displayName }), + this.i18n('Unsubscribed') ) }, - err => this.notificationsService.error(this.i18n('Error'), err.message) + err => this.notifier.error(err.message) ) } + + isUserLoggedIn () { + return this.authService.isLoggedIn() + } + + gotoLogin () { + this.router.navigate([ '/login' ]) + } }