* 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 Message = require('../core/message.js');
var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName; var getMessageAreaByName = require('../core/message_area.js').getMessageAreaByName;
var updateMessageAreaLastReadId = require('../core/message_area.js').updateMessageAreaLastReadId; var updateMessageAreaLastReadId = require('../core/message_area.js').updateMessageAreaLastReadId;
var getUserIdAndName = require('../core/user.js').getUserIdAndName;
var async = require('async'); var async = require('async');
var assert = require('assert'); var assert = require('assert');
@ -67,7 +68,6 @@ var MCICodeIds = {
To : 2, To : 2,
Subject : 3, Subject : 3,
AreaName : 4, AreaName : 4,
DateTime : 5, DateTime : 5,
MsgNum : 6, MsgNum : 6,
MsgTotal : 7, MsgTotal : 7,
@ -103,21 +103,37 @@ function FullScreenEditorModule(options) {
// editorType : email | area // editorType : email | area
// editorMode : view | edit | quote // editorMode : view | edit | quote
// //
// extraArgs - view mode // menuConfig.config or extraArgs
// messageAreaName // messageAreaName
// messageIndex / messageTotal // messageIndex / messageTotal
// toUserId
// //
// this.editorType = config.editorType;
this.editorType = config.editorType; this.editorMode = config.editorMode;
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)) { if(_.isObject(options.extraArgs)) {
//console.log(options.extraArgs) if(options.extraArgs.messageAreaName) {
this.messageAreaName = options.extraArgs.messageAreaName || Message.WellKnownAreaNames.Private; this.messageAreaName = options.extraArgs.messageAreaName;
this.messageIndex = options.extraArgs.messageIndex || 0; }
this.messageTotal = options.extraArgs.messageTotal || 0; 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; this.isReady = false;
this.isEditMode = function() { this.isEditMode = function() {
@ -214,21 +230,21 @@ function FullScreenEditorModule(options) {
this.setMessage = function(message) { this.setMessage = function(message) {
self.message = message; self.message = message;
if(!self.message.isPrivate()) { updateMessageAreaLastReadId(
updateMessageAreaLastReadId(self.client.user.userId, self.messageAreaName, self.message.messageId); self.client.user.userId, self.messageAreaName, self.message.messageId,
} function lastReadUpdated() {
if(self.isReady) { if(self.isReady) {
self.initHeaderViewMode(); self.initHeaderViewMode();
self.initFooterViewMode(); self.initFooterViewMode();
var bodyMessageView = self.viewControllers.body.getView(1); var bodyMessageView = self.viewControllers.body.getView(1);
if(bodyMessageView && _.has(self, 'message.message')) { if(bodyMessageView && _.has(self, 'message.message')) {
bodyMessageView.setText(self.message.message); bodyMessageView.setText(self.message.message);
//bodyMessageView.redraw(); //bodyMessageView.redraw();
}
} }
} });
}; };
this.getMessage = function(cb) { this.getMessage = function(cb) {
@ -242,12 +258,25 @@ function FullScreenEditorModule(options) {
}, },
function populateLocalUserInfo(callback) { function populateLocalUserInfo(callback) {
if(self.isLocalEmail()) { if(self.isLocalEmail()) {
msg.setLocalFromUserId(self.client.user.userId); self.message.setLocalFromUserId(self.client.user.userId);
msg.setLocalToUserId(self.toUserId);
}
// :TODO: DO THAT! if(self.toUserId > 0) {
callback(null); 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) { function complete(err) {