Skip to content

Commit dbec037

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

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/extensionsIntegrated/Phoenix/guided-tour.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
*
1919
*/
2020

21+
/*global logger*/
22+
2123
define(function (require, exports, module) {
24+
const KernalModeTrust = window.KernalModeTrust;
25+
if(!KernalModeTrust){
26+
// integrated extensions will have access to kernal mode, but not external extensions
27+
throw new Error("Guided Tour should have access to KernalModeTrust. Cannot boot without trust ring");
28+
}
29+
2230
const NotificationUI = require("widgets/NotificationUI"),
2331
Commands = require("command/Commands"),
2432
Strings = require("strings"),
@@ -244,6 +252,23 @@ define(function (require, exports, module) {
244252
PhStore.setItem(GUIDED_TOUR_LOCAL_STORAGE_KEY, JSON.stringify(userAlreadyDidAction));
245253
}
246254

255+
async function _resolvePowerUserSurveyURL(surveyJson) {
256+
try {
257+
const isLoggedIn = KernalModeTrust.EntitlementsManager.isLoggedIn();
258+
if(!isLoggedIn) {
259+
return surveyJson.powerUser;
260+
}
261+
const paidSubscriber = await KernalModeTrust.EntitlementsManager.isPaidSubscriber();
262+
if(paidSubscriber && surveyJson.PowerUserPaid) {
263+
return surveyJson.PowerUserPaid;
264+
}
265+
return surveyJson.PowerUserLoggedIn || surveyJson.powerUser;
266+
} catch (e) {
267+
logger.reportError(e, "Error resolving power user survey URL");
268+
}
269+
return surveyJson.powerUser;
270+
}
271+
247272
async function _showSurveys() {
248273
try {
249274
if(!navigator.onLine){
@@ -258,6 +283,8 @@ define(function (require, exports, module) {
258283
newUserShowDelayMS: surveyJSON.browser.newUserShowDelayMS || surveyJSON.newUserShowDelayMS,
259284
newUserUseDialog: surveyJSON.browser.newUserUseDialog || surveyJSON.newUserUseDialog,
260285
powerUser: surveyJSON.browser.powerUser || surveyJSON.powerUser,
286+
PowerUserPaid: surveyJSON.browser.PowerUserPaid || surveyJSON.PowerUserPaid,
287+
PowerUserLoggedIn: surveyJSON.browser.PowerUserLoggedIn || surveyJSON.PowerUserLoggedIn,
261288
powerUserTitle: surveyJSON.browser.powerUserTitle || surveyJSON.powerUserTitle,
262289
powerUserShowIntervalDays: surveyJSON.browser.powerUserShowIntervalDays
263290
|| surveyJSON.powerUserShowIntervalDays,
@@ -266,7 +293,8 @@ define(function (require, exports, module) {
266293
}
267294
surveyJSON.newUser && _showFirstUseSurvey(surveyJSON.newUser, surveyJSON.newUserShowDelayMS,
268295
surveyJSON.newUserTitle, surveyJSON.newUserUseDialog);
269-
surveyJSON.powerUser && _showRepeatUserSurvey(surveyJSON.powerUser, surveyJSON.powerUserShowIntervalDays,
296+
const powerUserSurveyURL = await _resolvePowerUserSurveyURL(surveyJSON);
297+
surveyJSON.powerUser && _showRepeatUserSurvey(powerUserSurveyURL, surveyJSON.powerUserShowIntervalDays,
270298
surveyJSON.powerUserTitle, surveyJSON.powerUserUseDialog);
271299
} catch (e) {
272300
console.error("Error fetching survey link", surveyLinksURL, e);

src/services/EntitlementsManager.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ define(function (require, exports, module) {
109109
};
110110
}
111111

112+
/**
113+
* Determines if the current user is a paid subscriber. A paid subscriber is a user who has paid $ for any pro-plan.
114+
*
115+
* @return {Promise<boolean>} A promise that resolves to a boolean indicating whether the user is a paid subscriber.
116+
*/
117+
async function isPaidSubscriber() {
118+
if(!LoginService.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)