Resolve: System methods prev/nextArea, and prev/nextConf can cause a crash #79

This commit is contained in:
Bryan Ashby 2016-07-25 14:35:58 -06:00
parent fb737357f5
commit 0a629feeb0
16 changed files with 376 additions and 353 deletions

View file

@ -1,14 +1,12 @@
/* jslint node: true */
'use strict';
var FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
var Message = require('../core/message.js');
var messageArea = require('../core/message_area.js');
var user = require('../core/user.js');
// ENiGMA½
const FullScreenEditorModule = require('../core/fse.js').FullScreenEditorModule;
const Message = require('../core/message.js');
var _ = require('lodash');
var async = require('async');
var assert = require('assert');
// deps
const _ = require('lodash');
exports.getModule = AreaViewFSEModule;
@ -21,8 +19,7 @@ exports.moduleInfo = {
function AreaViewFSEModule(options) {
FullScreenEditorModule.call(this, options);
var self = this;
var config = this.menuConfig.config;
const self = this;
this.editorType = 'area';
this.editorMode = 'view';
@ -36,57 +33,67 @@ function AreaViewFSEModule(options) {
this.messageIndex = this.messageIndex || 0;
this.messageTotal = this.messageList.length;
this.menuMethods.nextMessage = function(formData, extraArgs) {
this.menuMethods.nextMessage = function(formData, extraArgs, cb) {
if(self.messageIndex + 1 < self.messageList.length) {
self.messageIndex++;
self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid);
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
}
return cb(null);
};
this.menuMethods.prevMessage = function(formData, extraArgs) {
this.menuMethods.prevMessage = function(formData, extraArgs, cb) {
if(self.messageIndex > 0) {
self.messageIndex--;
self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid);
return self.loadMessageByUuid(self.messageList[self.messageIndex].messageUuid, cb);
}
return cb(null);
};
this.menuMethods.movementKeyPressed = function(formData, extraArgs) {
var bodyView = self.viewControllers.body.getView(1);
this.menuMethods.movementKeyPressed = function(formData, extraArgs, cb) {
const bodyView = self.viewControllers.body.getView(1); // :TODO: use const here vs magic #
// :TODO: Create methods for up/down vs using keyPressXXXXX
switch(formData.key.name) {
case 'down arrow' : bodyView.scrollDocumentUp(); break;
case 'up arrow' : bodyView.scrollDocumentDown(); break;
case 'page up' : bodyView.keyPressPageUp(); break;
case 'page down' : bodyView.keyPressPageDown(); break;
case 'down arrow' : bodyView.scrollDocumentUp(); break;
case 'up arrow' : bodyView.scrollDocumentDown(); break;
case 'page up' : bodyView.keyPressPageUp(); break;
case 'page down' : bodyView.keyPressPageDown(); break;
}
// :TODO: need to stop down/page down if doing so would push the last
// visible page off the screen at all
// visible page off the screen at all .... this should be handled by MLTEV though...
return cb(null);
};
this.menuMethods.replyMessage = function(formData, extraArgs) {
this.menuMethods.replyMessage = function(formData, extraArgs, cb) {
if(_.isString(extraArgs.menu)) {
var modOpts = {
const modOpts = {
extraArgs : {
messageAreaTag : self.messageAreaTag,
replyToMessage : self.message,
}
};
self.gotoMenu(extraArgs.menu, modOpts);
} else {
self.client.log(extraArgs, 'Missing extraArgs.menu');
return self.gotoMenu(extraArgs.menu, modOpts, cb);
}
self.client.log(extraArgs, 'Missing extraArgs.menu');
return cb(null);
};
this.loadMessageByUuid = function(uuid) {
var msg = new Message();
msg.load( { uuid : uuid, user : self.client.user }, function loaded(err) {
this.loadMessageByUuid = function(uuid, cb) {
const msg = new Message();
msg.load( { uuid : uuid, user : self.client.user }, () => {
self.setMessage(msg);
if(cb) {
return cb(null);
}
});
};
}
@ -106,7 +113,7 @@ AreaViewFSEModule.prototype.getSaveState = function() {
messageList : this.messageList,
messageIndex : this.messageIndex,
messageTotal : this.messageList.length,
}
};
};
AreaViewFSEModule.prototype.restoreSavedState = function(savedState) {