From fb705fc5dd7a7dabb163f0750fb2a0b8b266d5b0 Mon Sep 17 00:00:00 2001 From: Christine Spang Date: Tue, 10 Jan 2017 07:45:35 -0800 Subject: [PATCH] [local-sync] Remove unused message update hook Summary: Message bodies, drafts aside, are immutable, and we set the snippet on new messages manually in parseFromImap()---meaning this hook, if invoked, is likely to replace the snippet with a broken version computed with this old implementation. If we need a hook in the future (e.g. for updating drafts), it should use the snippet function from message-factory. Test Plan: n/a Reviewers: juan, halla Reviewed By: juan Differential Revision: https://phab.nylas.com/D3622 --- packages/local-sync/package.json | 1 - packages/local-sync/src/models/message.js | 18 +++++------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/local-sync/package.json b/packages/local-sync/package.json index 169c152c6..2ee18d967 100644 --- a/packages/local-sync/package.json +++ b/packages/local-sync/package.json @@ -23,7 +23,6 @@ "rx": "4.1.0", "sequelize": "nylas/sequelize#nylas-3.30.0", "sqlite3": "https://github.com/bengotow/node-sqlite3/archive/bengotow/usleep-v3.1.4.tar.gz", - "striptags": "2.1.1", "underscore": "1.8.3", "vision": "4.1.0" }, diff --git a/packages/local-sync/src/models/message.js b/packages/local-sync/src/models/message.js index a13979863..716b91de0 100644 --- a/packages/local-sync/src/models/message.js +++ b/packages/local-sync/src/models/message.js @@ -1,12 +1,9 @@ const crypto = require('crypto') -const striptags = require('striptags'); const {PromiseUtils, IMAPConnection} = require('isomorphic-core') const {DatabaseTypes: {JSONArrayColumn}} = require('isomorphic-core'); const {Errors: {APIError}} = require('isomorphic-core') -const SNIPPET_LENGTH = 191; - function validateRecipientsPresent(message) { if (message.getRecipients().length === 0) { throw new APIError(`No recipients specified`, 400); @@ -25,6 +22,11 @@ module.exports = (sequelize, Sequelize) => { subject: Sequelize.STRING(500), snippet: Sequelize.STRING(255), date: Sequelize.DATE, + // TODO: We do not currently sync drafts with the remote. When we add + // this feature, we need to be careful because this breaks the assumption + // that messages, modulo their flags and folders/labels, are immutable. + // Particularly, we will need to implement logic to make sure snippets + // stay in sync with the current message body. isDraft: Sequelize.BOOLEAN, isSent: Sequelize.BOOLEAN, isSending: Sequelize.BOOLEAN, @@ -67,16 +69,6 @@ module.exports = (sequelize, Sequelize) => { {fields: ['gMsgId']}, // Use in `searchThreads` {fields: ['folderImapUID']}, // Use in `searchThreads` ], - hooks: { - beforeUpdate(message) { - // Update the snippet if the body has changed - if (!message.changed('body')) { return; } - - const plainText = striptags(message.body); - // consolidate whitespace groups into single spaces and then truncate - message.snippet = plainText.split(/\s+/).join(" ").substring(0, SNIPPET_LENGTH) - }, - }, classMethods: { associate({Message, Folder, Label, File, Thread, MessageLabel}) { Message.belongsTo(Thread)