2015-06-25 04:45:21 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-28 03:44:27 +00:00
|
|
|
// ENiGMA½
|
2016-09-05 03:36:26 +00:00
|
|
|
const MenuModule = require('./menu_module.js').MenuModule;
|
|
|
|
const ViewController = require('./view_controller.js').ViewController;
|
|
|
|
const ansi = require('./ansi_term.js');
|
|
|
|
const theme = require('./theme.js');
|
|
|
|
const Message = require('./message.js');
|
|
|
|
const updateMessageAreaLastReadId = require('./message_area.js').updateMessageAreaLastReadId;
|
2016-10-02 19:47:19 +00:00
|
|
|
const getMessageAreaByTag = require('./message_area.js').getMessageAreaByTag;
|
2017-02-18 20:21:18 +00:00
|
|
|
const User = require('./user.js');
|
2016-07-28 03:44:27 +00:00
|
|
|
const StatLog = require('./stat_log.js');
|
2016-09-05 03:36:26 +00:00
|
|
|
const stringFormat = require('./string_format.js');
|
2017-01-26 05:18:05 +00:00
|
|
|
const MessageAreaConfTempSwitcher = require('./mod_mixins.js').MessageAreaConfTempSwitcher;
|
2017-08-25 04:23:14 +00:00
|
|
|
const { isAnsi, cleanControlCodes, insert } = require('./string_util.js');
|
2017-08-21 02:42:25 +00:00
|
|
|
const Config = require('./config.js').config;
|
2018-01-13 16:06:50 +00:00
|
|
|
const { getAddressedToInfo } = require('./mail_util.js');
|
2016-07-28 03:44:27 +00:00
|
|
|
|
|
|
|
// deps
|
2016-05-24 02:45:18 +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 = {
|
2015-06-25 22:33:17 +00:00
|
|
|
name : 'Full Screen Editor (FSE)',
|
|
|
|
desc : 'A full screen editor/viewer',
|
2015-06-25 04:45:21 +00:00
|
|
|
author : 'NuSkooler',
|
|
|
|
};
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
/*
|
|
|
|
MCI Codes - General
|
|
|
|
MA - Message Area Desc
|
|
|
|
|
|
|
|
MCI Codes - View Mode
|
|
|
|
Header
|
|
|
|
TL1 - From
|
|
|
|
TL2 - To
|
|
|
|
TL3 - Subject
|
2015-10-05 04:04:56 +00:00
|
|
|
TL4 - Area name
|
2015-09-02 04:20:29 +00:00
|
|
|
|
|
|
|
TL5 - Date/Time (TODO: format)
|
2015-09-04 22:17:41 +00:00
|
|
|
TL6 - Message number
|
|
|
|
TL7 - Mesage total (in area)
|
|
|
|
TL8 - View Count
|
|
|
|
TL9 - Hash tags
|
|
|
|
TL10 - Message ID
|
|
|
|
TL11 - Reply to message ID
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
TL12 - User1
|
|
|
|
TL13 - User2
|
2015-12-12 22:52:56 +00:00
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
|
2015-09-06 21:58:58 +00:00
|
|
|
Footer - Viewing
|
|
|
|
HM1 - Menu (prev/next/etc.)
|
|
|
|
|
|
|
|
TL6 - Message number
|
|
|
|
TL7 - Message total (in area)
|
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
TL12 - User1 (fmt message object)
|
|
|
|
TL13 - User2
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
|
|
|
|
*/
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciCodeIds = {
|
2015-09-06 21:58:58 +00:00
|
|
|
ViewModeHeader : {
|
2015-09-04 22:17:41 +00:00
|
|
|
From : 1,
|
|
|
|
To : 2,
|
|
|
|
Subject : 3,
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2015-09-04 22:17:41 +00:00
|
|
|
DateTime : 5,
|
|
|
|
MsgNum : 6,
|
|
|
|
MsgTotal : 7,
|
|
|
|
ViewCount : 8,
|
|
|
|
HashTags : 9,
|
|
|
|
MessageID : 10,
|
2015-12-12 22:52:56 +00:00
|
|
|
ReplyToMsgID : 11,
|
2016-02-03 04:35:59 +00:00
|
|
|
|
|
|
|
// :TODO: ConfName
|
2015-12-12 22:52:56 +00:00
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
},
|
2016-01-02 20:40:02 +00:00
|
|
|
|
2015-09-08 03:18:09 +00:00
|
|
|
ViewModeFooter : {
|
|
|
|
MsgNum : 6,
|
|
|
|
MsgTotal : 7,
|
2015-09-13 01:18:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
ReplyEditModeHeader : {
|
|
|
|
From : 1,
|
|
|
|
To : 2,
|
|
|
|
Subject : 3,
|
2016-01-02 20:40:02 +00:00
|
|
|
|
|
|
|
ErrorMsg : 13,
|
|
|
|
},
|
2015-09-04 06:02:28 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +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
|
|
|
|
|
|
|
|
exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModule extends MessageAreaConfTempSwitcher(MenuModule) {
|
|
|
|
|
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
const self = this;
|
|
|
|
const config = this.menuConfig.config;
|
|
|
|
|
|
|
|
//
|
|
|
|
// menuConfig.config:
|
|
|
|
// editorType : email | area
|
|
|
|
// editorMode : view | edit | quote
|
|
|
|
//
|
|
|
|
// menuConfig.config or extraArgs
|
|
|
|
// messageAreaTag
|
|
|
|
// messageIndex / messageTotal
|
|
|
|
// toUserId
|
|
|
|
//
|
|
|
|
this.editorType = config.editorType;
|
|
|
|
this.editorMode = config.editorMode;
|
|
|
|
|
|
|
|
if(config.messageAreaTag) {
|
|
|
|
this.messageAreaTag = config.messageAreaTag;
|
2016-01-04 00:46:32 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
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(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;
|
|
|
|
}
|
2016-01-04 00:46:32 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
this.isReady = false;
|
|
|
|
|
|
|
|
if(_.has(options, 'extraArgs.message')) {
|
|
|
|
this.setMessage(options.extraArgs.message);
|
|
|
|
} else if(_.has(options, 'extraArgs.replyToMessage')) {
|
|
|
|
this.replyToMessage = options.extraArgs.replyToMessage;
|
2016-01-04 00:46:32 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
|
|
|
|
this.menuMethods = {
|
|
|
|
//
|
|
|
|
// Validation stuff
|
|
|
|
//
|
|
|
|
viewValidationListener : function(err, cb) {
|
|
|
|
var errMsgView = self.viewControllers.header.getView(MciCodeIds.ReplyEditModeHeader.ErrorMsg);
|
|
|
|
var newFocusViewId;
|
|
|
|
if(errMsgView) {
|
|
|
|
if(err) {
|
|
|
|
errMsgView.setText(err.message);
|
|
|
|
|
|
|
|
if(MciCodeIds.ViewModeHeader.Subject === err.view.getId()) {
|
|
|
|
// :TODO: for "area" mode, should probably just bail if this is emtpy (e.g. cancel)
|
|
|
|
}
|
|
|
|
} 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) {
|
|
|
|
// :TODO:... what now?
|
|
|
|
console.log(err)
|
|
|
|
} else {
|
|
|
|
switch(self.footerMode) {
|
|
|
|
case 'editor' :
|
|
|
|
if(!_.isUndefined(self.viewControllers.footerEditorMenu)) {
|
|
|
|
//self.viewControllers.footerEditorMenu.setFocus(false);
|
|
|
|
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) {
|
|
|
|
// :TODO: Dont' use magic # ID's here
|
2017-08-25 04:23:14 +00:00
|
|
|
const quoteMsgView = self.viewControllers.quoteBuilder.getView(1);
|
2017-08-27 17:17:29 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(self.newQuoteBlock) {
|
|
|
|
self.newQuoteBlock = false;
|
2017-08-27 17:17:29 +00:00
|
|
|
|
|
|
|
// :TODO: If replying to ANSI, add a blank sepration line here
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
quoteMsgView.addText(self.getQuoteByHeader());
|
|
|
|
}
|
|
|
|
|
2017-08-25 04:23:14 +00:00
|
|
|
const quoteText = self.viewControllers.quoteBuilder.getView(3).getItem(formData.value.quote);
|
2017-01-26 05:18:05 +00:00
|
|
|
quoteMsgView.addText(quoteText);
|
|
|
|
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
2017-08-25 04:23:14 +00:00
|
|
|
const quoteListView = self.viewControllers.quoteBuilder.getView(3);
|
2017-01-26 05:18:05 +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);
|
|
|
|
},
|
|
|
|
/*
|
|
|
|
replyDiscard : function(formData, extraArgs) {
|
|
|
|
// :TODO: need to prompt yes/no
|
|
|
|
// :TODO: @method for fallback would be better
|
|
|
|
self.prevMenu();
|
|
|
|
},
|
|
|
|
*/
|
|
|
|
editModeMenuHelp : function(formData, extraArgs, cb) {
|
|
|
|
self.viewControllers.footerEditorMenu.setFocus(false);
|
|
|
|
return self.displayHelp(cb);
|
|
|
|
},
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// View Mode
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
viewModeMenuHelp : function(formData, extraArgs, cb) {
|
|
|
|
self.viewControllers.footerView.setFocus(false);
|
|
|
|
return self.displayHelp(cb);
|
|
|
|
}
|
|
|
|
};
|
2015-08-16 19:35:34 +00:00
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
isEditMode() {
|
|
|
|
return 'edit' === this.editorMode;
|
|
|
|
}
|
2018-01-01 20:32:55 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
isViewMode() {
|
|
|
|
return 'view' === this.editorMode;
|
|
|
|
}
|
2015-07-16 05:51:00 +00:00
|
|
|
|
2018-01-01 20:32:55 +00:00
|
|
|
isPrivateMail() {
|
2017-01-26 05:18:05 +00:00
|
|
|
return Message.WellKnownAreaTags.Private === this.messageAreaTag;
|
|
|
|
}
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
isReply() {
|
|
|
|
return !_.isUndefined(this.replyToMessage);
|
|
|
|
}
|
2015-09-20 07:29:07 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
getFooterName() {
|
2017-01-28 19:33:06 +00:00
|
|
|
return 'footer' + _.upperFirst(this.footerMode); // e.g. 'footerEditor', 'footerEditorMenu', ...
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
getFormId(name) {
|
2015-07-09 04:07:25 +00:00
|
|
|
return {
|
2015-09-04 20:28:05 +00:00
|
|
|
header : 0,
|
|
|
|
body : 1,
|
|
|
|
footerEditor : 2,
|
|
|
|
footerEditorMenu : 3,
|
|
|
|
footerView : 4,
|
2015-09-15 04:40:00 +00:00
|
|
|
quoteBuilder : 5,
|
2015-07-11 22:39:42 +00:00
|
|
|
|
2015-09-04 20:28:05 +00:00
|
|
|
help : 50,
|
2015-07-10 05:23:37 +00:00
|
|
|
}[name];
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-20 07:29:07 +00:00
|
|
|
|
|
|
|
// :TODO: convert to something like this for all view acces:
|
2017-01-26 05:18:05 +00:00
|
|
|
getHeaderViews() {
|
|
|
|
var vc = this.viewControllers.header;
|
2015-09-20 07:29:07 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(this.isViewMode()) {
|
2015-09-20 07:29:07 +00:00
|
|
|
return {
|
2016-08-04 01:48:45 +00:00
|
|
|
from : vc.getView(1),
|
|
|
|
to : vc.getView(2),
|
|
|
|
subject : vc.getView(3),
|
2015-09-20 07:29:07 +00:00
|
|
|
|
|
|
|
dateTime : vc.getView(5),
|
|
|
|
msgNum : vc.getView(7),
|
|
|
|
// ...
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-20 07:29:07 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
setInitialFooterMode() {
|
|
|
|
switch(this.editorMode) {
|
|
|
|
case 'edit' : this.footerMode = 'editor'; break;
|
|
|
|
case 'view' : this.footerMode = 'view'; break;
|
2015-09-04 20:28:05 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-04 20:28:05 +00:00
|
|
|
|
2017-08-25 04:23:14 +00:00
|
|
|
buildMessage(cb) {
|
2017-02-13 05:13:03 +00:00
|
|
|
const headerValues = this.viewControllers.header.getFormData().value;
|
2015-07-13 04:56:33 +00:00
|
|
|
|
2017-08-19 21:25:05 +00:00
|
|
|
const msgOpts = {
|
2017-01-26 05:18:05 +00:00
|
|
|
areaTag : this.messageAreaTag,
|
2015-07-13 20:58:45 +00:00
|
|
|
toUserName : headerValues.to,
|
2017-02-13 05:13:03 +00:00
|
|
|
fromUserName : this.client.user.username,
|
2015-07-13 20:58:45 +00:00
|
|
|
subject : headerValues.subject,
|
2017-08-27 17:17:29 +00:00
|
|
|
// :TODO: don't hard code 1 here:
|
|
|
|
message : this.viewControllers.body.getView(1).getData( { forceLineTerms : this.replyIsAnsi } ),
|
2015-07-13 04:56:33 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(this.isReply()) {
|
|
|
|
msgOpts.replyToMsgId = this.replyToMessage.messageId;
|
2017-08-19 21:25:05 +00:00
|
|
|
|
|
|
|
if(this.replyIsAnsi) {
|
|
|
|
//
|
|
|
|
// Ensure first characters indicate ANSI for detection down
|
2017-08-21 02:42:25 +00:00
|
|
|
// 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!)
|
2017-08-19 21:25:05 +00:00
|
|
|
//
|
2017-08-21 02:42:25 +00:00
|
|
|
msgOpts.meta = { System : { 'explicit_encoding' : Config.scannerTossers.ftn_bso.packetAnsiMsgEncoding || 'cp437' } };
|
2017-08-29 05:17:35 +00:00
|
|
|
msgOpts.message = `${ansi.reset()}${ansi.eraseData(2)}${ansi.goto(1,1)}\r\n${ansi.up()}${msgOpts.message}`;
|
2017-08-19 21:25:05 +00:00
|
|
|
}
|
2015-09-20 07:29:07 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.message = new Message(msgOpts);
|
2017-08-25 04:23:14 +00:00
|
|
|
|
|
|
|
return cb(null);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2016-05-24 02:45:18 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
setMessage(message) {
|
|
|
|
this.message = message;
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2016-01-04 00:46:32 +00:00
|
|
|
updateMessageAreaLastReadId(
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.user.userId, this.messageAreaTag, this.message.messageId, () => {
|
2015-10-22 21:44:44 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(this.isReady) {
|
|
|
|
this.initHeaderViewMode();
|
|
|
|
this.initFooterViewMode();
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-08-25 04:23:14 +00:00
|
|
|
const bodyMessageView = this.viewControllers.body.getView(1);
|
|
|
|
let msg = this.message.message;
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(bodyMessageView && _.has(this, 'message.message')) {
|
2017-08-17 03:36:14 +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
|
|
|
|
//
|
2017-08-25 04:23:14 +00:00
|
|
|
if(isAnsi(msg)) {
|
|
|
|
//
|
|
|
|
// Find tearline - we want to color it differently.
|
|
|
|
//
|
|
|
|
const tearLinePos = this.message.getTearLinePosition(msg);
|
|
|
|
|
|
|
|
if(tearLinePos > -1) {
|
|
|
|
msg = insert(msg, tearLinePos, bodyMessageView.getSGRFor('text'));
|
|
|
|
}
|
|
|
|
|
2017-08-17 03:36:14 +00:00
|
|
|
bodyMessageView.setAnsi(
|
2017-08-25 04:23:14 +00:00
|
|
|
msg.replace(/\r?\n/g, '\r\n'), // messages are stored with CRLF -> LF
|
2017-08-17 03:36:14 +00:00
|
|
|
{
|
2017-08-21 02:42:25 +00:00
|
|
|
prepped : false,
|
|
|
|
forceLineTerm : true,
|
2017-08-17 03:36:14 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
} else {
|
2017-08-25 04:23:14 +00:00
|
|
|
bodyMessageView.setText(cleanControlCodes(msg));
|
2017-08-17 03:36:14 +00:00
|
|
|
}
|
2016-05-24 02:45:18 +00:00
|
|
|
}
|
2016-01-04 00:46:32 +00:00
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
}
|
2016-05-24 02:45:18 +00:00
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getMessage(cb) {
|
|
|
|
const self = this;
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2015-09-21 01:10:09 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function buildIfNecessary(callback) {
|
|
|
|
if(self.isEditMode()) {
|
2017-08-25 04:23:14 +00:00
|
|
|
return self.buildMessage(callback); // creates initial self.message
|
2015-09-21 01:10:09 +00:00
|
|
|
}
|
2017-08-25 04:23:14 +00:00
|
|
|
|
|
|
|
return callback(null);
|
2015-09-21 01:10:09 +00:00
|
|
|
},
|
|
|
|
function populateLocalUserInfo(callback) {
|
2018-01-12 04:39:14 +00:00
|
|
|
if(!self.isPrivateMail()) {
|
|
|
|
return callback(null);
|
|
|
|
}
|
2018-01-06 05:03:33 +00:00
|
|
|
|
2018-01-12 04:39:14 +00:00
|
|
|
// :TODO: shouldn't local from user ID be set for all mail?
|
|
|
|
self.message.setLocalFromUserId(self.client.user.userId);
|
|
|
|
|
|
|
|
if(self.toUserId > 0) {
|
|
|
|
self.message.setLocalToUserId(self.toUserId);
|
|
|
|
return callback(null);
|
2015-09-21 01:10:09 +00:00
|
|
|
}
|
2018-01-12 04:39:14 +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-01-13 06:44:22 +00:00
|
|
|
if(self.replyToMessage && self.replyToMessage.isFromRemoteUser()) {
|
2018-01-12 04:39:14 +00:00
|
|
|
self.message.setRemoteToUser(self.replyToMessage.meta.System[Message.SystemMetaNames.RemoteFromUser]);
|
|
|
|
self.message.setExternalFlavor(self.replyToMessage.meta.System[Message.SystemMetaNames.ExternalFlavor]);
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
|
2018-01-13 16:06:50 +00:00
|
|
|
//
|
|
|
|
// Detect if the user is attempting to send to a remote mail type that we support
|
|
|
|
//
|
|
|
|
// :TODO: how to plug in support without tying to various types here? isSupportedExteranlType() or such
|
|
|
|
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-01-12 04:39:14 +00:00
|
|
|
// we need to look it up
|
|
|
|
User.getUserIdAndNameByLookup(self.message.toUserName, (err, toUserId) => {
|
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.message.setLocalToUserId(toUserId);
|
|
|
|
return callback(null);
|
|
|
|
});
|
2015-09-21 01:10:09 +00:00
|
|
|
}
|
|
|
|
],
|
2018-01-12 04:39:14 +00:00
|
|
|
err => {
|
|
|
|
return cb(err, self.message);
|
2015-09-21 01:10:09 +00:00
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-13 04:56:33 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
updateUserStats(cb) {
|
2016-07-28 03:44:27 +00:00
|
|
|
if(Message.isPrivateAreaTag(this.message.areaTag)) {
|
|
|
|
if(cb) {
|
2017-01-26 05:18:05 +00:00
|
|
|
cb(null);
|
2016-07-28 03:44:27 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
return; // don't inc stats for private messages
|
2016-07-28 03:44:27 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
return StatLog.incrementUserStat(this.client.user, 'post_count', 1, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
redrawFooter(options, cb) {
|
|
|
|
const self = this;
|
2016-07-28 03:44:27 +00:00
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function moveToFooterPosition(callback) {
|
|
|
|
//
|
2015-09-12 23:17:00 +00:00
|
|
|
// Calculate footer starting position
|
2015-07-09 04:07:25 +00:00
|
|
|
//
|
|
|
|
// row = (header height + body height)
|
|
|
|
//
|
2015-09-12 23:17:00 +00:00
|
|
|
var footerRow = self.header.height + self.body.height;
|
|
|
|
self.client.term.rawWrite(ansi.goto(footerRow, 1));
|
2015-07-09 04:07:25 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function clearFooterArea(callback) {
|
|
|
|
if(options.clear) {
|
2015-09-12 23:17:00 +00:00
|
|
|
// footer up to 3 rows in height
|
2016-01-02 20:40:02 +00:00
|
|
|
|
|
|
|
// :TODO: We'd like to delete up to N rows, but this does not work
|
|
|
|
// in NetRunner:
|
2016-02-10 05:30:59 +00:00
|
|
|
self.client.term.rawWrite(ansi.reset() + ansi.deleteLine(3));
|
2016-01-02 20:40:02 +00:00
|
|
|
|
2016-06-29 05:07:15 +00:00
|
|
|
self.client.term.rawWrite(ansi.reset() + ansi.eraseLine(2));
|
2015-07-09 04:07:25 +00:00
|
|
|
}
|
|
|
|
callback(null);
|
|
|
|
},
|
|
|
|
function displayFooterArt(callback) {
|
2017-01-28 19:33:06 +00:00
|
|
|
const footerArt = self.menuConfig.config.art[options.footerName];
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2017-01-30 02:56:34 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
footerArt,
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
|
|
|
function displayed(err, artData) {
|
2015-07-25 00:33:59 +00:00
|
|
|
callback(err, artData);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-09 04:07:25 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err, artData) {
|
|
|
|
cb(err, artData);
|
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
redrawScreen(cb) {
|
2015-07-11 22:39:42 +00:00
|
|
|
var comps = [ 'header', 'body' ];
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
2015-07-11 22:39:42 +00:00
|
|
|
var art = self.menuConfig.config.art;
|
|
|
|
|
|
|
|
self.client.term.rawWrite(ansi.resetScreen());
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function displayHeaderAndBody(callback) {
|
|
|
|
async.eachSeries( comps, function dispArt(n, next) {
|
2015-07-25 22:10:12 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
art[n],
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2015-07-25 00:33:59 +00:00
|
|
|
function displayed(err, artData) {
|
|
|
|
next(err);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-11 22:39:42 +00:00
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function displayFooter(callback) {
|
|
|
|
// we have to treat the footer special
|
|
|
|
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();
|
|
|
|
});
|
2015-11-28 19:17:14 +00:00
|
|
|
|
|
|
|
callback(null);
|
2015-07-11 22:39:42 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
cb(err);
|
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-11 22:39:42 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
switchFooter(cb) {
|
|
|
|
var footerName = this.getFooterName();
|
2015-09-15 04:40:00 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.redrawFooter( { footerName : footerName, clear : true }, (err, artData) => {
|
2015-07-09 04:07:25 +00:00
|
|
|
if(err) {
|
|
|
|
cb(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
var formId = this.getFormId(footerName);
|
2015-07-09 04:07:25 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
if(_.isUndefined(this.viewControllers[footerName])) {
|
2015-07-09 04:07:25 +00:00
|
|
|
var menuLoadOpts = {
|
2017-01-26 05:18:05 +00:00
|
|
|
callingMenu : this,
|
2015-07-09 04:07:25 +00:00
|
|
|
formId : formId,
|
|
|
|
mciMap : artData.mciMap
|
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.addViewController(
|
2015-07-09 04:07:25 +00:00
|
|
|
footerName,
|
2017-01-26 05:18:05 +00:00
|
|
|
new ViewController( { client : this.client, formId : formId } )
|
|
|
|
).loadFromMenuConfig(menuLoadOpts, err => {
|
2015-07-09 04:07:25 +00:00
|
|
|
cb(err);
|
|
|
|
});
|
|
|
|
} else {
|
2017-01-26 05:18:05 +00:00
|
|
|
this.viewControllers[footerName].redrawAll();
|
2015-07-09 04:07:25 +00:00
|
|
|
cb(null);
|
|
|
|
}
|
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-06 01:05:55 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
initSequence() {
|
2015-06-26 04:34:33 +00:00
|
|
|
var mciData = { };
|
2017-01-26 05:18:05 +00:00
|
|
|
const self = this;
|
2015-07-04 18:02:37 +00:00
|
|
|
var art = self.menuConfig.config.art;
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
assert(_.isObject(art));
|
2015-06-26 04:34:33 +00:00
|
|
|
|
2015-07-06 01:05:55 +00:00
|
|
|
async.series(
|
2015-06-25 05:09:26 +00:00
|
|
|
[
|
|
|
|
function beforeDisplayArt(callback) {
|
2016-06-29 05:07:15 +00:00
|
|
|
self.beforeArt(callback);
|
2015-06-25 05:09:26 +00:00
|
|
|
},
|
2015-07-09 04:07:25 +00:00
|
|
|
function displayHeaderAndBodyArt(callback) {
|
2015-07-04 18:02:37 +00:00
|
|
|
assert(_.isString(art.header));
|
|
|
|
assert(_.isString(art.body));
|
|
|
|
|
|
|
|
async.eachSeries( [ 'header', 'body' ], function dispArt(n, next) {
|
2015-08-03 00:27:05 +00:00
|
|
|
theme.displayThemedAsset(
|
2015-07-25 00:33:59 +00:00
|
|
|
art[n],
|
|
|
|
self.client,
|
2015-07-25 22:10:12 +00:00
|
|
|
{ font : self.menuConfig.font },
|
2015-07-25 00:33:59 +00:00
|
|
|
function displayed(err, artData) {
|
2015-09-27 21:35:24 +00:00
|
|
|
if(artData) {
|
|
|
|
mciData[n] = artData;
|
|
|
|
self[n] = { height : artData.height };
|
|
|
|
}
|
2015-09-12 23:17:00 +00:00
|
|
|
|
2015-07-25 00:33:59 +00:00
|
|
|
next(err);
|
2015-07-25 22:10:12 +00:00
|
|
|
}
|
|
|
|
);
|
2015-07-04 18:02:37 +00:00
|
|
|
}, function complete(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-07-09 04:07:25 +00:00
|
|
|
function displayFooter(callback) {
|
2015-09-04 20:28:05 +00:00
|
|
|
self.setInitialFooterMode();
|
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
var footerName = self.getFooterName();
|
2015-09-12 23:17:00 +00:00
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
self.redrawFooter( { footerName : footerName }, function artDisplayed(err, artData) {
|
2015-07-06 01:05:55 +00:00
|
|
|
mciData[footerName] = artData;
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
2015-06-26 04:34:33 +00:00
|
|
|
function afterArtDisplayed(callback) {
|
2015-09-06 21:58:58 +00:00
|
|
|
self.mciReady(mciData, callback);
|
2015-06-26 04:34:33 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-11-28 19:17:14 +00:00
|
|
|
if(err) {
|
|
|
|
// :TODO: This needs properly handled!
|
2015-09-01 05:18:46 +00:00
|
|
|
console.log(err)
|
2015-09-06 21:58:58 +00:00
|
|
|
} else {
|
|
|
|
self.isReady = true;
|
|
|
|
self.finishedLoading();
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2015-06-26 04:34:33 +00:00
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-06-26 04:34:33 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
createInitialViews(mciData, cb) {
|
|
|
|
const self = this;
|
2015-08-16 19:35:34 +00:00
|
|
|
var menuLoadOpts = { callingMenu : self };
|
2015-08-14 20:49:06 +00:00
|
|
|
|
2015-07-04 18:02:37 +00:00
|
|
|
async.series(
|
|
|
|
[
|
|
|
|
function header(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId('header');
|
2015-07-04 18:02:37 +00:00
|
|
|
menuLoadOpts.mciMap = mciData.header.mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'header',
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-04 18:02:37 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function headerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function body(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId('body');
|
2015-07-04 18:02:37 +00:00
|
|
|
menuLoadOpts.mciMap = mciData.body.mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
'body',
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-04 18:02:37 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function bodyReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-07-06 01:05:55 +00:00
|
|
|
},
|
|
|
|
function footer(callback) {
|
2015-07-09 04:07:25 +00:00
|
|
|
var footerName = self.getFooterName();
|
2015-07-06 01:05:55 +00:00
|
|
|
|
2015-07-09 04:07:25 +00:00
|
|
|
menuLoadOpts.formId = self.getFormId(footerName);
|
2015-07-06 01:05:55 +00:00
|
|
|
menuLoadOpts.mciMap = mciData[footerName].mciMap;
|
|
|
|
|
|
|
|
self.addViewController(
|
|
|
|
footerName,
|
2015-07-09 04:07:25 +00:00
|
|
|
new ViewController( { client : self.client, formId : menuLoadOpts.formId } )
|
2015-07-06 01:05:55 +00:00
|
|
|
).loadFromMenuConfig(menuLoadOpts, function footerReady(err) {
|
|
|
|
callback(err);
|
|
|
|
});
|
2015-08-16 19:35:34 +00:00
|
|
|
},
|
|
|
|
function prepareViewStates(callback) {
|
|
|
|
var header = self.viewControllers.header;
|
|
|
|
var from = header.getView(1);
|
|
|
|
from.acceptsFocus = false;
|
2015-09-01 21:37:03 +00:00
|
|
|
//from.setText(self.client.user.username);
|
2015-08-16 19:35:34 +00:00
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
// :TODO: make this a method
|
2015-08-16 19:35:34 +00:00
|
|
|
var body = self.viewControllers.body.getView(1);
|
|
|
|
self.updateTextEditMode(body.getTextEditMode());
|
|
|
|
self.updateEditModePosition(body.getEditPosition());
|
|
|
|
|
2015-09-02 04:20:29 +00:00
|
|
|
// :TODO: If view mode, set body to read only... which needs an impl...
|
|
|
|
|
2015-08-16 19:35:34 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
2015-09-01 21:37:03 +00:00
|
|
|
function setInitialData(callback) {
|
2015-09-13 01:18:08 +00:00
|
|
|
|
2015-09-03 05:11:17 +00:00
|
|
|
switch(self.editorMode) {
|
2016-08-04 04:43:06 +00:00
|
|
|
case 'view' :
|
|
|
|
if(self.message) {
|
|
|
|
self.initHeaderViewMode();
|
|
|
|
self.initFooterViewMode();
|
|
|
|
|
|
|
|
var bodyMessageView = self.viewControllers.body.getView(1);
|
|
|
|
if(bodyMessageView && _.has(self, 'message.message')) {
|
|
|
|
//self.setBodyMessageViewText();
|
|
|
|
bodyMessageView.setText(cleanControlCodes(self.message.message));
|
|
|
|
}
|
2015-09-13 01:18:08 +00:00
|
|
|
}
|
2016-08-04 04:43:06 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'edit' :
|
2017-08-27 02:26:41 +00:00
|
|
|
{
|
|
|
|
const fromView = self.viewControllers.header.getView(1);
|
|
|
|
const area = getMessageAreaByTag(self.messageAreaTag);
|
|
|
|
if(area && area.realNames) {
|
|
|
|
fromView.setText(self.client.user.properties.real_name || self.client.user.username);
|
|
|
|
} else {
|
|
|
|
fromView.setText(self.client.user.username);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(self.replyToMessage) {
|
|
|
|
self.initHeaderReplyEditMode();
|
|
|
|
}
|
2016-08-04 04:43:06 +00:00
|
|
|
}
|
|
|
|
break;
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2015-09-01 21:37:03 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
callback(null);
|
|
|
|
},
|
2015-08-16 19:35:34 +00:00
|
|
|
function setInitialFocus(callback) {
|
2015-09-02 04:20:29 +00:00
|
|
|
|
2015-09-01 05:18:46 +00:00
|
|
|
switch(self.editorMode) {
|
2016-08-04 04:43:06 +00:00
|
|
|
case 'edit' :
|
|
|
|
self.switchToHeader();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'view' :
|
|
|
|
self.switchToFooter();
|
|
|
|
//self.observeViewPosition();
|
|
|
|
break;
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
|
|
|
|
callback(null);
|
2015-07-04 18:02:37 +00:00
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
2015-10-05 04:04:56 +00:00
|
|
|
if(err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
cb(err);
|
2015-07-04 18:02:37 +00:00
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-08-16 19:35:34 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReadyHandler(mciData, cb) {
|
2015-08-16 19:35:34 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.createInitialViews(mciData, err => {
|
2015-12-11 04:43:57 +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
|
2015-12-12 22:52:56 +00:00
|
|
|
|
|
|
|
/*
|
2015-08-20 04:10:18 +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-12-12 22:52:56 +00:00
|
|
|
});*/
|
2015-09-06 21:58:58 +00:00
|
|
|
|
|
|
|
cb(err);
|
2015-08-16 19:35:34 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-04 18:02:37 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
updateEditModePosition(pos) {
|
|
|
|
if(this.isEditMode()) {
|
|
|
|
var posView = this.viewControllers.footerEditor.getView(1);
|
2015-07-06 01:05:55 +00:00
|
|
|
if(posView) {
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.term.rawWrite(ansi.savePos());
|
|
|
|
// :TODO: Use new formatting techniques here, e.g. state.cursorPositionRow, cursorPositionCol and cursorPositionFormat
|
2017-01-28 19:33:06 +00:00
|
|
|
posView.setText(_.padStart(String(pos.row + 1), 2, '0') + ',' + _.padEnd(String(pos.col + 1), 2, '0'));
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.term.rawWrite(ansi.restorePos());
|
2015-07-06 05:16:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-06 05:16:22 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
updateTextEditMode(mode) {
|
|
|
|
if(this.isEditMode()) {
|
|
|
|
var modeView = this.viewControllers.footerEditor.getView(2);
|
2015-07-06 05:16:22 +00:00
|
|
|
if(modeView) {
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.term.rawWrite(ansi.savePos());
|
2015-07-06 05:16:22 +00:00
|
|
|
modeView.setText('insert' === mode ? 'INS' : 'OVR');
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.term.rawWrite(ansi.restorePos());
|
2015-07-06 01:05:55 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-06 01:05:55 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
setHeaderText(id, text) {
|
|
|
|
this.setViewText('header', id, text);
|
|
|
|
}
|
2015-10-06 21:22:49 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
initHeaderViewMode() {
|
|
|
|
assert(_.isObject(this.message));
|
2015-10-06 21:22:49 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.From, this.message.fromUserName);
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.To, this.message.toUserName);
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.Subject, this.message.subject);
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.DateTime, moment(this.message.modTimestamp).format(this.client.currentTheme.helpers.getDateTimeFormat()));
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.MsgNum, (this.messageIndex + 1).toString());
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.MsgTotal, this.messageTotal.toString());
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.ViewCount, this.message.viewCount);
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.HashTags, 'TODO hash tags');
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.MessageID, this.message.messageId);
|
|
|
|
this.setHeaderText(MciCodeIds.ViewModeHeader.ReplyToMsgID, this.message.replyToMessageId);
|
|
|
|
}
|
2015-09-04 06:02:28 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
initHeaderReplyEditMode() {
|
|
|
|
assert(_.isObject(this.replyToMessage));
|
2015-09-13 01:18:08 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.setHeaderText(MciCodeIds.ReplyEditModeHeader.To, this.replyToMessage.fromUserName);
|
2016-01-02 20:40:02 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// We want to prefix the subject with "RE: " only if it's not already
|
|
|
|
// that way -- avoid RE: RE: RE: RE: ...
|
|
|
|
//
|
2017-01-26 05:18:05 +00:00
|
|
|
let newSubj = this.replyToMessage.subject;
|
2016-04-12 02:22:55 +00:00
|
|
|
if(false === /^RE:\s+/i.test(newSubj)) {
|
|
|
|
newSubj = `RE: ${newSubj}`;
|
2016-01-02 20:40:02 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.setHeaderText(MciCodeIds.ReplyEditModeHeader.Subject, newSubj);
|
|
|
|
}
|
2015-09-08 03:18:09 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
initFooterViewMode() {
|
|
|
|
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgNum, (this.messageIndex + 1).toString() );
|
|
|
|
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgTotal, this.messageTotal.toString() );
|
|
|
|
}
|
2015-09-08 03:18:09 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
displayHelp(cb) {
|
|
|
|
this.client.term.rawWrite(ansi.resetScreen());
|
2015-07-11 22:39:42 +00:00
|
|
|
|
2016-07-25 20:35:58 +00:00
|
|
|
theme.displayThemeArt(
|
2017-01-26 05:18:05 +00:00
|
|
|
{ name : this.menuConfig.config.art.help, client : this.client },
|
2016-07-25 20:35:58 +00:00
|
|
|
() => {
|
2017-01-26 05:18:05 +00:00
|
|
|
this.client.waitForKeyPress( () => {
|
|
|
|
this.redrawScreen( () => {
|
|
|
|
this.viewControllers[this.getFooterName()].setFocus(true);
|
2016-07-25 20:35:58 +00:00
|
|
|
return cb(null);
|
2015-11-28 19:17:14 +00:00
|
|
|
});
|
2015-07-11 22:39:42 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-11 22:39:42 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
displayQuoteBuilder() {
|
2015-09-14 03:15:55 +00:00
|
|
|
//
|
|
|
|
// Clear body area
|
|
|
|
//
|
2017-01-26 05:18:05 +00:00
|
|
|
this.newQuoteBlock = true;
|
|
|
|
const self = this;
|
2015-09-17 04:31:09 +00:00
|
|
|
|
2015-09-15 04:40:00 +00:00
|
|
|
async.waterfall(
|
|
|
|
[
|
|
|
|
function clearAndDisplayArt(callback) {
|
2015-09-17 04:31:09 +00:00
|
|
|
|
2016-01-02 20:40:02 +00:00
|
|
|
// :TODO: use termHeight, not hard coded 24 here:
|
|
|
|
|
|
|
|
// :TODO: NetRunner does NOT support delete line, so this does not work:
|
2015-09-15 04:40:00 +00:00
|
|
|
self.client.term.rawWrite(
|
2015-09-15 05:02:09 +00:00
|
|
|
ansi.goto(self.header.height + 1, 1) +
|
|
|
|
ansi.deleteLine(24 - self.header.height));
|
2016-01-02 20:40:02 +00:00
|
|
|
|
2015-09-15 04:40:00 +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 = {
|
|
|
|
callingMenu : self,
|
|
|
|
formId : formId,
|
|
|
|
mciMap : artData.mciMap,
|
|
|
|
};
|
|
|
|
|
|
|
|
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) {
|
2017-08-17 03:36:14 +00:00
|
|
|
const quoteView = self.viewControllers.quoteBuilder.getView(3);
|
|
|
|
const bodyView = self.viewControllers.body.getView(1);
|
|
|
|
|
|
|
|
self.replyToMessage.getQuoteLines(
|
|
|
|
{
|
|
|
|
termWidth : self.client.term.termWidth,
|
|
|
|
termHeight : self.client.term.termHeight,
|
|
|
|
cols : quoteView.dimens.width,
|
|
|
|
startCol : quoteView.position.col,
|
|
|
|
ansiResetSgr : bodyView.styleSGR1,
|
|
|
|
ansiFocusPrefixSgr : quoteView.styleSGR2,
|
|
|
|
},
|
2017-08-19 21:25:05 +00:00
|
|
|
(err, quoteLines, focusQuoteLines, replyIsAnsi) => {
|
2017-08-17 03:36:14 +00:00
|
|
|
if(err) {
|
|
|
|
return callback(err);
|
|
|
|
}
|
|
|
|
|
2017-08-19 21:25:05 +00:00
|
|
|
self.replyIsAnsi = replyIsAnsi;
|
|
|
|
|
2017-08-17 03:36:14 +00:00
|
|
|
quoteView.setItems(quoteLines);
|
|
|
|
quoteView.setFocusItems(focusQuoteLines);
|
|
|
|
|
|
|
|
return callback(null);
|
|
|
|
}
|
|
|
|
);
|
2015-09-15 04:40:00 +00:00
|
|
|
},
|
|
|
|
function setViewFocus(callback) {
|
|
|
|
self.viewControllers.quoteBuilder.getView(1).setFocus(false);
|
|
|
|
self.viewControllers.quoteBuilder.switchFocus(3);
|
|
|
|
|
|
|
|
callback(null);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
function complete(err) {
|
|
|
|
if(err) {
|
|
|
|
console.log(err) // :TODO: needs real impl.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-09-14 03:15:55 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
observeEditorEvents() {
|
|
|
|
const bodyView = this.viewControllers.body.getView(1);
|
2015-07-09 22:28:44 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
bodyView.on('edit position', pos => {
|
|
|
|
this.updateEditModePosition(pos);
|
2015-07-09 22:28:44 +00:00
|
|
|
});
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
bodyView.on('text edit mode', mode => {
|
|
|
|
this.updateTextEditMode(mode);
|
2015-07-09 22:28:44 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-07-09 22:28:44 +00:00
|
|
|
|
2015-09-20 04:55:09 +00:00
|
|
|
/*
|
|
|
|
this.observeViewPosition = function() {
|
|
|
|
self.viewControllers.body.getView(1).on('edit position', function positionUpdate(pos) {
|
|
|
|
console.log(pos.percent + ' / ' + pos.below)
|
|
|
|
});
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
switchToHeader() {
|
|
|
|
this.viewControllers.body.setFocus(false);
|
|
|
|
this.viewControllers.header.switchFocus(2); // to
|
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
switchToBody() {
|
|
|
|
this.viewControllers.header.setFocus(false);
|
|
|
|
this.viewControllers.body.switchFocus(1);
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.observeEditorEvents();
|
2018-01-14 20:52:40 +00:00
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
switchToFooter() {
|
|
|
|
this.viewControllers.header.setFocus(false);
|
|
|
|
this.viewControllers.body.setFocus(false);
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.viewControllers[this.getFooterName()].switchFocus(1); // HM1
|
|
|
|
}
|
2015-09-06 21:58:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
switchFromQuoteBuilderToBody() {
|
|
|
|
this.viewControllers.quoteBuilder.setFocus(false);
|
|
|
|
var body = this.viewControllers.body.getView(1);
|
2015-09-18 04:53:19 +00:00
|
|
|
body.redraw();
|
2017-01-26 05:18:05 +00:00
|
|
|
this.viewControllers.body.switchFocus(1);
|
2015-09-18 04:53:19 +00:00
|
|
|
|
|
|
|
// :TODO: create method (DRY)
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.updateTextEditMode(body.getTextEditMode());
|
|
|
|
this.updateEditModePosition(body.getEditPosition());
|
2015-09-18 04:53:19 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.observeEditorEvents();
|
|
|
|
}
|
2016-01-05 06:32:01 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
quoteBuilderFinalize() {
|
2016-01-05 06:32:01 +00:00
|
|
|
// :TODO: fix magic #'s
|
2017-08-25 04:23:14 +00:00
|
|
|
const quoteMsgView = this.viewControllers.quoteBuilder.getView(1);
|
|
|
|
const msgView = this.viewControllers.body.getView(1);
|
|
|
|
|
2017-09-09 05:07:11 +00:00
|
|
|
let quoteLines = quoteMsgView.getData().trim();
|
2016-01-05 06:32:01 +00:00
|
|
|
|
2017-09-09 05:07:11 +00:00
|
|
|
if(quoteLines.length > 0) {
|
2017-08-25 04:23:14 +00:00
|
|
|
if(this.replyIsAnsi) {
|
|
|
|
const bodyMessageView = this.viewControllers.body.getView(1);
|
|
|
|
quoteLines += `${ansi.normal()}${bodyMessageView.getSGRFor('text')}`;
|
|
|
|
}
|
2017-09-09 05:07:11 +00:00
|
|
|
msgView.addText(`${quoteLines}\n\n`);
|
2016-01-05 06:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
quoteMsgView.setText('');
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.footerMode = 'editor';
|
2016-01-05 06:32:01 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
this.switchFooter( () => {
|
|
|
|
this.switchFromQuoteBuilderToBody();
|
2016-01-05 06:32:01 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2015-06-25 05:12:03 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
getQuoteByHeader() {
|
2016-09-05 03:36:26 +00:00
|
|
|
let quoteFormat = this.menuConfig.config.quoteFormats;
|
2017-01-26 05:18:05 +00:00
|
|
|
|
2016-09-05 03:36:26 +00:00
|
|
|
if(Array.isArray(quoteFormat)) {
|
|
|
|
quoteFormat = quoteFormat[ Math.floor(Math.random() * quoteFormat.length) ];
|
|
|
|
} else if(!_.isString(quoteFormat)) {
|
|
|
|
quoteFormat = 'On {dateTime} {userName} said...';
|
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const dtFormat = this.menuConfig.config.quoteDateTimeFormat || this.client.currentTheme.helpers.getDateTimeFormat();
|
2016-09-05 03:36:26 +00:00
|
|
|
return stringFormat(quoteFormat, {
|
2017-01-26 05:18:05 +00:00
|
|
|
dateTime : moment(this.replyToMessage.modTimestamp).format(dtFormat),
|
|
|
|
userName : this.replyToMessage.fromUserName,
|
2016-09-05 03:36:26 +00:00
|
|
|
});
|
2017-01-26 05:18:05 +00:00
|
|
|
}
|
2016-07-25 20:35:58 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
enter() {
|
|
|
|
if(this.messageAreaTag) {
|
|
|
|
this.tempMessageConfAndAreaSwitch(this.messageAreaTag);
|
2015-06-27 21:32:29 +00:00
|
|
|
}
|
2015-09-01 05:18:46 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
super.enter();
|
2015-09-01 05:18:46 +00:00
|
|
|
}
|
2016-08-04 01:48:45 +00:00
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
leave() {
|
|
|
|
this.tempMessageConfAndAreaRestore();
|
|
|
|
super.leave();
|
2016-08-04 01:48:45 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
mciReady(mciData, cb) {
|
|
|
|
return this.mciReadyHandler(mciData, cb);
|
|
|
|
}
|
2015-06-26 04:34:33 +00:00
|
|
|
};
|