* Update last read ID even for private_mail

* Allow options.config or extraArgs for various configuration
This commit is contained in:
Bryan Ashby 2016-01-03 17:46:32 -07:00
parent bcd3d1aa75
commit 9306b6e38c
1 changed files with 55 additions and 26 deletions

View File

@ -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.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,9 +230,9 @@ 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();
@ -228,7 +244,7 @@ function FullScreenEditorModule(options) {
//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);
// :TODO: DO THAT!
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);
}
}
],
function complete(err) {