[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
This commit is contained in:
Juan Tejada 2017-01-26 16:06:43 -08:00
parent 651a199cb6
commit 4480fd89a2

View file

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