mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-01 13:14:16 +08:00
fix(sync-draft): Accept the thread id given to the draft server-side
This commit is contained in:
parent
cffa9c723c
commit
99e2d3b2d3
2 changed files with 14 additions and 2 deletions
|
@ -28,7 +28,7 @@ testData =
|
|||
body: '<body>123</body>'
|
||||
|
||||
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 =>
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue