From 9306b6e38caf44a8f2fc0f07d06dd7008a8f66c3 Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Sun, 3 Jan 2016 17:46:32 -0700 Subject: [PATCH] * Update last read ID even for private_mail * Allow options.config or extraArgs for various configuration --- core/fse.js | 81 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/core/fse.js b/core/fse.js index 1b5526fc..00254f6b 100644 --- a/core/fse.js +++ b/core/fse.js @@ -9,6 +9,7 @@ var MultiLineEditTextView = require('../core/multi_line_edit_text_view.js').Mul var Message = require('../core/message.js'); var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName; var updateMessageAreaLastReadId = require('../core/message_area.js').updateMessageAreaLastReadId; +var getUserIdAndName = require('../core/user.js').getUserIdAndName; var async = require('async'); var assert = require('assert'); @@ -67,7 +68,6 @@ var MCICodeIds = { To : 2, Subject : 3, AreaName : 4, - DateTime : 5, MsgNum : 6, MsgTotal : 7, @@ -103,20 +103,36 @@ function FullScreenEditorModule(options) { // editorType : email | area // editorMode : view | edit | quote // - // extraArgs - view mode + // menuConfig.config or extraArgs // messageAreaName // messageIndex / messageTotal + // toUserId // - // - this.editorType = config.editorType; - this.editorMode = config.editorMode; + this.editorType = config.editorType; + this.editorMode = config.editorMode; + this.messageAreaName = config.messageAreaName || Message.WellKnownAreaNames.Private; + this.messageIndex = config.messageIndex || 0; + this.messageTotal = config.messageTotal || 0; + this.toUserId = config.toUserId || 0; + // extraArgs can override some config if(_.isObject(options.extraArgs)) { - //console.log(options.extraArgs) - this.messageAreaName = options.extraArgs.messageAreaName || Message.WellKnownAreaNames.Private; - this.messageIndex = options.extraArgs.messageIndex || 0; - this.messageTotal = options.extraArgs.messageTotal || 0; + if(options.extraArgs.messageAreaName) { + this.messageAreaName = options.extraArgs.messageAreaName; + } + if(options.extraArgs.messageIndex) { + this.messageIndex = options.extraArgs.messageIndex; + } + if(options.extraArgs.messageTotal) { + this.messageTotal = options.extraArgs.messageTotal; + } + if(options.extraArgs.toUserId) { + this.toUserId = options.extraArgs.toUserId; + } } + + console.log(this.toUserId) + console.log(this.messageAreaName) this.isReady = false; @@ -214,21 +230,21 @@ function FullScreenEditorModule(options) { this.setMessage = function(message) { self.message = message; - if(!self.message.isPrivate()) { - updateMessageAreaLastReadId(self.client.user.userId, self.messageAreaName, self.message.messageId); - } + updateMessageAreaLastReadId( + self.client.user.userId, self.messageAreaName, self.message.messageId, + function lastReadUpdated() { - if(self.isReady) { - self.initHeaderViewMode(); - self.initFooterViewMode(); + if(self.isReady) { + self.initHeaderViewMode(); + self.initFooterViewMode(); - var bodyMessageView = self.viewControllers.body.getView(1); - if(bodyMessageView && _.has(self, 'message.message')) { - bodyMessageView.setText(self.message.message); - //bodyMessageView.redraw(); + var bodyMessageView = self.viewControllers.body.getView(1); + if(bodyMessageView && _.has(self, 'message.message')) { + bodyMessageView.setText(self.message.message); + //bodyMessageView.redraw(); + } } - } - + }); }; this.getMessage = function(cb) { @@ -242,12 +258,25 @@ function FullScreenEditorModule(options) { }, function populateLocalUserInfo(callback) { if(self.isLocalEmail()) { - msg.setLocalFromUserId(self.client.user.userId); - msg.setLocalToUserId(self.toUserId); + self.message.setLocalFromUserId(self.client.user.userId); + + if(self.toUserId > 0) { + self.message.setLocalToUserId(self.toUserId); + callback(null); + } else { + // we need to look it up + getUserIdAndName(self.message.toUserName, function userInfo(err, toUserId) { + if(err) { + callback(err); + } else { + self.message.setLocalToUserId(toUserId); + callback(null); + } + }); + } + } else { + callback(null); } - - // :TODO: DO THAT! - callback(null); } ], function complete(err) {