Skip to content

Commit fb2adbc

Browse files
committed
chore: power user survey for subscribers and ligged in users support
1 parent 4356ba1 commit fb2adbc

File tree

2 files changed

+47
-21
lines changed

2 files changed

+47
-21
lines changed

src/extensionsIntegrated/Phoenix/guided-tour.js

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,15 @@
1-
/*
2-
* GNU AGPL-3.0 License
3-
*
4-
* Copyright (c) 2021 - present core.ai . All rights reserved.
5-
*
6-
* This program is free software: you can redistribute it and/or modify it
7-
* under the terms of the GNU Affero General Public License as published by
8-
* the Free Software Foundation, either version 3 of the License, or
9-
* (at your option) any later version.
10-
*
11-
* This program is distributed in the hope that it will be useful, but WITHOUT
12-
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13-
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14-
* for more details.
15-
*
16-
* You should have received a copy of the GNU Affero General Public License
17-
* along with this program. If not, see https://opensource.org/licenses/AGPL-3.0.
18-
*
19-
*/
1+
// SPDX-License-Identifier: AGPL-3.0-only
2+
// Copyright (c) 2021 - present core.ai. All rights reserved.
3+
4+
/*global logger*/
205

216
define(function (require, exports, module) {
7+
const KernalModeTrust = window.KernalModeTrust;
8+
if(!KernalModeTrust){
9+
// integrated extensions will have access to kernal mode, but not external extensions
10+
throw new Error("Guided Tour should have access to KernalModeTrust. Cannot boot without trust ring");
11+
}
12+
2213
const NotificationUI = require("widgets/NotificationUI"),
2314
Commands = require("command/Commands"),
2415
Strings = require("strings"),
@@ -244,6 +235,23 @@ define(function (require, exports, module) {
244235
PhStore.setItem(GUIDED_TOUR_LOCAL_STORAGE_KEY, JSON.stringify(userAlreadyDidAction));
245236
}
246237

238+
async function _resolvePowerUserSurveyURL(surveyJson) {
239+
try {
240+
const isLoggedIn = KernalModeTrust.EntitlementsManager.isLoggedIn();
241+
if(!isLoggedIn) {
242+
return surveyJson.powerUser;
243+
}
244+
const paidSubscriber = await KernalModeTrust.EntitlementsManager.isPaidSubscriber();
245+
if(paidSubscriber && surveyJson.powerUserPaid) {
246+
return surveyJson.powerUserPaid;
247+
}
248+
return surveyJson.powerUserLoggedIn || surveyJson.powerUser;
249+
} catch (e) {
250+
logger.reportError(e, "Error resolving power user survey URL");
251+
}
252+
return surveyJson.powerUser;
253+
}
254+
247255
async function _showSurveys() {
248256
try {
249257
if(!navigator.onLine){
@@ -258,6 +266,8 @@ define(function (require, exports, module) {
258266
newUserShowDelayMS: surveyJSON.browser.newUserShowDelayMS || surveyJSON.newUserShowDelayMS,
259267
newUserUseDialog: surveyJSON.browser.newUserUseDialog || surveyJSON.newUserUseDialog,
260268
powerUser: surveyJSON.browser.powerUser || surveyJSON.powerUser,
269+
powerUserPaid: surveyJSON.browser.powerUserPaid || surveyJSON.powerUserPaid,
270+
powerUserLoggedIn: surveyJSON.browser.powerUserLoggedIn || surveyJSON.powerUserLoggedIn,
261271
powerUserTitle: surveyJSON.browser.powerUserTitle || surveyJSON.powerUserTitle,
262272
powerUserShowIntervalDays: surveyJSON.browser.powerUserShowIntervalDays
263273
|| surveyJSON.powerUserShowIntervalDays,
@@ -266,7 +276,8 @@ define(function (require, exports, module) {
266276
}
267277
surveyJSON.newUser && _showFirstUseSurvey(surveyJSON.newUser, surveyJSON.newUserShowDelayMS,
268278
surveyJSON.newUserTitle, surveyJSON.newUserUseDialog);
269-
surveyJSON.powerUser && _showRepeatUserSurvey(surveyJSON.powerUser, surveyJSON.powerUserShowIntervalDays,
279+
const powerUserSurveyURL = await _resolvePowerUserSurveyURL(surveyJSON);
280+
powerUserSurveyURL && _showRepeatUserSurvey(powerUserSurveyURL, surveyJSON.powerUserShowIntervalDays,
270281
surveyJSON.powerUserTitle, surveyJSON.powerUserUseDialog);
271282
} catch (e) {
272283
console.error("Error fetching survey link", surveyLinksURL, e);

src/services/EntitlementsManager.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ define(function (require, exports, module) {
5555
* @returns {*}
5656
*/
5757
function isLoggedIn() {
58-
return LoginService.isLoggedIn();
58+
return LoginService && LoginService.isLoggedIn();
5959
}
6060

6161
/**
@@ -109,6 +109,19 @@ define(function (require, exports, module) {
109109
};
110110
}
111111

112+
/**
113+
* Checks if the current user is a paid subscriber (has purchased a plan, not trial users)
114+
*
115+
* @return {Promise<boolean>} A promise that resolves to true if the user is a paid subscriber, false otherwise.
116+
*/
117+
async function isPaidSubscriber() {
118+
if(!isLoggedIn()) {
119+
return false;
120+
}
121+
const planDetails = await getPlanDetails();
122+
return !!planDetails.paidSubscriber;
123+
}
124+
112125
/**
113126
* Check if user is in a pro trial. IF the user is in pro trail, then `plan.isSubscriber` will always be true.
114127
* @returns {Promise<boolean>} True if user is in pro trial, false otherwise
@@ -339,6 +352,7 @@ define(function (require, exports, module) {
339352
EntitlementsService: EntitlementsManager,
340353
isLoggedIn,
341354
getPlanDetails,
355+
isPaidSubscriber,
342356
isInProTrial,
343357
getTrialRemainingDays,
344358
getRawEntitlements,
@@ -355,6 +369,7 @@ define(function (require, exports, module) {
355369
EntitlementsManager.isLoggedIn = isLoggedIn;
356370
EntitlementsManager.loginToAccount = loginToAccount;
357371
EntitlementsManager.getPlanDetails = getPlanDetails;
372+
EntitlementsManager.isPaidSubscriber = isPaidSubscriber;
358373
EntitlementsManager.isInProTrial = isInProTrial;
359374
EntitlementsManager.getTrialRemainingDays = getTrialRemainingDays;
360375
EntitlementsManager.getRawEntitlements = getRawEntitlements;

0 commit comments

Comments
 (0)