From 5beb89f223539f1e415a976ff104f772526b4d20 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Mon, 9 Nov 2020 16:25:27 +0100 Subject: refactor scoped token service --- .../my-account-applications.component.html | 4 +- .../my-account-applications.component.ts | 59 +++++++++++++--------- client/src/app/+my-account/my-account.component.ts | 10 ++-- client/src/app/+my-account/my-account.module.ts | 4 +- 4 files changed, 43 insertions(+), 34 deletions(-) (limited to 'client/src/app/+my-account') diff --git a/client/src/app/+my-account/my-account-applications/my-account-applications.component.html b/client/src/app/+my-account/my-account-applications/my-account-applications.component.html index 62e2cb59b..53a9c91ac 100644 --- a/client/src/app/+my-account/my-account-applications/my-account-applications.component.html +++ b/client/src/app/+my-account/my-account-applications/my-account-applications.component.html @@ -7,8 +7,8 @@

SUBSCRIPTION FEED

- Used to retrieve the list of videos of the creators - you subscribed to from outside PeerTube + Use third-party feed aggregators to retrieve the list of videos from + channels you subscribed to. Make sure to keep your token private.
diff --git a/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts index c3f09dfe3..233e42c83 100644 --- a/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts +++ b/client/src/app/+my-account/my-account-applications/my-account-applications.component.ts @@ -1,10 +1,10 @@ import { Component, OnInit } from '@angular/core' -import { AuthService, Notifier, ConfirmService } from '@app/core' +import { AuthService, Notifier, ConfirmService, 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 +15,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 constructor ( private authService: AuthService, + private scopedTokensService: ScopedTokensService, private videoService: VideoService, private notifier: Notifier, private confirmService: ConfirmService @@ -27,31 +27,40 @@ export class MyAccountApplicationsComponent implements OnInit { ngOnInit () { this.feedUrl = this.baseURL + this.scopedTokensService.getScopedTokens() + .subscribe( + 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) - } - ) + 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( + $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( + tokens => { + this.regenApplications(tokens) + this.notifier.success($localize`Token renewed. Update your client configuration accordingly.`) + }, + + 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 } } diff --git a/client/src/app/+my-account/my-account.component.ts b/client/src/app/+my-account/my-account.component.ts index 12966aebb..eaf8a72e9 100644 --- a/client/src/app/+my-account/my-account.component.ts +++ b/client/src/app/+my-account/my-account.component.ts @@ -41,11 +41,6 @@ export class MyAccountComponent implements OnInit { label: $localize`Abuse reports`, routerLink: '/my-account/abuses', iconName: 'flag' - }, - { - label: $localize`Applications`, - routerLink: '/my-account/applications', - iconName: 'codesandbox' } ] } @@ -61,6 +56,11 @@ export class MyAccountComponent implements OnInit { routerLink: '/my-account/notifications' }, + { + label: $localize`Applications`, + routerLink: '/my-account/applications' + }, + moderationEntries ] } diff --git a/client/src/app/+my-account/my-account.module.ts b/client/src/app/+my-account/my-account.module.ts index 70bf58aae..076864563 100644 --- a/client/src/app/+my-account/my-account.module.ts +++ b/client/src/app/+my-account/my-account.module.ts @@ -20,8 +20,8 @@ import { MyAccountDangerZoneComponent } from './my-account-settings/my-account-d import { MyAccountNotificationPreferencesComponent } from './my-account-settings/my-account-notification-preferences' import { MyAccountProfileComponent } from './my-account-settings/my-account-profile/my-account-profile.component' import { MyAccountSettingsComponent } from './my-account-settings/my-account-settings.component' +import { MyAccountApplicationsComponent } from './my-account-applications/my-account-applications.component' import { MyAccountComponent } from './my-account.component' -import { VideoChangeOwnershipComponent } from './my-account-applications/my-account-applications.component' @NgModule({ imports: [ @@ -46,13 +46,13 @@ import { VideoChangeOwnershipComponent } from './my-account-applications/my-acco MyAccountChangePasswordComponent, MyAccountProfileComponent, MyAccountChangeEmailComponent, + MyAccountApplicationsComponent, MyAccountDangerZoneComponent, MyAccountBlocklistComponent, MyAccountAbusesListComponent, MyAccountServerBlocklistComponent, MyAccountNotificationsComponent, - MyAccountNotificationPreferencesComponent, MyAccountNotificationPreferencesComponent ], -- cgit v1.2.3