2018-06-21 04:27:37 +02:00
|
|
|
import { Component, NgZone, OnDestroy, OnInit } from "@angular/core";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.service";
|
|
|
|
import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.service";
|
|
|
|
import { OrganizationService } from "@bitwarden/common/abstractions/organization.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { TokenService } from "@bitwarden/common/abstractions/token.service";
|
2018-07-03 15:27:59 +02:00
|
|
|
|
2022-05-09 14:21:52 +02:00
|
|
|
import { StateService } from "../../abstractions/state.service";
|
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
const BroadcasterSubscriptionId = "SettingsComponent";
|
|
|
|
|
2018-06-21 04:27:37 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-settings",
|
|
|
|
templateUrl: "settings.component.html",
|
|
|
|
})
|
2018-07-03 15:27:59 +02:00
|
|
|
export class SettingsComponent implements OnInit, OnDestroy {
|
|
|
|
premium: boolean;
|
2019-02-18 22:10:32 +01:00
|
|
|
selfHosted: boolean;
|
2021-11-22 14:41:40 +01:00
|
|
|
hasFamilySponsorshipAvailable: boolean;
|
2022-05-09 14:21:52 +02:00
|
|
|
hideSubscription: boolean;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
constructor(
|
|
|
|
private tokenService: TokenService,
|
|
|
|
private broadcasterService: BroadcasterService,
|
2021-11-22 14:41:40 +01:00
|
|
|
private ngZone: NgZone,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
2022-05-09 14:21:52 +02:00
|
|
|
private organizationService: OrganizationService,
|
|
|
|
private stateService: StateService,
|
|
|
|
private apiService: ApiService
|
2021-12-14 17:10:26 +01:00
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
async ngOnInit() {
|
|
|
|
this.broadcasterService.subscribe(BroadcasterSubscriptionId, async (message: any) => {
|
|
|
|
this.ngZone.run(async () => {
|
|
|
|
switch (message.command) {
|
|
|
|
case "purchasedPremium":
|
|
|
|
await this.load();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
});
|
2021-12-17 15:57:11 +01:00
|
|
|
});
|
|
|
|
|
2019-02-18 22:10:32 +01:00
|
|
|
this.selfHosted = await this.platformUtilsService.isSelfHost();
|
2018-07-03 15:27:59 +02:00
|
|
|
await this.load();
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.broadcasterService.unsubscribe(BroadcasterSubscriptionId);
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-03 15:27:59 +02:00
|
|
|
async load() {
|
2022-06-14 04:13:41 +02:00
|
|
|
this.premium = await this.stateService.getHasPremiumPersonally();
|
2021-12-14 17:10:26 +01:00
|
|
|
this.hasFamilySponsorshipAvailable = await this.organizationService.canManageSponsorships();
|
2022-06-14 04:13:41 +02:00
|
|
|
const hasPremiumFromOrg = await this.stateService.getHasPremiumFromOrganization();
|
2022-05-12 14:43:27 +02:00
|
|
|
let billing = null;
|
|
|
|
if (!this.selfHosted) {
|
|
|
|
billing = await this.apiService.getUserBillingHistory();
|
|
|
|
}
|
|
|
|
this.hideSubscription =
|
|
|
|
!this.premium && hasPremiumFromOrg && (this.selfHosted || billing?.hasNoHistory);
|
2018-07-03 15:27:59 +02:00
|
|
|
}
|
|
|
|
}
|