MAJOR *POSSIBLY BREAKING* changes in FSE

* WIP on cleanup to use 'standard' MCI formatting / theming  used elsewhere in system
* Some MCI ID changes (e.g. FSE in edit mode %TL13 -> %TL4); update your theme.hjson / artwork!
This commit is contained in:
Bryan Ashby 2018-01-26 21:45:08 -07:00
parent a3e257aee3
commit 974ee1b389
2 changed files with 100 additions and 116 deletions

View File

@ -29,72 +29,57 @@ exports.moduleInfo = {
author : 'NuSkooler', author : 'NuSkooler',
}; };
/* const MciViewIds = {
MCI Codes - General header : {
MA - Message Area Desc from : 1,
to : 2,
MCI Codes - View Mode subject : 3,
Header errorMsg : 4,
TL1 - From modTimestamp : 5,
TL2 - To msgNum : 6,
TL3 - Subject msgTotal : 7,
TL4 - Area name
TL5 - Date/Time (TODO: format)
TL6 - Message number
TL7 - Mesage total (in area)
TL8 - View Count
TL9 - Hash tags
TL10 - Message ID
TL11 - Reply to message ID
TL12 - User1
TL13 - User2
Footer - Viewing
HM1 - Menu (prev/next/etc.)
TL6 - Message number
TL7 - Message total (in area)
TL12 - User1 (fmt message object)
TL13 - User2
*/
const MciCodeIds = {
ViewModeHeader : {
From : 1,
To : 2,
Subject : 3,
DateTime : 5,
MsgNum : 6,
MsgTotal : 7,
ViewCount : 8,
HashTags : 9,
MessageID : 10,
ReplyToMsgID : 11,
// :TODO: ConfName
customRangeStart : 10, // 10+ = customs
}, },
body : {
message : 1,
},
// :TODO: quote builder MCIs - remove all magic #'s
// :TODO: consolidate all footer MCI's - remove all magic #'s
ViewModeFooter : { ViewModeFooter : {
MsgNum : 6, MsgNum : 6,
MsgTotal : 7, MsgTotal : 7,
// :TODO: Just use custom ranges
}, },
ReplyEditModeHeader : { quoteBuilder : {
From : 1, quotedMsg : 1,
To : 2, // 2 NYI
Subject : 3, quoteLines : 3,
}
ErrorMsg : 13,
},
}; };
/*
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
*/
// :TODO: convert code in this class to newer styles, conventions, etc. There is a lot of experimental stuff here that has better (DRY) alternatives // :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) { exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModule extends MessageAreaConfTempSwitcher(MenuModule) {
@ -155,13 +140,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
// Validation stuff // Validation stuff
// //
viewValidationListener : function(err, cb) { viewValidationListener : function(err, cb) {
var errMsgView = self.viewControllers.header.getView(MciCodeIds.ReplyEditModeHeader.ErrorMsg); var errMsgView = self.viewControllers.header.getView(MciViewIds.header.errorMsg);
var newFocusViewId; var newFocusViewId;
if(errMsgView) { if(errMsgView) {
if(err) { if(err) {
errMsgView.setText(err.message); errMsgView.setText(err.message);
if(MciCodeIds.ViewModeHeader.Subject === err.view.getId()) { if(MciViewIds.header.subject === err.view.getId()) {
// :TODO: for "area" mode, should probably just bail if this is emtpy (e.g. cancel) // :TODO: for "area" mode, should probably just bail if this is emtpy (e.g. cancel)
} }
} else { } else {
@ -208,8 +193,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
return cb(null); return cb(null);
}, },
appendQuoteEntry: function(formData, extraArgs, cb) { appendQuoteEntry: function(formData, extraArgs, cb) {
// :TODO: Dont' use magic # ID's here const quoteMsgView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
const quoteMsgView = self.viewControllers.quoteBuilder.getView(1);
if(self.newQuoteBlock) { if(self.newQuoteBlock) {
self.newQuoteBlock = false; self.newQuoteBlock = false;
@ -219,14 +203,16 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
quoteMsgView.addText(self.getQuoteByHeader()); quoteMsgView.addText(self.getQuoteByHeader());
} }
const quoteText = self.viewControllers.quoteBuilder.getView(3).getItem(formData.value.quote); const quoteListView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quoteLines);
const quoteText = quoteListView.getItem(formData.value.quote);
quoteMsgView.addText(quoteText); quoteMsgView.addText(quoteText);
// //
// If this is *not* the last item, advance. Otherwise, do nothing as we // 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 // don't want to jump back to the top and repeat already quoted lines
// //
const quoteListView = self.viewControllers.quoteBuilder.getView(3);
if(quoteListView.getData() !== quoteListView.getCount() - 1) { if(quoteListView.getData() !== quoteListView.getCount() - 1) {
quoteListView.focusNext(); quoteListView.focusNext();
} else { } else {
@ -293,22 +279,28 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}[name]; }[name];
} }
// :TODO: convert to something like this for all view acces: getHeaderFormatObj() {
getHeaderViews() { const remoteUserNotAvail = this.menuConfig.config.remoteUserNotAvail || 'N/A';
var vc = this.viewControllers.header; const localUserIdNotAvail = this.menuConfig.config.localUserIdNotAvail || 'N/A';
const modTimestampFormat = this.menuConfig.config.modTimestampFormat || this.client.currentTheme.helpers.getDateTimeFormat();
if(this.isViewMode()) { return {
return { // :TODO: ensure we show real names for form/to if they are enforced in the area
from : vc.getView(1), fromUserName : this.message.fromUserName,
to : vc.getView(2), toUserName : this.message.toUserName,
subject : vc.getView(3), // :TODO:
//fromRealName
dateTime : vc.getView(5), //toRealName
msgNum : vc.getView(7), 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,
};
} }
setInitialFooterMode() { setInitialFooterMode() {
@ -327,7 +319,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
fromUserName : this.client.user.username, fromUserName : this.client.user.username,
subject : headerValues.subject, subject : headerValues.subject,
// :TODO: don't hard code 1 here: // :TODO: don't hard code 1 here:
message : this.viewControllers.body.getView(1).getData( { forceLineTerms : this.replyIsAnsi } ), message : this.viewControllers.body.getView(MciViewIds.body.message).getData( { forceLineTerms : this.replyIsAnsi } ),
}; };
if(this.isReply()) { if(this.isReply()) {
@ -360,7 +352,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
this.initHeaderViewMode(); this.initHeaderViewMode();
this.initFooterViewMode(); this.initFooterViewMode();
const bodyMessageView = this.viewControllers.body.getView(1); const bodyMessageView = this.viewControllers.body.getView(MciViewIds.body.message);
let msg = this.message.message; let msg = this.message.message;
if(bodyMessageView && _.has(this, 'message.message')) { if(bodyMessageView && _.has(this, 'message.message')) {
@ -407,14 +399,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
return callback(null); return callback(null);
}, },
function populateLocalUserInfo(callback) { function populateLocalUserInfo(callback) {
self.message.setLocalFromUserId(self.client.user.userId);
if(!self.isPrivateMail()) { if(!self.isPrivateMail()) {
return callback(null); return callback(null);
} }
// :TODO: shouldn't local from user ID be set for all mail?
self.message.setLocalFromUserId(self.client.user.userId);
if(self.toUserId > 0) { if(self.toUserId > 0) {
self.message.setLocalToUserId(self.toUserId); self.message.setLocalToUserId(self.toUserId);
return callback(null); return callback(null);
@ -695,12 +686,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}, },
function prepareViewStates(callback) { function prepareViewStates(callback) {
var header = self.viewControllers.header; var header = self.viewControllers.header;
var from = header.getView(1); var from = header.getView(MciViewIds.header.from);
from.acceptsFocus = false; from.acceptsFocus = false;
//from.setText(self.client.user.username); //from.setText(self.client.user.username);
// :TODO: make this a method // :TODO: make this a method
var body = self.viewControllers.body.getView(1); var body = self.viewControllers.body.getView(MciViewIds.body.message);
self.updateTextEditMode(body.getTextEditMode()); self.updateTextEditMode(body.getTextEditMode());
self.updateEditModePosition(body.getEditPosition()); self.updateEditModePosition(body.getEditPosition());
@ -716,7 +707,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
self.initHeaderViewMode(); self.initHeaderViewMode();
self.initFooterViewMode(); self.initFooterViewMode();
var bodyMessageView = self.viewControllers.body.getView(1); var bodyMessageView = self.viewControllers.body.getView(MciViewIds.body.message);
if(bodyMessageView && _.has(self, 'message.message')) { if(bodyMessageView && _.has(self, 'message.message')) {
//self.setBodyMessageViewText(); //self.setBodyMessageViewText();
bodyMessageView.setText(cleanControlCodes(self.message.message)); bodyMessageView.setText(cleanControlCodes(self.message.message));
@ -726,7 +717,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
case 'edit' : case 'edit' :
{ {
const fromView = self.viewControllers.header.getView(1); const fromView = self.viewControllers.header.getView(MciViewIds.header.from);
const area = getMessageAreaByTag(self.messageAreaTag); const area = getMessageAreaByTag(self.messageAreaTag);
if(area && area.realNames) { if(area && area.realNames) {
fromView.setText(self.client.user.properties.real_name || self.client.user.username); fromView.setText(self.client.user.properties.real_name || self.client.user.username);
@ -817,24 +808,20 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
} }
initHeaderViewMode() { initHeaderViewMode() {
assert(_.isObject(this.message)); 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());
this.setHeaderText(MciCodeIds.ViewModeHeader.From, this.message.fromUserName); this.updateCustomViewTextsWithFilter('header', MciViewIds.header.customRangeStart, this.getHeaderFormatObj());
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);
} }
initHeaderReplyEditMode() { initHeaderReplyEditMode() {
assert(_.isObject(this.replyToMessage)); assert(_.isObject(this.replyToMessage));
this.setHeaderText(MciCodeIds.ReplyEditModeHeader.To, this.replyToMessage.fromUserName); this.setHeaderText(MciViewIds.header.to, this.replyToMessage.fromUserName);
// //
// We want to prefix the subject with "RE: " only if it's not already // We want to prefix the subject with "RE: " only if it's not already
@ -845,12 +832,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
newSubj = `RE: ${newSubj}`; newSubj = `RE: ${newSubj}`;
} }
this.setHeaderText(MciCodeIds.ReplyEditModeHeader.Subject, newSubj); this.setHeaderText(MciViewIds.header.subject, newSubj);
} }
initFooterViewMode() { initFooterViewMode() {
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgNum, (this.messageIndex + 1).toString() ); this.setViewText('footerView', MciViewIds.ViewModeFooter.msgNum, (this.messageIndex + 1).toString() );
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgTotal, this.messageTotal.toString() ); this.setViewText('footerView', MciViewIds.ViewModeFooter.msgTotal, this.messageTotal.toString() );
} }
displayHelp(cb) { displayHelp(cb) {
@ -913,8 +900,8 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
} }
}, },
function loadQuoteLines(callback) { function loadQuoteLines(callback) {
const quoteView = self.viewControllers.quoteBuilder.getView(3); const quoteView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quoteLines);
const bodyView = self.viewControllers.body.getView(1); const bodyView = self.viewControllers.body.getView(MciViewIds.body.message);
self.replyToMessage.getQuoteLines( self.replyToMessage.getQuoteLines(
{ {
@ -935,16 +922,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
quoteView.setItems(quoteLines); quoteView.setItems(quoteLines);
quoteView.setFocusItems(focusQuoteLines); quoteView.setFocusItems(focusQuoteLines);
self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg).setFocus(false);
self.viewControllers.quoteBuilder.switchFocus(MciViewIds.quoteBuilder.quoteLines);
return callback(null); return callback(null);
} }
); );
}, },
function setViewFocus(callback) {
self.viewControllers.quoteBuilder.getView(1).setFocus(false);
self.viewControllers.quoteBuilder.switchFocus(3);
callback(null);
}
], ],
function complete(err) { function complete(err) {
if(err) { if(err) {
@ -955,7 +939,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
} }
observeEditorEvents() { observeEditorEvents() {
const bodyView = this.viewControllers.body.getView(1); const bodyView = this.viewControllers.body.getView(MciViewIds.body.message);
bodyView.on('edit position', pos => { bodyView.on('edit position', pos => {
this.updateEditModePosition(pos); this.updateEditModePosition(pos);
@ -968,7 +952,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
/* /*
this.observeViewPosition = function() { this.observeViewPosition = function() {
self.viewControllers.body.getView(1).on('edit position', function positionUpdate(pos) { self.viewControllers.body.getView(MciViewIds.body.message).on('edit position', function positionUpdate(pos) {
console.log(pos.percent + ' / ' + pos.below) console.log(pos.percent + ' / ' + pos.below)
}); });
}; };
@ -995,7 +979,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
switchFromQuoteBuilderToBody() { switchFromQuoteBuilderToBody() {
this.viewControllers.quoteBuilder.setFocus(false); this.viewControllers.quoteBuilder.setFocus(false);
var body = this.viewControllers.body.getView(1); var body = this.viewControllers.body.getView(MciViewIds.body.message);
body.redraw(); body.redraw();
this.viewControllers.body.switchFocus(1); this.viewControllers.body.switchFocus(1);
@ -1009,14 +993,14 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
quoteBuilderFinalize() { quoteBuilderFinalize() {
// :TODO: fix magic #'s // :TODO: fix magic #'s
const quoteMsgView = this.viewControllers.quoteBuilder.getView(1); const quoteMsgView = this.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
const msgView = this.viewControllers.body.getView(1); const msgView = this.viewControllers.body.getView(MciViewIds.body.message);
let quoteLines = quoteMsgView.getData().trim(); let quoteLines = quoteMsgView.getData().trim();
if(quoteLines.length > 0) { if(quoteLines.length > 0) {
if(this.replyIsAnsi) { if(this.replyIsAnsi) {
const bodyMessageView = this.viewControllers.body.getView(1); const bodyMessageView = this.viewControllers.body.getView(MciViewIds.body.message);
quoteLines += `${ansi.normal()}${bodyMessageView.getSGRFor('text')}`; quoteLines += `${ansi.normal()}${bodyMessageView.getSGRFor('text')}`;
} }
msgView.addText(`${quoteLines}\n\n`); msgView.addText(`${quoteLines}\n\n`);