Add replyTo to message model

This commit is contained in:
Ben Gotow 2016-06-29 16:10:39 -07:00
parent da27959009
commit b00b1e6d21
5 changed files with 20 additions and 5 deletions

View file

@ -50,6 +50,10 @@ const validate = (request, username, password, callback) => {
return return
} }
token.getAccount().then((account) => { token.getAccount().then((account) => {
if (!account) {
callback(new Error("Could not find Account referenced by AccountToken"), false, {});
return;
}
SchedulerUtils.notifyAccountIsActive(account.id) SchedulerUtils.notifyAccountIsActive(account.id)
callback(null, true, account); callback(null, true, account);
}); });

View file

@ -22,6 +22,7 @@ module.exports = (sequelize, Sequelize) => {
from: JSONARRAYType('from'), from: JSONARRAYType('from'),
cc: JSONARRAYType('cc'), cc: JSONARRAYType('cc'),
bcc: JSONARRAYType('bcc'), bcc: JSONARRAYType('bcc'),
replyTo: JSONARRAYType('replyTo'),
categoryUID: { type: Sequelize.STRING, allowNull: true}, categoryUID: { type: Sequelize.STRING, allowNull: true},
}, { }, {
indexes: [ indexes: [
@ -72,6 +73,11 @@ module.exports = (sequelize, Sequelize) => {
body: this.body, body: this.body,
subject: this.subject, subject: this.subject,
snippet: this.snippet, snippet: this.snippet,
to: this.to,
from: this.from,
cc: this.cc,
bcc: this.bcc,
reply_to: this.replyTo,
date: this.date.getTime() / 1000.0, date: this.date.getTime() / 1000.0,
unread: this.unread, unread: this.unread,
starred: this.starred, starred: this.starred,

View file

@ -15,6 +15,10 @@ module.exports = (sequelize, Sequelize) => {
lastMessageSentDate: Sequelize.DATE, lastMessageSentDate: Sequelize.DATE,
participants: JSONARRAYType('participants'), participants: JSONARRAYType('participants'),
}, { }, {
indexes: [
{ fields: ['subject'] },
{ fields: ['threadId'] },
],
classMethods: { classMethods: {
associate: ({Category, Message, ThreadCategory}) => { associate: ({Category, Message, ThreadCategory}) => {
Thread.belongsToMany(Category, {through: ThreadCategory}) Thread.belongsToMany(Category, {through: ThreadCategory})

View file

@ -7,7 +7,7 @@ global.NylasError = NylasError;
// List of the attributes of Message that the processor should be allowed to change. // List of the attributes of Message that the processor should be allowed to change.
// The message may move between folders, get starred, etc. while it's being // The message may move between folders, get starred, etc. while it's being
// processed, and it shouldn't overwrite changes to those fields. // processed, and it shouldn't overwrite changes to those fields.
const MessageAttributes = ['body', 'processed', 'to', 'from', 'cc', 'bcc', 'snippet', 'threadId'] const MessageAttributes = ['body', 'processed', 'to', 'from', 'cc', 'replyTo', 'bcc', 'snippet', 'threadId']
const MessageProcessorVersion = 1; const MessageProcessorVersion = 1;
function runPipeline({db, accountId, message}) { function runPipeline({db, accountId, message}) {

View file

@ -27,10 +27,11 @@ function processMessage({message}) {
console.log("Received message has no body or snippet.") console.log("Received message has no body or snippet.")
} }
// extract data from the raw headers object message.to = extractContacts(message.headers.to);
for (const field of ['to', 'from', 'cc', 'bcc']) { message.cc = extractContacts(message.headers.cc);
message[field] = extractContacts(message.headers[field]); message.bcc = extractContacts(message.headers.bcc);
} message.from = extractContacts(message.headers.from);
message.replyTo = extractContacts(message.headers['reply-to']);
return Promise.resolve(message); return Promise.resolve(message);
} }