2015-06-25 04:45:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2018-07-21 20:32:06 +00:00
|
|
|
const { MenuModule } = require('./menu_module.js');
|
|
|
|
const { ViewController } = require('./view_controller.js');
|
|
|
|
const ansi = require('./ansi_term.js');
|
|
|
|
const theme = require('./theme.js');
|
|
|
|
const Message = require('./message.js');
|
|
|
|
const {
|
|
|
|
updateMessageAreaLastReadId
|
|
|
|
} = require('./message_area.js');
|
|
|
|
const { getMessageAreaByTag } = require('./message_area.js');
|
|
|
|
const User = require('./user.js');
|
|
|
|
const StatLog = require('./stat_log.js');
|
|
|
|
const stringFormat = require('./string_format.js');
|
|
|
|
const {
|
|
|
|
MessageAreaConfTempSwitcher
|
|
|
|
} = require('./mod_mixins.js');
|
|
|
|
const {
|
|
|
|
isAnsi, cleanControlCodes,
|
|
|
|
insert
|
|
|
|
} = require('./string_util.js');
|
|
|
|
const Config = require('./config.js').get;
|
|
|
|
const { getAddressedToInfo } = require('./mail_util.js');
|
|
|
|
const Events = require('./events.js');
|
2018-11-24 00:41:16 +00:00
|
|
|
const UserProps = require('./user_property.js');
|
2018-11-28 04:21:00 +00:00
|
|
|
const SysProps = require('./system_property.js');
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// deps
|
2018-07-21 20:32:06 +00:00
|
|
|
const async = require('async');
|
|
|
|
const assert = require('assert');
|
|
|
|
const _ = require('lodash');
|
|
|
|
const moment = require('moment');
|
2015-06-25 05:09:26 +00:00
|
|
|
|
2015-06-25 04:45:21 +00:00
|
|
|
exports.moduleInfo = {
|
2018-06-23 03:26:46 +00:00
|
|
|
name : 'Full Screen Editor (FSE)',
|
|
|
|
desc : 'A full screen editor/viewer',
|
|
|
|
author : 'NuSkooler',
|
2015-06-25 04:45:21 +00:00
|
|
|
};
|
|
|
|
|
2018-01-27 04:45:08 +00:00
|
|
|
const MciViewIds = {
|
2018-06-22 05:15:04 +00:00
|
|
|
header : {
|
2018-06-23 03:26:46 +00:00
|
|
|
from : 1,
|
|
|
|
to : 2,
|
|
|
|
subject : 3,
|
|
|
|
errorMsg : 4,
|
|
|
|
modTimestamp : 5,
|
|
|
|
msgNum : 6,
|
|
|
|
msgTotal : 7,
|
|
|
|
|
|
|
|
customRangeStart : 10, // 10+ = customs
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
body : {
|
2018-06-23 03:26:46 +00:00
|
|
|
message : 1,
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: quote builder MCIs - remove all magic #'s
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: consolidate all footer MCI's - remove all magic #'s
|
2018-06-22 05:15:04 +00:00
|
|
|
ViewModeFooter : {
|
2018-06-23 03:26:46 +00:00
|
|
|
MsgNum : 6,
|
|
|
|
MsgTotal : 7,
|
|
|
|
// :TODO: Just use custom ranges
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
quoteBuilder : {
|
2018-06-23 03:26:46 +00:00
|
|
|
quotedMsg : 1,
|
|
|
|
// 2 NYI
|
|
|
|
quoteLines : 3,
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2015-09-04 06:02:28 +00:00
|
|
|
};
|
|
|
|
|
2018-01-27 04:45:08 +00:00
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
Custom formatting:
|
|
|
|
header
|
|
|
|
fromUserName
|
|
|
|
toUserName
|
|
|
|
|
|
|
|
fromRealName (may be fromUserName) NYI
|
|
|
|
toRealName (may be toUserName) NYI
|
|
|
|
|
|
|
|
fromRemoteUser (may be "N/A")
|
|
|
|
toRemoteUser (may be "N/A")
|
|
|
|
subject
|
|
|
|
modTimestamp
|
|
|
|
msgNum
|
|
|
|
msgTotal (in area)
|
|
|
|
messageId
|
2018-01-27 04:45:08 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: convert code in this class to newer styles, conventions, etc. There is a lot of experimental stuff here that has better (DRY) alternatives
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModule extends MessageAreaConfTempSwitcher(MenuModule) {
|
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
const self = this;
|
|
|
|
const config = this.menuConfig.config;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// menuConfig.config:
|
|
|
|
// editorType : email | area
|
|
|
|
// editorMode : view | edit | quote
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// menuConfig.config or extraArgs
|
|
|
|
// messageAreaTag
|
|
|
|
// messageIndex / messageTotal
|
|
|
|
// toUserId
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
this.editorType = config.editorType;
|
|
|
|
this.editorMode = config.editorMode;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
if(config.messageAreaTag) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: swtich to this.config.messageAreaTag so we can follow Object.assign pattern for config/extraArgs
|
|
|
|
this.messageAreaTag = config.messageAreaTag;
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
this.messageIndex = config.messageIndex || 0;
|
|
|
|
this.messageTotal = config.messageTotal || 0;
|
|
|
|
this.toUserId = config.toUserId || 0;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// extraArgs can override some config
|
2018-06-22 05:15:04 +00:00
|
|
|
if(_.isObject(options.extraArgs)) {
|
|
|
|
if(options.extraArgs.messageAreaTag) {
|
|
|
|
this.messageAreaTag = options.extraArgs.messageAreaTag;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.noUpdateLastReadId = _.get(options, 'extraArgs.noUpdateLastReadId', config.noUpdateLastReadId) || false;
|
|
|
|
|
|
|
|
this.isReady = false;
|
|
|
|
|
|
|
|
if(_.has(options, 'extraArgs.message')) {
|
|
|
|
this.setMessage(options.extraArgs.message);
|
|
|
|
} else if(_.has(options, 'extraArgs.replyToMessage')) {
|
|
|
|
this.replyToMessage = options.extraArgs.replyToMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Validation stuff
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
viewValidationListener : function(err, cb) {
|
|
|
|
var errMsgView = self.viewControllers.header.getView(MciViewIds.header.errorMsg);
|
|
|
|
var newFocusViewId;
|
|
|
|
if(errMsgView) {
|
|
|
|
if(err) {
|
|
|
|
errMsgView.setText(err.message);
|
|
|
|
|
|
|
|
if(MciViewIds.header.subject === err.view.getId()) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: for "area" mode, should probably just bail if this is emtpy (e.g. cancel)
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
errMsgView.clearText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cb(newFocusViewId);
|
|
|
|
},
|
|
|
|
headerSubmit : function(formData, extraArgs, cb) {
|
|
|
|
self.switchToBody();
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
editModeEscPressed : function(formData, extraArgs, cb) {
|
|
|
|
self.footerMode = 'editor' === self.footerMode ? 'editorMenu' : 'editor';
|
|
|
|
|
|
|
|
self.switchFooter(function next(err) {
|
|
|
|
if(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(self.footerMode) {
|
|
|
|
case 'editor' :
|
|
|
|
if(!_.isUndefined(self.viewControllers.footerEditorMenu)) {
|
|
|
|
self.viewControllers.footerEditorMenu.detachClientEvents();
|
|
|
|
}
|
|
|
|
self.viewControllers.body.switchFocus(1);
|
|
|
|
self.observeEditorEvents();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'editorMenu' :
|
|
|
|
self.viewControllers.body.setFocus(false);
|
|
|
|
self.viewControllers.footerEditorMenu.switchFocus(1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default : throw new Error('Unexpected mode');
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
editModeMenuQuote : function(formData, extraArgs, cb) {
|
|
|
|
self.viewControllers.footerEditorMenu.setFocus(false);
|
|
|
|
self.displayQuoteBuilder();
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
appendQuoteEntry: function(formData, extraArgs, cb) {
|
|
|
|
const quoteMsgView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
|
|
|
|
|
|
|
|
if(self.newQuoteBlock) {
|
|
|
|
self.newQuoteBlock = false;
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: If replying to ANSI, add a blank sepration line here
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
quoteMsgView.addText(self.getQuoteByHeader());
|
|
|
|
}
|
|
|
|
|
|
|
|
const quoteListView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quoteLines);
|
2018-06-23 03:26:46 +00:00
|
|
|
const quoteText = quoteListView.getItem(formData.value.quote);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
quoteMsgView.addText(quoteText);
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// If this is *not* the last item, advance. Otherwise, do nothing as we
|
|
|
|
// don't want to jump back to the top and repeat already quoted lines
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
if(quoteListView.getData() !== quoteListView.getCount() - 1) {
|
|
|
|
quoteListView.focusNext();
|
|
|
|
} else {
|
|
|
|
self.quoteBuilderFinalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
quoteBuilderEscPressed : function(formData, extraArgs, cb) {
|
|
|
|
self.quoteBuilderFinalize();
|
|
|
|
return cb(null);
|
|
|
|
},
|
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
replyDiscard : function(formData, extraArgs) {
|
|
|
|
// :TODO: need to prompt yes/no
|
|
|
|
// :TODO: @method for fallback would be better
|
|
|
|
self.prevMenu();
|
|
|
|
},
|
|
|
|
*/
|
2018-06-22 05:15:04 +00:00
|
|
|
editModeMenuHelp : function(formData, extraArgs, cb) {
|
|
|
|
self.viewControllers.footerEditorMenu.setFocus(false);
|
|
|
|
return self.displayHelp(cb);
|
|
|
|
},
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
2018-06-23 03:26:46 +00:00
|
|
|
// View Mode
|
2018-06-22 05:15:04 +00:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
viewModeMenuHelp : function(formData, extraArgs, cb) {
|
|
|
|
self.viewControllers.footerView.setFocus(false);
|
|
|
|
return self.displayHelp(cb);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
isEditMode() {
|
|
|
|
return 'edit' === this.editorMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
isViewMode() {
|
|
|
|
return 'view' === this.editorMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
isPrivateMail() {
|
|
|
|
return Message.WellKnownAreaTags.Private === this.messageAreaTag;
|
|
|
|
}
|
|
|
|
|
|
|
|
isReply() {
|
|
|
|
return !_.isUndefined(this.replyToMessage);
|
|
|
|
}
|
|
|
|
|
|
|
|
getFooterName() {
|
2018-06-23 03:26:46 +00:00
|
|
|
return 'footer' + _.upperFirst(this.footerMode); // e.g. 'footerEditor', 'footerEditorMenu', ...
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getFormId(name) {
|
|
|
|
return {
|
2018-06-23 03:26:46 +00:00
|
|
|
header : 0,
|
|
|
|
body : 1,
|
|
|
|
footerEditor : 2,
|
|
|
|
footerEditorMenu : 3,
|
|
|
|
footerView : 4,
|
|
|
|
quoteBuilder : 5,
|
|
|
|
|
|
|
|
help : 50,
|
2018-06-22 05:15:04 +00:00
|
|
|
}[name];
|
|
|
|
}
|
|
|
|
|
|
|
|
getHeaderFormatObj() {
|
2018-06-23 03:26:46 +00:00
|
|
|
const remoteUserNotAvail = this.menuConfig.config.remoteUserNotAvail || 'N/A';
|
|
|
|
const localUserIdNotAvail = this.menuConfig.config.localUserIdNotAvail || 'N/A';
|
|
|
|
const modTimestampFormat = this.menuConfig.config.modTimestampFormat || this.client.currentTheme.helpers.getDateTimeFormat();
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
return {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: ensure we show real names for form/to if they are enforced in the area
|
|
|
|
fromUserName : this.message.fromUserName,
|
|
|
|
toUserName : this.message.toUserName,
|
|
|
|
// :TODO:
|
2018-06-22 05:15:04 +00:00
|
|
|
//fromRealName
|
|
|
|
//toRealName
|
2018-06-23 03:26:46 +00:00
|
|
|
fromUserId : _.get(this.message, 'meta.System.local_from_user_id', localUserIdNotAvail),
|
|
|
|
toUserId : _.get(this.message, 'meta.System.local_to_user_id', localUserIdNotAvail),
|
|
|
|
fromRemoteUser : _.get(this.message, 'meta.System.remote_from_user', remoteUserNotAvail),
|
|
|
|
toRemoteUser : _.get(this.messgae, 'meta.System.remote_to_user', remoteUserNotAvail),
|
|
|
|
subject : this.message.subject,
|
|
|
|
modTimestamp : this.message.modTimestamp.format(modTimestampFormat),
|
|
|
|
msgNum : this.messageIndex + 1,
|
|
|
|
msgTotal : this.messageTotal,
|
|
|
|
messageId : this.message.messageId,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
setInitialFooterMode() {
|
|
|
|
switch(this.editorMode) {
|
|
|
|
case 'edit' : this.footerMode = 'editor'; break;
|
|
|
|
case 'view' : this.footerMode = 'view'; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buildMessage(cb) {
|
|
|
|
const headerValues = this.viewControllers.header.getFormData().value;
|
|
|
|
|
|
|
|
const msgOpts = {
|
2018-06-23 03:26:46 +00:00
|
|
|
areaTag : this.messageAreaTag,
|
|
|
|
toUserName : headerValues.to,
|
|
|
|
fromUserName : this.client.user.username,
|
|
|
|
subject : headerValues.subject,
|
|
|
|
// :TODO: don't hard code 1 here:
|
|
|
|
message : this.viewControllers.body.getView(MciViewIds.body.message).getData( { forceLineTerms : this.replyIsAnsi } ),
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if(this.isReply()) {
|
2018-06-23 03:26:46 +00:00
|
|
|
msgOpts.replyToMsgId = this.replyToMessage.messageId;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
if(this.replyIsAnsi) {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Ensure first characters indicate ANSI for detection down
|
|
|
|
// the line (other boards/etc.). We also set explicit_encoding
|
|
|
|
// to packetAnsiMsgEncoding (generally cp437) as various boards
|
|
|
|
// really don't like ANSI messages in UTF-8 encoding (they should!)
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
msgOpts.meta = { System : { 'explicit_encoding' : _.get(Config(), 'scannerTossers.ftn_bso.packetAnsiMsgEncoding', 'cp437') } };
|
|
|
|
msgOpts.message = `${ansi.reset()}${ansi.eraseData(2)}${ansi.goto(1,1)}\r\n${ansi.up()}${msgOpts.message}`;
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.message = new Message(msgOpts);
|
|
|
|
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateLastReadId(cb) {
|
|
|
|
if(this.noUpdateLastReadId) {
|
|
|
|
return cb(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
return updateMessageAreaLastReadId(
|
|
|
|
this.client.user.userId, this.messageAreaTag, this.message.messageId, cb
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
setMessage(message) {
|
|
|
|
this.message = message;
|
|
|
|
|
|
|
|
this.updateLastReadId( () => {
|
|
|
|
if(this.isReady) {
|
|
|
|
this.initHeaderViewMode();
|
|
|
|
this.initFooterViewMode();
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
const bodyMessageView = this.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
let msg = this.message.message;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
if(bodyMessageView && _.has(this, 'message.message')) {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// We handle ANSI messages differently than standard messages -- this is required as
|
|
|
|
// we don't want to do things like word wrap ANSI, but instead, trust that it's formatted
|
|
|
|
// how the author wanted it
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
if(isAnsi(msg)) {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Find tearline - we want to color it differently.
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
const tearLinePos = this.message.getTearLinePosition(msg);
|
|
|
|
|
|
|
|
if(tearLinePos > -1) {
|
|
|
|
msg = insert(msg, tearLinePos, bodyMessageView.getSGRFor('text'));
|
|
|
|
}
|
|
|
|
|
|
|
|
bodyMessageView.setAnsi(
|
2018-06-23 03:26:46 +00:00
|
|
|
msg.replace(/\r?\n/g, '\r\n'), // messages are stored with CRLF -> LF
|
2018-06-22 05:15:04 +00:00
|
|
|
{
|
2018-06-23 03:26:46 +00:00
|
|
|
prepped : false,
|
|
|
|
forceLineTerm : true,
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
bodyMessageView.setText(cleanControlCodes(msg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getMessage(cb) {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function buildIfNecessary(callback) {
|
|
|
|
if(self.isEditMode()) {
|
2018-06-23 03:26:46 +00:00
|
|
|
return self.buildMessage(callback); // creates initial self.message
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
},
|
|
|
|
function populateLocalUserInfo(callback) {
|
|
|
|
self.message.setLocalFromUserId(self.client.user.userId);
|
|
|
|
|
|
|
|
if(!self.isPrivateMail()) {
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(self.toUserId > 0) {
|
|
|
|
self.message.setLocalToUserId(self.toUserId);
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// If the message we're replying to is from a remote user
|
|
|
|
// don't try to look up the local user ID. Instead, mark the mail
|
|
|
|
// for export with the remote to address.
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
if(self.replyToMessage && self.replyToMessage.isFromRemoteUser()) {
|
|
|
|
self.message.setRemoteToUser(self.replyToMessage.meta.System[Message.SystemMetaNames.RemoteFromUser]);
|
|
|
|
self.message.setExternalFlavor(self.replyToMessage.meta.System[Message.SystemMetaNames.ExternalFlavor]);
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Detect if the user is attempting to send to a remote mail type that we support
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: how to plug in support without tying to various types here? isSupportedExteranlType() or such
|
2018-06-22 05:15:04 +00:00
|
|
|
const addressedToInfo = getAddressedToInfo(self.message.toUserName);
|
|
|
|
if(addressedToInfo.name && Message.AddressFlavor.FTN === addressedToInfo.flavor) {
|
|
|
|
self.message.setRemoteToUser(addressedToInfo.remote);
|
|
|
|
self.message.setExternalFlavor(addressedToInfo.flavor);
|
|
|
|
self.message.toUserName = addressedToInfo.name;
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// we need to look it up
|
2018-06-22 05:15:04 +00:00
|
|
|
User.getUserIdAndNameByLookup(self.message.toUserName, (err, toUserId) => {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.message.setLocalToUserId(toUserId);
|
|
|
|
return callback(null);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
],
|
|
|
|
err => {
|
|
|
|
return cb(err, self.message);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-28 04:21:00 +00:00
|
|
|
updateUserAndSystemStats(cb) {
|
2018-06-22 05:15:04 +00:00
|
|
|
if(Message.isPrivateAreaTag(this.message.areaTag)) {
|
2018-07-21 20:32:06 +00:00
|
|
|
Events.emit(Events.getSystemEvents().UserSendMail, { user : this.client.user });
|
2018-06-22 05:15:04 +00:00
|
|
|
if(cb) {
|
|
|
|
cb(null);
|
|
|
|
}
|
2018-06-23 03:26:46 +00:00
|
|
|
return; // don't inc stats for private messages
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-21 20:32:06 +00:00
|
|
|
Events.emit(Events.getSystemEvents().UserPostMessage, { user : this.client.user, areaTag : this.message.areaTag });
|
2018-11-28 04:21:00 +00:00
|
|
|
|
|
|
|
StatLog.incrementNonPersistentSystemStat(SysProps.MessageTotalCount, 1);
|
|
|
|
StatLog.incrementNonPersistentSystemStat(SysProps.MessagesToday, 1);
|
2018-11-24 05:02:36 +00:00
|
|
|
return StatLog.incrementUserStat(this.client.user, UserProps.MessagePostCount, 1, cb);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
redrawFooter(options, cb) {
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function moveToFooterPosition(callback) {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Calculate footer starting position
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// row = (header height + body height)
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
var footerRow = self.header.height + self.body.height;
|
|
|
|
self.client.term.rawWrite(ansi.goto(footerRow, 1));
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function clearFooterArea(callback) {
|
|
|
|
if(options.clear) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// footer up to 3 rows in height
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: We'd like to delete up to N rows, but this does not work
|
|
|
|
// in NetRunner:
|
2018-06-22 05:15:04 +00:00
|
|
|
self.client.term.rawWrite(ansi.reset() + ansi.deleteLine(3));
|
|
|
|
|
|
|
|
self.client.term.rawWrite(ansi.reset() + ansi.eraseLine(2));
|
|
|
|
}
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function displayFooterArt(callback) {
|
|
|
|
const footerArt = self.menuConfig.config.art[options.footerName];
|
|
|
|
|
|
|
|
theme.displayThemedAsset(
|
|
|
|
footerArt,
|
|
|
|
self.client,
|
|
|
|
{ font : self.menuConfig.font },
|
|
|
|
function displayed(err, artData) {
|
|
|
|
callback(err, artData);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err, artData) {
|
|
|
|
cb(err, artData);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
redrawScreen(cb) {
|
2018-06-23 03:26:46 +00:00
|
|
|
var comps = [ 'header', 'body' ];
|
|
|
|
const self = this;
|
|
|
|
var art = self.menuConfig.config.art;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
self.client.term.rawWrite(ansi.resetScreen());
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function displayHeaderAndBody(callback) {
|
|
|
|
async.eachSeries( comps, function dispArt(n, next) {
|
|
|
|
theme.displayThemedAsset(
|
|
|
|
art[n],
|
|
|
|
self.client,
|
2018-11-18 01:56:09 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2018-06-22 05:15:04 +00:00
|
|
|
function displayed(err) {
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}, function complete(err) {
|
|
|
|
//self.body.height = self.client.term.termHeight - self.header.height - 1;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function displayFooter(callback) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// we have to treat the footer special
|
2018-06-22 05:15:04 +00:00
|
|
|
self.redrawFooter( { clear : false, footerName : self.getFooterName() }, function footerDisplayed(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function refreshViews(callback) {
|
|
|
|
comps.push(self.getFooterName());
|
|
|
|
|
|
|
|
comps.forEach(function artComp(n) {
|
|
|
|
self.viewControllers[n].redrawAll();
|
|
|
|
});
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
switchFooter(cb) {
|
|
|
|
var footerName = this.getFooterName();
|
|
|
|
|
|
|
|
this.redrawFooter( { footerName : footerName, clear : true }, (err, artData) => {
|
|
|
|
if(err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var formId = this.getFormId(footerName);
|
|
|
|
|
|
|
|
if(_.isUndefined(this.viewControllers[footerName])) {
|
|
|
|
var menuLoadOpts = {
|
2018-06-23 03:26:46 +00:00
|
|
|
callingMenu : this,
|
|
|
|
formId : formId,
|
|
|
|
mciMap : artData.mciMap
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.addViewController(
|
|
|
|
footerName,
|
|
|
|
new ViewController( { client : this.client, formId : formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, err => {
|
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.viewControllers[footerName].redrawAll();
|
|
|
|
cb(null);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
initSequence() {
|
|
|
|
var mciData = { };
|
2018-06-23 03:26:46 +00:00
|
|
|
const self = this;
|
|
|
|
var art = self.menuConfig.config.art;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
assert(_.isObject(art));
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function beforeDisplayArt(callback) {
|
|
|
|
self.beforeArt(callback);
|
|
|
|
},
|
|
|
|
function displayHeaderAndBodyArt(callback) {
|
|
|
|
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
|
|
|
theme.displayThemedAsset(
|
|
|
|
art[n],
|
|
|
|
self.client,
|
2018-11-18 01:56:09 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2018-06-22 05:15:04 +00:00
|
|
|
function displayed(err, artData) {
|
|
|
|
if(artData) {
|
|
|
|
mciData[n] = artData;
|
|
|
|
self[n] = { height : artData.height };
|
|
|
|
}
|
|
|
|
|
|
|
|
next(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function displayFooter(callback) {
|
|
|
|
self.setInitialFooterMode();
|
|
|
|
|
|
|
|
var footerName = self.getFooterName();
|
|
|
|
|
|
|
|
self.redrawFooter( { footerName : footerName }, function artDisplayed(err, artData) {
|
|
|
|
mciData[footerName] = artData;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function afterArtDisplayed(callback) {
|
|
|
|
self.mciReady(mciData, callback);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.warn( { error : err.message }, 'FSE init error');
|
|
|
|
} else {
|
|
|
|
self.isReady = true;
|
|
|
|
self.finishedLoading();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
createInitialViews(mciData, cb) {
|
|
|
|
const self = this;
|
|
|
|
var menuLoadOpts = { callingMenu : self };
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function header(callback) {
|
|
|
|
menuLoadOpts.formId = self.getFormId('header');
|
2018-06-23 03:26:46 +00:00
|
|
|
menuLoadOpts.mciMap = mciData.header.mciMap;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'header',
|
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function body(callback) {
|
2018-06-23 03:26:46 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId('body');
|
|
|
|
menuLoadOpts.mciMap = mciData.body.mciMap;
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'body',
|
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function footer(callback) {
|
|
|
|
var footerName = self.getFooterName();
|
|
|
|
|
|
|
|
menuLoadOpts.formId = self.getFormId(footerName);
|
|
|
|
menuLoadOpts.mciMap = mciData[footerName].mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
footerName,
|
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function prepareViewStates(callback) {
|
|
|
|
var header = self.viewControllers.header;
|
|
|
|
var from = header.getView(MciViewIds.header.from);
|
|
|
|
from.acceptsFocus = false;
|
|
|
|
//from.setText(self.client.user.username);
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: make this a method
|
2018-06-22 05:15:04 +00:00
|
|
|
var body = self.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
self.updateTextEditMode(body.getTextEditMode());
|
|
|
|
self.updateEditModePosition(body.getEditPosition());
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: If view mode, set body to read only... which needs an impl...
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function setInitialData(callback) {
|
|
|
|
|
|
|
|
switch(self.editorMode) {
|
|
|
|
case 'view' :
|
|
|
|
if(self.message) {
|
|
|
|
self.initHeaderViewMode();
|
|
|
|
self.initFooterViewMode();
|
|
|
|
|
|
|
|
var bodyMessageView = self.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
if(bodyMessageView && _.has(self, 'message.message')) {
|
|
|
|
//self.setBodyMessageViewText();
|
|
|
|
bodyMessageView.setText(cleanControlCodes(self.message.message));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit' :
|
|
|
|
{
|
|
|
|
const fromView = self.viewControllers.header.getView(MciViewIds.header.from);
|
|
|
|
const area = getMessageAreaByTag(self.messageAreaTag);
|
|
|
|
if(area && area.realNames) {
|
2018-11-24 00:41:16 +00:00
|
|
|
fromView.setText(self.client.user.properties[UserProps.RealName] || self.client.user.username);
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
|
|
|
fromView.setText(self.client.user.username);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(self.replyToMessage) {
|
|
|
|
self.initHeaderReplyEditMode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function setInitialFocus(callback) {
|
|
|
|
|
|
|
|
switch(self.editorMode) {
|
|
|
|
case 'edit' :
|
|
|
|
self.switchToHeader();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'view' :
|
|
|
|
self.switchToFooter();
|
|
|
|
//self.observeViewPosition();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReadyHandler(mciData, cb) {
|
|
|
|
|
|
|
|
this.createInitialViews(mciData, err => {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: Can probably be replaced with @systemMethod:validateUserNameExists when the framework is in
|
|
|
|
// place - if this is for existing usernames else validate spec
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
self.viewControllers.header.on('leave', function headerViewLeave(view) {
|
|
|
|
|
|
|
|
if(2 === view.id) { // "to" field
|
|
|
|
self.validateToUserName(view.getData(), function result(err) {
|
|
|
|
if(err) {
|
|
|
|
// :TODO: display a error in a %TL area or such
|
|
|
|
view.clearText();
|
|
|
|
self.viewControllers.headers.switchFocus(2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});*/
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
updateEditModePosition(pos) {
|
|
|
|
if(this.isEditMode()) {
|
|
|
|
var posView = this.viewControllers.footerEditor.getView(1);
|
|
|
|
if(posView) {
|
|
|
|
this.client.term.rawWrite(ansi.savePos());
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: Use new formatting techniques here, e.g. state.cursorPositionRow, cursorPositionCol and cursorPositionFormat
|
2018-06-22 05:15:04 +00:00
|
|
|
posView.setText(_.padStart(String(pos.row + 1), 2, '0') + ',' + _.padEnd(String(pos.col + 1), 2, '0'));
|
|
|
|
this.client.term.rawWrite(ansi.restorePos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updateTextEditMode(mode) {
|
|
|
|
if(this.isEditMode()) {
|
|
|
|
var modeView = this.viewControllers.footerEditor.getView(2);
|
|
|
|
if(modeView) {
|
|
|
|
this.client.term.rawWrite(ansi.savePos());
|
|
|
|
modeView.setText('insert' === mode ? 'INS' : 'OVR');
|
|
|
|
this.client.term.rawWrite(ansi.restorePos());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
setHeaderText(id, text) {
|
|
|
|
this.setViewText('header', id, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
initHeaderViewMode() {
|
2018-06-23 03:26:46 +00:00
|
|
|
this.setHeaderText(MciViewIds.header.from, this.message.fromUserName);
|
|
|
|
this.setHeaderText(MciViewIds.header.to, this.message.toUserName);
|
|
|
|
this.setHeaderText(MciViewIds.header.subject, this.message.subject);
|
|
|
|
this.setHeaderText(MciViewIds.header.modTimestamp, moment(this.message.modTimestamp).format(this.client.currentTheme.helpers.getDateTimeFormat()));
|
|
|
|
this.setHeaderText(MciViewIds.header.msgNum, (this.messageIndex + 1).toString());
|
|
|
|
this.setHeaderText(MciViewIds.header.msgTotal, this.messageTotal.toString());
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
this.updateCustomViewTextsWithFilter('header', MciViewIds.header.customRangeStart, this.getHeaderFormatObj());
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// if we changed conf/area we need to update any related standard MCI view
|
2018-06-22 05:15:04 +00:00
|
|
|
this.refreshPredefinedMciViewsByCode('header', [ 'MA', 'MC', 'ML', 'CM' ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
initHeaderReplyEditMode() {
|
|
|
|
assert(_.isObject(this.replyToMessage));
|
|
|
|
|
|
|
|
this.setHeaderText(MciViewIds.header.to, this.replyToMessage.fromUserName);
|
|
|
|
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// We want to prefix the subject with "RE: " only if it's not already
|
|
|
|
// that way -- avoid RE: RE: RE: RE: ...
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
let newSubj = this.replyToMessage.subject;
|
|
|
|
if(false === /^RE:\s+/i.test(newSubj)) {
|
|
|
|
newSubj = `RE: ${newSubj}`;
|
|
|
|
}
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
this.setHeaderText(MciViewIds.header.subject, newSubj);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initFooterViewMode() {
|
|
|
|
this.setViewText('footerView', MciViewIds.ViewModeFooter.msgNum, (this.messageIndex + 1).toString() );
|
|
|
|
this.setViewText('footerView', MciViewIds.ViewModeFooter.msgTotal, this.messageTotal.toString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
displayHelp(cb) {
|
|
|
|
this.client.term.rawWrite(ansi.resetScreen());
|
|
|
|
|
|
|
|
theme.displayThemeArt(
|
|
|
|
{ name : this.menuConfig.config.art.help, client : this.client },
|
|
|
|
() => {
|
|
|
|
this.client.waitForKeyPress( () => {
|
|
|
|
this.redrawScreen( () => {
|
|
|
|
this.viewControllers[this.getFooterName()].setFocus(true);
|
|
|
|
return cb(null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
displayQuoteBuilder() {
|
|
|
|
//
|
2018-06-23 03:26:46 +00:00
|
|
|
// Clear body area
|
2018-06-22 05:15:04 +00:00
|
|
|
//
|
|
|
|
this.newQuoteBlock = true;
|
|
|
|
const self = this;
|
|
|
|
|
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function clearAndDisplayArt(callback) {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: NetRunner does NOT support delete line, so this does not work:
|
2018-06-22 05:15:04 +00:00
|
|
|
self.client.term.rawWrite(
|
|
|
|
ansi.goto(self.header.height + 1, 1) +
|
2018-06-23 03:26:46 +00:00
|
|
|
ansi.deleteLine((self.client.term.termHeight - self.header.height) - 1));
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
theme.displayThemeArt( { name : self.menuConfig.config.art.quote, client : self.client }, function displayed(err, artData) {
|
|
|
|
callback(err, artData);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function createViewsIfNecessary(artData, callback) {
|
|
|
|
var formId = self.getFormId('quoteBuilder');
|
|
|
|
|
|
|
|
if(_.isUndefined(self.viewControllers.quoteBuilder)) {
|
|
|
|
var menuLoadOpts = {
|
2018-06-23 03:26:46 +00:00
|
|
|
callingMenu : self,
|
|
|
|
formId : formId,
|
|
|
|
mciMap : artData.mciMap,
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'quoteBuilder',
|
|
|
|
new ViewController( { client : self.client, formId : formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, function quoteViewsReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.viewControllers.quoteBuilder.redrawAll();
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function loadQuoteLines(callback) {
|
|
|
|
const quoteView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quoteLines);
|
2018-06-23 03:26:46 +00:00
|
|
|
const bodyView = self.viewControllers.body.getView(MciViewIds.body.message);
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
self.replyToMessage.getQuoteLines(
|
|
|
|
{
|
2018-06-23 03:26:46 +00:00
|
|
|
termWidth : self.client.term.termWidth,
|
|
|
|
termHeight : self.client.term.termHeight,
|
|
|
|
cols : quoteView.dimens.width,
|
|
|
|
startCol : quoteView.position.col,
|
|
|
|
ansiResetSgr : bodyView.styleSGR1,
|
|
|
|
ansiFocusPrefixSgr : quoteView.styleSGR2,
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
|
|
|
(err, quoteLines, focusQuoteLines, replyIsAnsi) => {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.replyIsAnsi = replyIsAnsi;
|
|
|
|
|
|
|
|
quoteView.setItems(quoteLines);
|
|
|
|
quoteView.setFocusItems(focusQuoteLines);
|
|
|
|
|
|
|
|
self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg).setFocus(false);
|
|
|
|
self.viewControllers.quoteBuilder.switchFocus(MciViewIds.quoteBuilder.quoteLines);
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
self.client.log.warn( { error : err.message }, 'Error displaying quote builder');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
observeEditorEvents() {
|
|
|
|
const bodyView = this.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
|
|
|
|
bodyView.on('edit position', pos => {
|
|
|
|
this.updateEditModePosition(pos);
|
|
|
|
});
|
|
|
|
|
|
|
|
bodyView.on('text edit mode', mode => {
|
|
|
|
this.updateTextEditMode(mode);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-06-23 03:26:46 +00:00
|
|
|
this.observeViewPosition = function() {
|
|
|
|
self.viewControllers.body.getView(MciViewIds.body.message).on('edit position', function positionUpdate(pos) {
|
|
|
|
console.log(pos.percent + ' / ' + pos.below)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*/
|
2015-09-20 04:55:09 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
switchToHeader() {
|
|
|
|
this.viewControllers.body.setFocus(false);
|
2018-06-23 03:26:46 +00:00
|
|
|
this.viewControllers.header.switchFocus(2); // to
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
switchToBody() {
|
|
|
|
this.viewControllers.header.setFocus(false);
|
|
|
|
this.viewControllers.body.switchFocus(1);
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.observeEditorEvents();
|
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
switchToFooter() {
|
|
|
|
this.viewControllers.header.setFocus(false);
|
|
|
|
this.viewControllers.body.setFocus(false);
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
this.viewControllers[this.getFooterName()].switchFocus(1); // HM1
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
switchFromQuoteBuilderToBody() {
|
|
|
|
this.viewControllers.quoteBuilder.setFocus(false);
|
|
|
|
var body = this.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
body.redraw();
|
|
|
|
this.viewControllers.body.switchFocus(1);
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: create method (DRY)
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.updateTextEditMode(body.getTextEditMode());
|
|
|
|
this.updateEditModePosition(body.getEditPosition());
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.observeEditorEvents();
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
quoteBuilderFinalize() {
|
2018-06-23 03:26:46 +00:00
|
|
|
// :TODO: fix magic #'s
|
|
|
|
const quoteMsgView = this.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
|
|
|
|
const msgView = this.viewControllers.body.getView(MciViewIds.body.message);
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
let quoteLines = quoteMsgView.getData().trim();
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(quoteLines.length > 0) {
|
|
|
|
if(this.replyIsAnsi) {
|
|
|
|
const bodyMessageView = this.viewControllers.body.getView(MciViewIds.body.message);
|
|
|
|
quoteLines += `${ansi.normal()}${bodyMessageView.getSGRFor('text')}`;
|
|
|
|
}
|
|
|
|
msgView.addText(`${quoteLines}\n\n`);
|
|
|
|
}
|
2018-01-15 19:22:11 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
quoteMsgView.setText('');
|
2016-01-05 06:32:01 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.footerMode = 'editor';
|
2016-01-05 06:32:01 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
this.switchFooter( () => {
|
|
|
|
this.switchFromQuoteBuilderToBody();
|
|
|
|
});
|
|
|
|
}
|
2015-06-25 05:12:03 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
getQuoteByHeader() {
|
|
|
|
let quoteFormat = this.menuConfig.config.quoteFormats;
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
if(Array.isArray(quoteFormat)) {
|
|
|
|
quoteFormat = quoteFormat[ Math.floor(Math.random() * quoteFormat.length) ];
|
|
|
|
} else if(!_.isString(quoteFormat)) {
|
|
|
|
quoteFormat = 'On {dateTime} {userName} said...';
|
|
|
|
}
|
2016-09-05 03:36:26 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
const dtFormat = this.menuConfig.config.quoteDateTimeFormat || this.client.currentTheme.helpers.getDateTimeFormat();
|
|
|
|
return stringFormat(quoteFormat, {
|
2018-06-23 03:26:46 +00:00
|
|
|
dateTime : moment(this.replyToMessage.modTimestamp).format(dtFormat),
|
|
|
|
userName : this.replyToMessage.fromUserName,
|
2018-06-22 05:15:04 +00:00
|
|
|
});
|
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
enter() {
|
|
|
|
if(this.messageAreaTag) {
|
|
|
|
this.tempMessageConfAndAreaSwitch(this.messageAreaTag);
|
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
super.enter();
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
leave() {
|
|
|
|
this.tempMessageConfAndAreaRestore();
|
|
|
|
super.leave();
|
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2018-06-22 05:15:04 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
return this.mciReadyHandler(mciData, cb);
|
|
|
|
}
|
2015-06-26 04:34:33 +00:00
|
|
|
};
|