[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
This commit is contained in:
Juan Tejada 2017-02-09 14:42:42 -08:00
parent cec55f7188
commit 6856a2ccf7

View file

@ -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});