]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/+my-account/my-account-applications/my-account-applications.component.ts
Update translations
[github/Chocobozzz/PeerTube.git] / client / src / app / +my-account / my-account-applications / my-account-applications.component.ts
index c3f09dfe38d8da89c5a5b45e038ff202cfe374c9..e88cdd228697e3df9d9e02fbbd0f6b841cbfce01 100644 (file)
@@ -1,10 +1,9 @@
-
 import { Component, OnInit } from '@angular/core'
-import { AuthService, Notifier, ConfirmService } from '@app/core'
+import { AuthService, ConfirmService, Notifier, ScopedTokensService } from '@app/core'
 import { VideoService } from '@app/shared/shared-main'
 import { FeedFormat } from '@shared/models'
-import { Subject, merge } from 'rxjs'
-import { debounceTime } from 'rxjs/operators'
+import { ScopedToken } from '@shared/models/users/user-scoped-token'
+import { environment } from '../../../environments/environment'
 
 @Component({
   selector: 'my-account-applications',
@@ -15,11 +14,11 @@ export class MyAccountApplicationsComponent implements OnInit {
   feedUrl: string
   feedToken: string
 
-  private baseURL = window.location.protocol + '//' + window.location.host
-  private tokenStream = new Subject()
+  private baseURL = environment.originServerUrl || window.location.origin
 
   constructor (
     private authService: AuthService,
+    private scopedTokensService: ScopedTokensService,
     private videoService: VideoService,
     private notifier: Notifier,
     private confirmService: ConfirmService
@@ -27,31 +26,37 @@ export class MyAccountApplicationsComponent implements OnInit {
 
   ngOnInit () {
     this.feedUrl = this.baseURL
+    this.scopedTokensService.getScopedTokens()
+      .subscribe({
+        next: tokens => this.regenApplications(tokens),
 
-    merge(
-      this.tokenStream,
-      this.authService.userInformationLoaded
-    ).pipe(debounceTime(400))
-     .subscribe(
-       _ => {
-         const user = this.authService.getUser()
-         this.videoService.getVideoSubscriptionFeedUrls(user.account.id)
-                          .then(feeds => this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url)
-                          .then(_ => this.authService.getScopedTokens().then(tokens => this.feedToken = tokens.feedToken))
-       },
-
-       err => {
-         this.notifier.error(err.message)
-       }
-     )
+        error: err => this.notifier.error(err.message)
+      })
   }
 
   async renewToken () {
-    const res = await this.confirmService.confirm('Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?', 'Renew token')
+    const res = await this.confirmService.confirm(
+      // eslint-disable-next-line max-len
+      $localize`Renewing the token will disallow previously configured clients from retrieving the feed until they use the new token. Proceed?`,
+      $localize`Renew token`
+    )
     if (res === false) return
 
-    await this.authService.renewScopedTokens()
-    this.notifier.success('Token renewed. Update your client configuration accordingly.')
-    this.tokenStream.next()
+    this.scopedTokensService.renewScopedTokens()
+      .subscribe({
+        next: tokens => {
+          this.regenApplications(tokens)
+          this.notifier.success($localize`Token renewed. Update your client configuration accordingly.`)
+        },
+
+        error: err => this.notifier.error(err.message)
+      })
+  }
+
+  private regenApplications (tokens: ScopedToken) {
+    const user = this.authService.getUser()
+    const feeds = this.videoService.getVideoSubscriptionFeedUrls(user.account.id, tokens.feedToken)
+    this.feedUrl = this.baseURL + feeds.find(f => f.format === FeedFormat.RSS).url
+    this.feedToken = tokens.feedToken
   }
 }