mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-07 19:57:56 +08:00
[client-app] deprecate returnsModel
param for nylas-api-request
Summary: We no longer need to use the `returnsModel` param since we get all of our models through the in memory delta stream. There were a ton of places unnecessarily passing `returnsModel: false` when it defaults to false in the first place Depends on D4057 Test Plan: manual Reviewers: halla, spang, juan Reviewed By: spang, juan Differential Revision: https://phab.nylas.com/D4065
This commit is contained in:
parent
abaf63202c
commit
ba1f429928
15 changed files with 6 additions and 34 deletions
|
@ -24,7 +24,6 @@ class ContactRankingsCache extends RefreshingJSONCache {
|
||||||
options: {
|
options: {
|
||||||
accountId: this._accountId,
|
accountId: this._accountId,
|
||||||
path: "/contacts/rankings",
|
path: "/contacts/rankings",
|
||||||
returnsModel: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,6 @@ export function runAuthRequest(accountInfo) {
|
||||||
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
|
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
|
||||||
body: data,
|
body: data,
|
||||||
auth: noauth,
|
auth: noauth,
|
||||||
returnsModel: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return n1CloudIMAPAuthRequest.run().then((remoteJSON) => {
|
return n1CloudIMAPAuthRequest.run().then((remoteJSON) => {
|
||||||
|
@ -148,7 +147,6 @@ export function runAuthRequest(accountInfo) {
|
||||||
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
|
timeout: 1000 * 90, // Connecting to IMAP could take up to 90 seconds, so we don't want to hang up too soon
|
||||||
body: data,
|
body: data,
|
||||||
auth: noauth,
|
auth: noauth,
|
||||||
returnsModel: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
return localSyncIMAPAuthRequest.run().then((localJSON) => {
|
return localSyncIMAPAuthRequest.run().then((localJSON) => {
|
||||||
|
|
|
@ -281,7 +281,6 @@ describe "NylasAPI", ->
|
||||||
expect(this.options.path).toBe "/drafts/#{draft.serverId}"
|
expect(this.options.path).toBe "/drafts/#{draft.serverId}"
|
||||||
expect(this.options.accountId).toBe TEST_ACCOUNT_ID
|
expect(this.options.accountId).toBe TEST_ACCOUNT_ID
|
||||||
expect(this.options.method).toBe "DELETE"
|
expect(this.options.method).toBe "DELETE"
|
||||||
expect(this.options.returnsModel).toBe false
|
|
||||||
NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
NylasAPIHelpers.makeDraftDeletionRequest(draft)
|
||||||
|
|
||||||
it "should increment the change tracker, preventing any further deltas about the draft", ->
|
it "should increment the change tracker, preventing any further deltas about the draft", ->
|
||||||
|
|
|
@ -120,14 +120,6 @@ xdescribe('SendDraftTask', function sendDraftTask() {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should pass returnsModel:false", () => {
|
|
||||||
waitsForPromise(() => this.task.performRemote().then(() => {
|
|
||||||
expect(NylasAPIRequest.prototype.run.calls.length).toBe(1);
|
|
||||||
const options = NylasAPIRequest.prototype.run.mostRecentCall.args[0];
|
|
||||||
expect(options.returnsModel).toBe(false);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should always send the draft body in the request body (joined attribute check)", () => {
|
it("should always send the draft body in the request body (joined attribute check)", () => {
|
||||||
waitsForPromise(() => this.task.performRemote().then(() => {
|
waitsForPromise(() => this.task.performRemote().then(() => {
|
||||||
expect(NylasAPIRequest.prototype.run.calls.length).toBe(1);
|
expect(NylasAPIRequest.prototype.run.calls.length).toBe(1);
|
||||||
|
|
|
@ -183,15 +183,6 @@ xdescribe('SyncbackDraftTask', function syncbackDraftTask() {
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should pass returnsModel:false so that the draft can be manually removed/added to the database, accounting for its ID change", () => {
|
|
||||||
const task = new SyncbackDraftTask("localDraftId");
|
|
||||||
waitsForPromise(() => task.performRemote().then(() => {
|
|
||||||
expect(NylasAPIRequest.prototype.run).toHaveBeenCalled();
|
|
||||||
const options = NylasAPIRequest.prototype.run.mostRecentCall.args[0];
|
|
||||||
expect(options.returnsModel).toBe(false);
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should save metadata associated with the draft when the draft has been already saved to the api", () => {
|
it("should save metadata associated with the draft when the draft has been already saved to the api", () => {
|
||||||
const draft = remoteDraft();
|
const draft = remoteDraft();
|
||||||
draft.pluginMetadata = [{pluginId: 1, value: {a: 1}}];
|
draft.pluginMetadata = [{pluginId: 1, value: {a: 1}}];
|
||||||
|
|
|
@ -147,7 +147,6 @@ xdescribe('SyncbackModelTask', function syncbackModelTask() {
|
||||||
expect(opts.path).toBe("/test")
|
expect(opts.path).toBe("/test")
|
||||||
expect(opts.method).toBe("POST")
|
expect(opts.method).toBe("POST")
|
||||||
expect(opts.accountId).toBe("account-123")
|
expect(opts.accountId).toBe("account-123")
|
||||||
expect(opts.returnsModel).toBe(false)
|
|
||||||
expect(opts.body).toEqual(this.testModel.toJSON())
|
expect(opts.body).toEqual(this.testModel.toJSON())
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Actions from './actions'
|
||||||
import {APIError} from './errors'
|
import {APIError} from './errors'
|
||||||
import DatabaseStore from './stores/database-store'
|
import DatabaseStore from './stores/database-store'
|
||||||
import NylasAPIRequest from './nylas-api-request'
|
import NylasAPIRequest from './nylas-api-request'
|
||||||
|
import NylasAPIHelpers from './nylas-api-helpers'
|
||||||
import ProviderSyncbackRequest from './models/provider-syncback-request'
|
import ProviderSyncbackRequest from './models/provider-syncback-request'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +62,6 @@ class SyncbackTaskAPIRequest {
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor({api, options}) {
|
constructor({api, options}) {
|
||||||
options.returnsModel = true
|
|
||||||
this._request = new NylasAPIRequest({api, options})
|
this._request = new NylasAPIRequest({api, options})
|
||||||
this._onSyncbackRequestCreated = options.onSyncbackRequestCreated || (() => {})
|
this._onSyncbackRequestCreated = options.onSyncbackRequestCreated || (() => {})
|
||||||
}
|
}
|
||||||
|
@ -69,12 +69,16 @@ class SyncbackTaskAPIRequest {
|
||||||
run() {
|
run() {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const syncbackRequest = await this._request.run()
|
const syncbackRequest = await this._request.run();
|
||||||
|
await NylasAPIHelpers.handleModelResponse(syncbackRequest)
|
||||||
await this._onSyncbackRequestCreated(syncbackRequest)
|
await this._onSyncbackRequestCreated(syncbackRequest)
|
||||||
const syncbackRequestId = syncbackRequest.id
|
const syncbackRequestId = syncbackRequest.id
|
||||||
SyncbackTaskAPIRequest.listenForRequest(syncbackRequestId)
|
SyncbackTaskAPIRequest.listenForRequest(syncbackRequestId)
|
||||||
.then(resolve).catch(reject)
|
.then(resolve).catch(reject)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
if (err.response && err.response.statusCode === 404) {
|
||||||
|
NylasAPIHelpers.handleModel404(this._request.options.url)
|
||||||
|
}
|
||||||
reject(err)
|
reject(err)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -231,7 +231,6 @@ export default class ChangeMailTask extends Task {
|
||||||
accountId: model.accountId,
|
accountId: model.accountId,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
body: this.requestBodyForModel(model),
|
body: this.requestBodyForModel(model),
|
||||||
returnsModel: true,
|
|
||||||
onSyncbackRequestCreated: (syncbackRequest) => {
|
onSyncbackRequestCreated: (syncbackRequest) => {
|
||||||
if (!this._syncbackRequestIds) this._syncbackRequestIds = {}
|
if (!this._syncbackRequestIds) this._syncbackRequestIds = {}
|
||||||
this._syncbackRequestIds[model.id] = syncbackRequest.id
|
this._syncbackRequestIds[model.id] = syncbackRequest.id
|
||||||
|
|
|
@ -64,7 +64,6 @@ export default class DestroyCategoryTask extends Task {
|
||||||
accountId,
|
accountId,
|
||||||
path,
|
path,
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
returnsModel: false,
|
|
||||||
onSyncbackRequestCreated: (syncbackRequest) => {
|
onSyncbackRequestCreated: (syncbackRequest) => {
|
||||||
this._syncbackRequestId = syncbackRequest.id
|
this._syncbackRequestId = syncbackRequest.id
|
||||||
},
|
},
|
||||||
|
|
|
@ -45,7 +45,6 @@ export default class DestroyDraftTask extends BaseDraftTask {
|
||||||
body: {
|
body: {
|
||||||
version: this.draft.version,
|
version: this.draft.version,
|
||||||
},
|
},
|
||||||
returnsModel: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -46,7 +46,6 @@ export default class EventRSVPTask extends Task {
|
||||||
event_id: id,
|
event_id: id,
|
||||||
status: this.RSVPResponse,
|
status: this.RSVPResponse,
|
||||||
},
|
},
|
||||||
returnsModel: true,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -67,9 +67,6 @@ export default class SyncbackCategoryTask extends Task {
|
||||||
body: {
|
body: {
|
||||||
display_name: this.displayName || this.category.displayName,
|
display_name: this.displayName || this.category.displayName,
|
||||||
},
|
},
|
||||||
// returnsModel must be false because we want to update the
|
|
||||||
// existing model rather than returning a new model.
|
|
||||||
returnsModel: false,
|
|
||||||
onSyncbackRequestCreated: (syncbackRequest) => {
|
onSyncbackRequestCreated: (syncbackRequest) => {
|
||||||
this._syncbackRequestId = syncbackRequest.id
|
this._syncbackRequestId = syncbackRequest.id
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,7 +21,6 @@ export default class SyncbackDraftTask extends BaseDraftTask {
|
||||||
path: (this.draft.serverId) ? `/drafts/${this.draft.serverId}` : "/drafts",
|
path: (this.draft.serverId) ? `/drafts/${this.draft.serverId}` : "/drafts",
|
||||||
method: (this.draft.serverId) ? 'PUT' : 'POST',
|
method: (this.draft.serverId) ? 'PUT' : 'POST',
|
||||||
body: this.draft.toJSON(),
|
body: this.draft.toJSON(),
|
||||||
returnsModel: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.run()
|
.run()
|
||||||
|
|
|
@ -29,7 +29,6 @@ export default class SyncbackMetadataTask extends SyncbackModelTask {
|
||||||
}
|
}
|
||||||
const options = {
|
const options = {
|
||||||
accountId: model.accountId,
|
accountId: model.accountId,
|
||||||
returnsModel: false,
|
|
||||||
path: `/metadata/${model.serverId}/${this.pluginId}`,
|
path: `/metadata/${model.serverId}/${this.pluginId}`,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
|
|
|
@ -53,7 +53,6 @@ export default class SyncbackModelTask extends Task {
|
||||||
try {
|
try {
|
||||||
const options = _.extend({
|
const options = _.extend({
|
||||||
accountId: model.accountId,
|
accountId: model.accountId,
|
||||||
returnsModel: false,
|
|
||||||
}, this.getRequestData(model));
|
}, this.getRequestData(model));
|
||||||
return new NylasAPIRequest({
|
return new NylasAPIRequest({
|
||||||
api: NylasAPI,
|
api: NylasAPI,
|
||||||
|
|
Loading…
Add table
Reference in a new issue