diff --git a/src/appstore.js b/src/appstore.js index 035a85134..6a562291c 100644 --- a/src/appstore.js +++ b/src/appstore.js @@ -5,6 +5,7 @@ exports = module.exports = { unpurchase: unpurchase, getSubscription: getSubscription, + isFreePlan: isFreePlan, sendAliveStatus: sendAliveStatus, @@ -90,6 +91,10 @@ function getSubscription(callback) { }); } +function isFreePlan(subscription) { + return !subscription || subscription.plan.id === 'free'; +} + function purchase(appId, appstoreId, callback) { assert.strictEqual(typeof appId, 'string'); assert.strictEqual(typeof appstoreId, 'string'); diff --git a/src/digest.js b/src/digest.js index be6332113..01c11815f 100644 --- a/src/digest.js +++ b/src/digest.js @@ -28,11 +28,9 @@ function maybeSend(callback) { var pendingAppUpdates = updateInfo.apps || {}; pendingAppUpdates = Object.keys(pendingAppUpdates).map(function (key) { return pendingAppUpdates[key]; }); - appstore.getSubscription(function (error, result) { + appstore.getSubscription(function (error, subscription) { if (error) debug('Error getting subscription:', error); - var hasSubscription = result && result.plan.id !== 'free'; - eventlog.getByCreationTime(new Date(new Date() - 7*86400000), function (error, events) { if (error) return callback(error); @@ -46,7 +44,7 @@ function maybeSend(callback) { if (error) return callback(error); var info = { - hasSubscription: hasSubscription, + hasSubscription: appstore.isFreePlan(subscription), pendingAppUpdates: pendingAppUpdates, pendingBoxUpdate: updateInfo.box || null, diff --git a/src/updatechecker.js b/src/updatechecker.js index 02548f91a..2ee128c69 100644 --- a/src/updatechecker.js +++ b/src/updatechecker.js @@ -105,7 +105,7 @@ function checkAppUpdates(callback) { } // always send notifications if user is on the free plan - if (result.plan.id === 'free') { + if (appstore.isFreePlan(result)) { debug('Notifying user of app update for %s from %s to %s', app.id, app.manifest.version, updateInfo.manifest.version); mailer.appUpdateAvailable(app, false /* subscription */, updateInfo); return iteratorDone(); @@ -162,7 +162,7 @@ function checkBoxUpdates(callback) { } // always send notifications if user is on the free plan - if (result.plan.id === 'free') { + if (appstore.isFreePlan(result)) { mailer.boxUpdateAvailable(false /* hasSubscription */, updateInfo.version, updateInfo.changelog); return done(); }