From 6856a2ccf75d866f99c81bce82aad11671987905 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Thu, 9 Feb 2017 14:42:42 -0800 Subject: [PATCH] [local-sync] When replying to a thread, properly add it to Sent folder Summary: Previously, when processing messages during folder sync, if the message already existed, and it belonged to a thread, we would update the message, but forget to update its thread with any changes that new message would produce on the thread (e.g. updating the threads folders or labels). One obvious manifestation of this was when replying to a thread: the EnsureMessageInSentFolderTask would create the new message, and then attempt to sync the sent folder to fetch the newly created message. When processing this message during sync, we would update the message but not update its thread, so the thread would not be associated to the sent folder, and it wouldn't show up in your sent items list in the UI. Test Plan: manually verify that it works Reviewers: evan, mark, spang Reviewed By: mark, spang Differential Revision: https://phab.nylas.com/D3872 --- packages/local-sync/src/message-processor/index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/local-sync/src/message-processor/index.js b/packages/local-sync/src/message-processor/index.js index 506bc0124..d5e66927a 100644 --- a/packages/local-sync/src/message-processor/index.js +++ b/packages/local-sync/src/message-processor/index.js @@ -93,7 +93,7 @@ class MessageProcessor { async _processMessage({accountId, folderId, imapMessage, struct, desiredParts}) { const db = await LocalDatabaseConnector.forAccount(accountId); - const {Message, Folder} = db + const {Message, Folder, Label} = db const folder = await Folder.findById(folderId) const accountDb = await LocalDatabaseConnector.forShared() const account = await accountDb.Account.findById(accountId) @@ -105,7 +105,9 @@ class MessageProcessor { folder, accountId, }); - const existingMessage = await Message.findById(messageValues.id); + const existingMessage = await Message.findById(messageValues.id, { + include: [{model: Folder, as: 'folder'}, {model: Label, as: 'labels'}], + }); let processedMessage; if (existingMessage) { // TODO: optimize to not do a full message parse for existing messages @@ -262,11 +264,15 @@ class MessageProcessor { await existingMessage.setLabels(messageValues.labels) } - let thread = await existingMessage.getThread(); + let thread = await existingMessage.getThread({ + include: [{model: db.Folder, as: 'folders'}, {model: db.Label, as: 'labels'}], + }); if (!existingMessage.isProcessed) { if (!thread) { thread = await detectThread({db, messageValues}); existingMessage.threadId = thread.id; + } else { + await thread.updateFromMessages({db, messages: [existingMessage]}) } await this._addReferences(db, existingMessage, thread, messageValues.references); const files = await extractFiles({db, messageValues: existingMessage, struct});