From 4480fd89a24e9b918bccbc55a89d1155a11cf373 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Thu, 26 Jan 2017 16:06:43 -0800 Subject: [PATCH] [local-sync] Correctly check presence of messages when updating thread Summary: updateMessagesFromThread requires `messages` to be an array only when recompute is falsy Test Plan: manual Reviewers: halla Reviewed By: halla Differential Revision: https://phab.nylas.com/D3797 --- packages/local-sync/src/models/thread.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/local-sync/src/models/thread.js b/packages/local-sync/src/models/thread.js index 5e56219b9..f37ddb280 100644 --- a/packages/local-sync/src/models/thread.js +++ b/packages/local-sync/src/models/thread.js @@ -99,9 +99,6 @@ module.exports = (sequelize, Sequelize) => { }, async updateFromMessages({db, messages, recompute, transaction} = {}) { - if (!(messages instanceof Array)) { - throw new Error('Thread.updateFromMessages() expected an array of messages') - } if (!(this.folders instanceof Array) || !(this.labels instanceof Array)) { throw new Error('Thread.updateFromMessages() expected .folders and .labels to be inflated arrays') } @@ -131,6 +128,12 @@ module.exports = (sequelize, Sequelize) => { this.firstMessageDate = null; this.lastMessageSentDate = null; this.lastMessageReceivedDate = null; + } else { + // If we're not recomputing from all of the thread's messages, we need + // to know which messages to update from + if (!(_messages instanceof Array)) { + throw new Error('Thread.updateFromMessages() expected an array of messages') + } } const folderIds = new Set(this.folders.map(f => f.id));