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',
};
/*
MCI Codes - General
MA - Message Area Desc
MCI Codes - View Mode
Header
TL1 - From
TL2 - To
TL3 - Subject
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
const MciViewIds = {
header : {
from : 1,
to : 2,
subject : 3,
errorMsg : 4,
modTimestamp : 5,
msgNum : 6,
msgTotal : 7,
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 : {
MsgNum : 6,
MsgTotal : 7,
// :TODO: Just use custom ranges
},
ReplyEditModeHeader : {
From : 1,
To : 2,
Subject : 3,
ErrorMsg : 13,
},
quoteBuilder : {
quotedMsg : 1,
// 2 NYI
quoteLines : 3,
}
};
/*
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
exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModule extends MessageAreaConfTempSwitcher(MenuModule) {
@ -155,13 +140,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
// Validation stuff
//
viewValidationListener : function(err, cb) {
var errMsgView = self.viewControllers.header.getView(MciCodeIds.ReplyEditModeHeader.ErrorMsg);
var errMsgView = self.viewControllers.header.getView(MciViewIds.header.errorMsg);
var newFocusViewId;
if(errMsgView) {
if(err) {
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)
}
} else {
@ -208,8 +193,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
return cb(null);
},
appendQuoteEntry: function(formData, extraArgs, cb) {
// :TODO: Dont' use magic # ID's here
const quoteMsgView = self.viewControllers.quoteBuilder.getView(1);
const quoteMsgView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
if(self.newQuoteBlock) {
self.newQuoteBlock = false;
@ -219,14 +203,16 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
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);
//
// 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
//
const quoteListView = self.viewControllers.quoteBuilder.getView(3);
if(quoteListView.getData() !== quoteListView.getCount() - 1) {
quoteListView.focusNext();
} else {
@ -293,22 +279,28 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}[name];
}
// :TODO: convert to something like this for all view acces:
getHeaderViews() {
var vc = this.viewControllers.header;
getHeaderFormatObj() {
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();
if(this.isViewMode()) {
return {
from : vc.getView(1),
to : vc.getView(2),
subject : vc.getView(3),
dateTime : vc.getView(5),
msgNum : vc.getView(7),
// ...
};
}
return {
// :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:
//fromRealName
//toRealName
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() {
@ -327,7 +319,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
fromUserName : this.client.user.username,
subject : headerValues.subject,
// :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()) {
@ -360,7 +352,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
this.initHeaderViewMode();
this.initFooterViewMode();
const bodyMessageView = this.viewControllers.body.getView(1);
const bodyMessageView = this.viewControllers.body.getView(MciViewIds.body.message);
let msg = this.message.message;
if(bodyMessageView && _.has(this, 'message.message')) {
@ -407,14 +399,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
return callback(null);
},
function populateLocalUserInfo(callback) {
function populateLocalUserInfo(callback) {
self.message.setLocalFromUserId(self.client.user.userId);
if(!self.isPrivateMail()) {
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) {
self.message.setLocalToUserId(self.toUserId);
return callback(null);
@ -695,12 +686,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
},
function prepareViewStates(callback) {
var header = self.viewControllers.header;
var from = header.getView(1);
var from = header.getView(MciViewIds.header.from);
from.acceptsFocus = false;
//from.setText(self.client.user.username);
// :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.updateEditModePosition(body.getEditPosition());
@ -716,7 +707,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
self.initHeaderViewMode();
self.initFooterViewMode();
var bodyMessageView = self.viewControllers.body.getView(1);
var bodyMessageView = self.viewControllers.body.getView(MciViewIds.body.message);
if(bodyMessageView && _.has(self, 'message.message')) {
//self.setBodyMessageViewText();
bodyMessageView.setText(cleanControlCodes(self.message.message));
@ -726,7 +717,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
case 'edit' :
{
const fromView = self.viewControllers.header.getView(1);
const fromView = self.viewControllers.header.getView(MciViewIds.header.from);
const area = getMessageAreaByTag(self.messageAreaTag);
if(area && area.realNames) {
fromView.setText(self.client.user.properties.real_name || self.client.user.username);
@ -817,24 +808,20 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}
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.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);
this.updateCustomViewTextsWithFilter('header', MciViewIds.header.customRangeStart, this.getHeaderFormatObj());
}
initHeaderReplyEditMode() {
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
@ -845,12 +832,12 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
newSubj = `RE: ${newSubj}`;
}
this.setHeaderText(MciCodeIds.ReplyEditModeHeader.Subject, newSubj);
this.setHeaderText(MciViewIds.header.subject, newSubj);
}
initFooterViewMode() {
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgNum, (this.messageIndex + 1).toString() );
this.setViewText('footerView', MciCodeIds.ViewModeFooter.MsgTotal, this.messageTotal.toString() );
this.setViewText('footerView', MciViewIds.ViewModeFooter.msgNum, (this.messageIndex + 1).toString() );
this.setViewText('footerView', MciViewIds.ViewModeFooter.msgTotal, this.messageTotal.toString() );
}
displayHelp(cb) {
@ -913,8 +900,8 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}
},
function loadQuoteLines(callback) {
const quoteView = self.viewControllers.quoteBuilder.getView(3);
const bodyView = self.viewControllers.body.getView(1);
const quoteView = self.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quoteLines);
const bodyView = self.viewControllers.body.getView(MciViewIds.body.message);
self.replyToMessage.getQuoteLines(
{
@ -935,16 +922,13 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
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 setViewFocus(callback) {
self.viewControllers.quoteBuilder.getView(1).setFocus(false);
self.viewControllers.quoteBuilder.switchFocus(3);
callback(null);
}
],
function complete(err) {
if(err) {
@ -955,7 +939,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
}
observeEditorEvents() {
const bodyView = this.viewControllers.body.getView(1);
const bodyView = this.viewControllers.body.getView(MciViewIds.body.message);
bodyView.on('edit position', pos => {
this.updateEditModePosition(pos);
@ -968,7 +952,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
/*
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)
});
};
@ -995,7 +979,7 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
switchFromQuoteBuilderToBody() {
this.viewControllers.quoteBuilder.setFocus(false);
var body = this.viewControllers.body.getView(1);
var body = this.viewControllers.body.getView(MciViewIds.body.message);
body.redraw();
this.viewControllers.body.switchFocus(1);
@ -1009,14 +993,14 @@ exports.FullScreenEditorModule = exports.getModule = class FullScreenEditorModul
quoteBuilderFinalize() {
// :TODO: fix magic #'s
const quoteMsgView = this.viewControllers.quoteBuilder.getView(1);
const msgView = this.viewControllers.body.getView(1);
const quoteMsgView = this.viewControllers.quoteBuilder.getView(MciViewIds.quoteBuilder.quotedMsg);
const msgView = this.viewControllers.body.getView(MciViewIds.body.message);
let quoteLines = quoteMsgView.getData().trim();
if(quoteLines.length > 0) {
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')}`;
}
msgView.addText(`${quoteLines}\n\n`);