aboutsummaryrefslogtreecommitdiffhomepage
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/src/app/shared/user-subscription/subscribe-button.component.ts53
1 files changed, 29 insertions, 24 deletions
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 888f6552a..81a0df512 100644
--- a/client/src/app/shared/user-subscription/subscribe-button.component.ts
+++ b/client/src/app/shared/user-subscription/subscribe-button.component.ts
@@ -7,7 +7,8 @@ import { I18n } from '@ngx-translate/i18n-polyfill'
7import { VideoService } from '@app/shared/video/video.service' 7import { VideoService } from '@app/shared/video/video.service'
8import { FeedFormat } from '../../../../../shared/models/feeds' 8import { FeedFormat } from '../../../../../shared/models/feeds'
9import { Account } from '@app/shared/account/account.model' 9import { Account } from '@app/shared/account/account.model'
10import { forkJoin, merge } from 'rxjs' 10import { concat, forkJoin, merge } from 'rxjs'
11import { toArray } from 'rxjs/operators'
11 12
12@Component({ 13@Component({
13 selector: 'my-subscribe-button', 14 selector: 'my-subscribe-button',
@@ -82,12 +83,14 @@ export class SubscribeButtonComponent implements OnInit {
82 } 83 }
83 84
84 localSubscribe () { 85 localSubscribe () {
86 const subscribedStatus = this.subscribeStatus(false)
87
85 const observableBatch = this.videoChannels 88 const observableBatch = this.videoChannels
86 .map(videoChannel => this.getChannelHandler(videoChannel)) 89 .map(videoChannel => this.getChannelHandler(videoChannel))
87 .filter(handle => this.subscribeStatus(false).includes(handle)) 90 .filter(handle => subscribedStatus.includes(handle))
88 .map(handle => this.userSubscriptionService.addSubscription(handle)) 91 .map(handle => this.userSubscriptionService.addSubscription(handle))
89 92
90 merge(observableBatch, 2) 93 forkJoin(observableBatch)
91 .subscribe( 94 .subscribe(
92 () => { 95 () => {
93 this.notifier.success( 96 this.notifier.success(
@@ -116,25 +119,27 @@ export class SubscribeButtonComponent implements OnInit {
116 } 119 }
117 120
118 localUnsubscribe () { 121 localUnsubscribe () {
122 const subscribeStatus = this.subscribeStatus(true)
123
119 const observableBatch = this.videoChannels 124 const observableBatch = this.videoChannels
120 .map(videoChannel => this.getChannelHandler(videoChannel)) 125 .map(videoChannel => this.getChannelHandler(videoChannel))
121 .filter(handle => this.subscribeStatus(true).includes(handle)) 126 .filter(handle => subscribeStatus.includes(handle))
122 .map(handle => this.userSubscriptionService.deleteSubscription(handle)) 127 .map(handle => this.userSubscriptionService.deleteSubscription(handle))
123 128
124 forkJoin(observableBatch) 129 concat(...observableBatch)
125 .subscribe( 130 .subscribe({
126 () => { 131 complete: () => {
127 this.notifier.success( 132 this.notifier.success(
128 this.account 133 this.account
129 ? this.i18n('Unsubscribed from all channels of {{nameWithHost}}', { nameWithHost: this.account.nameWithHost }) 134 ? this.i18n('Unsubscribed from all channels of {{nameWithHost}}', { nameWithHost: this.account.nameWithHost })
130 : this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannels[0].nameWithHost }) 135 : this.i18n('Unsubscribed from {{nameWithHost}}', { nameWithHost: this.videoChannels[ 0 ].nameWithHost })
131 , 136 ,
132 this.i18n('Unsubscribed') 137 this.i18n('Unsubscribed')
133 ) 138 )
134 }, 139 },
135 140
136 err => this.notifier.error(err.message) 141 error: err => this.notifier.error(err.message)
137 ) 142 })
138 } 143 }
139 144
140 isUserLoggedIn () { 145 isUserLoggedIn () {
@@ -176,15 +181,15 @@ export class SubscribeButtonComponent implements OnInit {
176 for (const videoChannel of this.videoChannels) { 181 for (const videoChannel of this.videoChannels) {
177 const handle = this.getChannelHandler(videoChannel) 182 const handle = this.getChannelHandler(videoChannel)
178 this.subscribed.set(handle, false) 183 this.subscribed.set(handle, false)
184
179 merge( 185 merge(
180 this.userSubscriptionService.listenToSubscriptionCacheChange(handle), 186 this.userSubscriptionService.listenToSubscriptionCacheChange(handle),
181 this.userSubscriptionService.doesSubscriptionExist(handle) 187 this.userSubscriptionService.doesSubscriptionExist(handle)
182 ) 188 ).subscribe(
183 .subscribe( 189 res => this.subscribed.set(handle, res),
184 res => this.subscribed.set(handle, res),
185 190
186 err => this.notifier.error(err.message) 191 err => this.notifier.error(err.message)
187 ) 192 )
188 } 193 }
189 } 194 }
190} 195}