import { concat, forkJoin, merge } from 'rxjs'
import { Component, Input, OnChanges, OnInit } from '@angular/core'
-import { Router } from '@angular/router'
-import { AuthService, Notifier } from '@app/core'
+import { AuthService, Notifier, RedirectService } from '@app/core'
import { Account, VideoChannel, VideoService } from '@app/shared/shared-main'
-import { I18n } from '@ngx-translate/i18n-polyfill'
import { FeedFormat } from '@shared/models'
import { UserSubscriptionService } from './user-subscription.service'
constructor (
private authService: AuthService,
- private router: Router,
+ private redirectService: RedirectService,
private notifier: Notifier,
private userSubscriptionService: UserSubscriptionService,
- private i18n: I18n,
private videoService: VideoService
) { }
.map(handle => this.userSubscriptionService.addSubscription(handle))
forkJoin(observableBatch)
- .subscribe(
- () => {
+ .subscribe({
+ next: () => {
this.notifier.success(
this.account
- ? this.i18n(
- 'Subscribed to all current channels of {{nameWithHost}}. You will be notified of all their new videos.',
- { nameWithHost: this.account.displayName }
- )
- : this.i18n(
- 'Subscribed to {{nameWithHost}}. You will be notified of all their new videos.',
- { nameWithHost: this.videoChannels[0].displayName }
- )
- ,
- this.i18n('Subscribed')
+ ? $localize`Subscribed to all current channels of ${this.account.displayName}. You will be notified of all their new videos.`
+ : $localize`Subscribed to ${this.videoChannels[0].displayName}. You will be notified of all their new videos.`,
+
+ $localize`Subscribed`
)
},
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
unsubscribe () {
complete: () => {
this.notifier.success(
this.account
- ? this.i18n('Unsubscribed from all channels of {{nameWithHost}}', { nameWithHost: this.account.nameWithHost })
- : this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannels[ 0 ].nameWithHost })
- ,
- this.i18n('Unsubscribed')
+ ? $localize`Unsubscribed from all channels of ${this.account.nameWithHost}`
+ : $localize`Unsubscribed from ${this.videoChannels[0].nameWithHost}`,
+
+ $localize`Unsubscribed`
)
},
}
gotoLogin () {
- this.router.navigate([ '/login' ])
+ this.redirectService.redirectToLogin()
}
subscribeStatus (subscribed: boolean) {
const accumulator: string[] = []
- for (const [key, value] of this.subscribed.entries()) {
+ for (const [ key, value ] of this.subscribed.entries()) {
if (value === subscribed) accumulator.push(key)
}
return accumulator
}
+ isSubscribedToAll () {
+ return Array.from(this.subscribed.values()).every(v => v === true)
+ }
+
+ isRemoteSubscribeAvailable () {
+ return !this.isUserLoggedIn()
+ }
+
private getChannelHandler (videoChannel: VideoChannel) {
return videoChannel.name + '@' + videoChannel.host
}
merge(
this.userSubscriptionService.listenToSubscriptionCacheChange(handle),
this.userSubscriptionService.doesSubscriptionExist(handle)
- ).subscribe(
- res => this.subscribed.set(handle, res),
+ ).subscribe({
+ next: res => this.subscribed.set(handle, res),
- err => this.notifier.error(err.message)
- )
+ error: err => this.notifier.error(err.message)
+ })
}
}
}