From 8f241048de38774bf53f676031b13b84f0f66dcf Mon Sep 17 00:00:00 2001 From: Evan Morikawa Date: Fri, 3 Feb 2017 19:27:56 -0800 Subject: [PATCH] fix(identity): properly post to identity endpoint --- .../thread-snooze/lib/snooze-store.es6 | 17 +++++++++++++++-- src/K2 | 2 +- src/flux/edgehill-api.es6 | 2 +- src/flux/stores/identity-store.es6 | 8 ++++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/internal_packages/thread-snooze/lib/snooze-store.es6 b/internal_packages/thread-snooze/lib/snooze-store.es6 index e351f89d8..90a4cee25 100644 --- a/internal_packages/thread-snooze/lib/snooze-store.es6 +++ b/internal_packages/thread-snooze/lib/snooze-store.es6 @@ -1,6 +1,7 @@ +import {remote} from 'electron' import _ from 'underscore'; -import {Actions, NylasAPIHelpers, AccountStore, DatabaseStore, Message, - CategoryStore} from 'nylas-exports'; +import {FeatureUsageStore, Actions, NylasAPIHelpers, AccountStore, + DatabaseStore, Message, CategoryStore} from 'nylas-exports'; import SnoozeUtils from './snooze-utils' import {PLUGIN_ID, PLUGIN_NAME} from './snooze-constants'; import SnoozeActions from './snooze-actions'; @@ -68,12 +69,22 @@ class SnoozeStore { }; onSnoozeThreads = (threads, snoozeDate, label) => { + if (!FeatureUsageStore.isUsable("snooze")) { + remote.dialog.showMessageBox({ + title: 'Out of snoozes', + detail: `You have used your monthly quota of Snoozes`, + buttons: ['OK'], + type: 'info', + }); + return Promise.resolve() + } this.recordSnoozeEvent(threads, snoozeDate, label) const accounts = AccountStore.accountsForItems(threads) const promises = accounts.map((acc) => { return NylasAPIHelpers.authPlugin(this.pluginId, this.pluginName, acc) }) + return Promise.all(promises) .then(() => { return SnoozeUtils.moveThreadsToSnooze(threads, this.snoozeCategoriesPromise, snoozeDate) @@ -96,6 +107,8 @@ class SnoozeStore { } }); }); + }).then(() => { + return FeatureUsageStore.useFeature('snooze') }) .catch((error) => { SnoozeUtils.moveThreadsFromSnooze(threads, this.snoozeCategoriesPromise) diff --git a/src/K2 b/src/K2 index a400ce3ce..7dbdd771b 160000 --- a/src/K2 +++ b/src/K2 @@ -1 +1 @@ -Subproject commit a400ce3ce9c19db1fc941fb9f3ebdd3892796630 +Subproject commit 7dbdd771b0764b1a6e1509a67876694501678889 diff --git a/src/flux/edgehill-api.es6 b/src/flux/edgehill-api.es6 index e20f0e49f..45dd0f7bc 100644 --- a/src/flux/edgehill-api.es6 +++ b/src/flux/edgehill-api.es6 @@ -14,7 +14,7 @@ class _EdgehillAPI { _onConfigChanged = () => { const env = NylasEnv.config.get('env') if (['development', 'local'].includes(env)) { - this.APIRoot = "http://localhost:5009"; + this.APIRoot = "http://n1-auth.lvh.me:5555"; } else if (env === 'experimental') { this.APIRoot = "https://edgehill-experimental.nylas.com"; } else if (env === 'staging') { diff --git a/src/flux/stores/identity-store.es6 b/src/flux/stores/identity-store.es6 index e7a73b839..fbc96067a 100644 --- a/src/flux/stores/identity-store.es6 +++ b/src/flux/stores/identity-store.es6 @@ -208,15 +208,19 @@ class IdentityStore extends NylasStore { startTime: Date.now(), }; try { - await this.nylasIDRequest(options) + const newIdentity = await this.nylasIDRequest(options); + return newIdentity } catch (err) { const error = err || new Error(`IdentityStore.fetchPath: ${path} ${err.message}.`) NylasEnv.reportError(error) + return null } } nylasIDRequest(options) { return new Promise((resolve, reject) => { + options.formData = false + options.json = true options.auth = { username: this._identity.token, password: '', @@ -236,7 +240,7 @@ class IdentityStore extends NylasStore { }); if (response.statusCode === 200) { try { - return resolve(JSON.parse(body)); + return resolve(body); } catch (err) { return reject(err) }