From c3890fe50d2ddd9ecb582595e0b11a5bada4ddc6 Mon Sep 17 00:00:00 2001 From: Aman Harwara Date: Mon, 4 Sep 2023 21:13:42 +0530 Subject: [PATCH] chore: dont show alert on every role change --- .../snjs/lib/Services/Features/FeaturesService.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/snjs/lib/Services/Features/FeaturesService.ts b/packages/snjs/lib/Services/Features/FeaturesService.ts index aadba4d29..3c32b61f4 100644 --- a/packages/snjs/lib/Services/Features/FeaturesService.ts +++ b/packages/snjs/lib/Services/Features/FeaturesService.ts @@ -360,7 +360,8 @@ export class FeaturesService const isInitialLoadRolesChange = previousRoles.length === 0 if (!isInitialLoadRolesChange) { - if (this.onlineRolesIncludePaidSubscription()) { + const didPreviousRolesIncludePaidSubscription = this.rolesIncludePaidSubscription(previousRoles) + if (this.onlineRolesIncludePaidSubscription() && !didPreviousRolesIncludePaidSubscription) { await this.notifyEvent(FeaturesEvent.DidPurchaseSubscription) } } @@ -395,10 +396,16 @@ export class FeaturesService return !isNativeFeature } - onlineRolesIncludePaidSubscription(): boolean { - const unpaidRoles = [RoleName.NAMES.CoreUser] + private rolesIncludePaidSubscription(roles: string[]) { + { + const unpaidRoles = [RoleName.NAMES.CoreUser] - return this.onlineRoles.some((role) => !unpaidRoles.includes(role)) + return roles.some((role) => !unpaidRoles.includes(role)) + } + } + + onlineRolesIncludePaidSubscription(): boolean { + return this.rolesIncludePaidSubscription(this.onlineRoles) } public rolesBySorting(roles: string[]): string[] {