From 99e2d3b2d3d08280e83ed4d4bf18cd08d13a557f Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 24 Feb 2016 17:20:08 -0800 Subject: [PATCH] fix(sync-draft): Accept the thread id given to the draft server-side --- spec/tasks/syncback-draft-spec.coffee | 13 ++++++++++++- src/flux/tasks/syncback-draft.coffee | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/spec/tasks/syncback-draft-spec.coffee b/spec/tasks/syncback-draft-spec.coffee index ae3629d04..4c6ac4560 100644 --- a/spec/tasks/syncback-draft-spec.coffee +++ b/spec/tasks/syncback-draft-spec.coffee @@ -28,7 +28,7 @@ testData = body: '123' localDraft = -> new Message _.extend {}, testData, {clientId: "local-id"} -remoteDraft = -> new Message _.extend {}, testData, {clientId: "local-id", serverId: "remoteid1234"} +remoteDraft = -> new Message _.extend {}, testData, {clientId: "local-id", serverId: "remoteid1234", threadId: '1234', version: 2} describe "SyncbackDraftTask", -> beforeEach -> @@ -141,6 +141,17 @@ describe "SyncbackDraftTask", -> expect(options.accountId).toBe("abc123") expect(options.method).toBe('POST') + it "should apply the server ID, thread ID and version to the draft", -> + task = new SyncbackDraftTask("localDraftId") + waitsForPromise => + task.performRemote().then -> + expect(DatabaseTransaction.prototype.persistModel).toHaveBeenCalled() + saved = DatabaseTransaction.prototype.persistModel.calls[0].args[0] + remote = remoteDraft() + expect(saved.threadId).toEqual(remote.threadId) + expect(saved.serverId).toEqual(remote.serverId) + expect(saved.version).toEqual(remote.version) + it "should pass returnsModel:false so that the draft can be manually removed/added to the database, accounting for its ID change", -> task = new SyncbackDraftTask("localDraftId") waitsForPromise => diff --git a/src/flux/tasks/syncback-draft.coffee b/src/flux/tasks/syncback-draft.coffee index 35ab38267..7d5a3a044 100644 --- a/src/flux/tasks/syncback-draft.coffee +++ b/src/flux/tasks/syncback-draft.coffee @@ -67,7 +67,7 @@ class SyncbackDraftTask extends Task body: draft.toJSON() returnsModel: false - updateLocalDraft: ({version, id}) => + updateLocalDraft: ({version, id, thread_id}) => # Important: There could be a significant delay between us initiating the save # and getting JSON back from the server. Our local copy of the draft may have # already changed more. @@ -81,6 +81,7 @@ class SyncbackDraftTask extends Task # Draft may have been deleted. Oh well. return Promise.resolve() unless draft if draft.serverId isnt id + draft.threadId = thread_id draft.serverId = id draftIsNew = true draft.version = version