Merge branch 'master' of ssh://numinibsd/git/base/enigma-bbs

This commit is contained in:
Bryan Ashby 2016-06-20 14:44:06 -06:00
commit 9a71674840
16 changed files with 589 additions and 214 deletions

View File

@ -13,7 +13,7 @@ exports.getModuleAsset = getModuleAsset;
exports.resolveConfigAsset = resolveConfigAsset; exports.resolveConfigAsset = resolveConfigAsset;
exports.getViewPropertyAsset = getViewPropertyAsset; exports.getViewPropertyAsset = getViewPropertyAsset;
var ALL_ASSETS = [ const ALL_ASSETS = [
'art', 'art',
'menu', 'menu',
'method', 'method',

View File

@ -169,6 +169,10 @@ function initialize(cb) {
}, },
function readyMessageNetworkSupport(callback) { function readyMessageNetworkSupport(callback) {
require('./msg_network.js').startup(callback); require('./msg_network.js').startup(callback);
},
function readyEventScheduler(callback) {
const EventSchedulerModule = require('./event_scheduler.js').EventSchedulerModule;
EventSchedulerModule.loadAndStart(callback);
} }
], ],
function onComplete(err) { function onComplete(err) {

View File

@ -211,15 +211,24 @@ function getDefaultConfig() {
archivers : { archivers : {
zip : { zip : {
sig : "504b0304", sig : '504b0304',
offset : 0, offset : 0,
compressCmd : "7z", compressCmd : '7z',
compressArgs : [ "a", "-tzip", "{archivePath}", "{fileList}" ], compressArgs : [ 'a', '-tzip', '{archivePath}', '{fileList}' ],
decompressCmd : "7z", decompressCmd : '7z',
decompressArgs : [ "e", "-o{extractPath}", "{archivePath}" ] decompressArgs : [ 'e', '-o{extractPath}', '{archivePath}' ]
} }
}, },
messageAreaDefaults : {
//
// The following can be override per-area as well
//
maxMessages : 1024, // 0 = unlimited
maxAgeDays : 0, // 0 = unlimited
},
messageConferences : { messageConferences : {
system_internal : { system_internal : {
name : 'System Internal', name : 'System Internal',
@ -257,6 +266,25 @@ function getDefaultConfig() {
} }
}, },
eventScheduler : {
events : {
trimMessageAreas : {
// may optionally use [or ]@watch:/path/to/file
schedule : 'every 24 hours after 3:30 am',
// action:
// - @method:path/to/module.js:theMethodName
// (path is relative to engima base dir)
//
// - @execute:/path/to/something/executable.sh
//
action : '@method:core/message_area.js:trimMessageAreasScheduledEvent', // see method for avail args
}
}
},
misc : { misc : {
idleLogoutSeconds : 60 * 6, // 6m idleLogoutSeconds : 60 * 6, // 6m
}, },

View File

@ -169,17 +169,19 @@ function createMessageBaseTables() {
'END;' 'END;'
); );
// :TODO: need SQL to ensure cleaned up if delete from message?
dbs.message.run( dbs.message.run(
'CREATE TABLE IF NOT EXISTS message_meta (' + 'CREATE TABLE IF NOT EXISTS message_meta (' +
' message_id INTEGER NOT NULL,' + ' message_id INTEGER NOT NULL,' +
' meta_category INTEGER NOT NULL,' + ' meta_category INTEGER NOT NULL,' +
' meta_name VARCHAR NOT NULL,' + ' meta_name VARCHAR NOT NULL,' +
' meta_value VARCHAR NOT NULL,' + ' meta_value VARCHAR NOT NULL,' +
' UNIQUE(message_id, meta_category, meta_name, meta_value),' + // why unique here? ' UNIQUE(message_id, meta_category, meta_name, meta_value),' + // :TODO:why unique here?
' FOREIGN KEY(message_id) REFERENCES message(message_id)' + ' FOREIGN KEY(message_id) REFERENCES message(message_id)' +
');' ');'
); );
// :TODO: need SQL to ensure cleaned up if delete from message?
dbs.message.run( dbs.message.run(
'CREATE TABLE IF NOT EXISTS hash_tag (' + 'CREATE TABLE IF NOT EXISTS hash_tag (' +
' hash_tag_id INTEGER PRIMARY KEY,' + ' hash_tag_id INTEGER PRIMARY KEY,' +
@ -188,6 +190,7 @@ function createMessageBaseTables() {
');' ');'
); );
// :TODO: need SQL to ensure cleaned up if delete from message?
dbs.message.run( dbs.message.run(
'CREATE TABLE IF NOT EXISTS message_hash_tag (' + 'CREATE TABLE IF NOT EXISTS message_hash_tag (' +
' hash_tag_id INTEGER NOT NULL,' + ' hash_tag_id INTEGER NOT NULL,' +

View File

@ -1,24 +1,24 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
var spawn = require('child_process').spawn; const events = require('events');
var events = require('events');
var _ = require('lodash'); const _ = require('lodash');
var pty = require('ptyw.js'); const pty = require('ptyw.js');
var decode = require('iconv-lite').decode; const decode = require('iconv-lite').decode;
var net = require('net'); const createServer = require('net').createServer;
var async = require('async');
exports.Door = Door; exports.Door = Door;
function Door(client, exeInfo) { function Door(client, exeInfo) {
events.EventEmitter.call(this); events.EventEmitter.call(this);
const self = this;
this.client = client; this.client = client;
this.exeInfo = exeInfo; this.exeInfo = exeInfo;
this.exeInfo.encoding = this.exeInfo.encoding || 'cp437'; this.exeInfo.encoding = this.exeInfo.encoding || 'cp437';
this.exeInfo.encoding = this.exeInfo.encoding.toLowerCase();
let restored = false;
// //
// Members of exeInfo: // Members of exeInfo:
@ -32,24 +32,16 @@ function Door(client, exeInfo) {
// node // node
// inhSocket // inhSocket
// //
}
require('util').inherits(Door, events.EventEmitter); this.doorDataHandler = function(data) {
if(self.client.term.outputEncoding === self.exeInfo.encoding) {
self.client.term.rawWrite(data);
} else {
Door.prototype.run = function() {
var self = this;
var doorData = function(data) {
// :TODO: skip decoding if we have a match, e.g. cp437 === cp437
self.client.term.write(decode(data, self.exeInfo.encoding)); self.client.term.write(decode(data, self.exeInfo.encoding));
}
}; };
var restored = false; this.restoreIo = function(piped) {
var restore = function(piped) {
if(!restored && self.client.term.output) { if(!restored && self.client.term.output) {
self.client.term.output.unpipe(piped); self.client.term.output.unpipe(piped);
self.client.term.output.resume(); self.client.term.output.resume();
@ -57,56 +49,63 @@ Door.prototype.run = function() {
} }
}; };
var sockServer; this.prepareSocketIoServer = function(cb) {
async.series(
[
function prepareServer(callback) {
if('socket' === self.exeInfo.io) { if('socket' === self.exeInfo.io) {
sockServer = net.createServer(function connected(conn) { const sockServer = createServer(conn => {
sockServer.getConnections(function connCount(err, count) { sockServer.getConnections( (err, count) => {
// We expect only one connection from our DOOR/emulator/etc. // We expect only one connection from our DOOR/emulator/etc.
if(!err && count <= 1) { if(!err && count <= 1) {
self.client.term.output.pipe(conn); self.client.term.output.pipe(conn);
conn.on('data', doorData); conn.on('data', self.doorDataHandler);
conn.on('end', function ended() { conn.once('end', () => {
restore(conn); return self.restoreIo(conn);
}); });
conn.on('error', function error(err) { conn.once('error', err => {
self.client.log.info('Door socket server connection error: ' + err.message); self.client.log.info( { error : err.toString() }, 'Door socket server connection');
restore(conn); return self.restoreIo(conn);
}); });
} }
}); });
}); });
sockServer.listen(0, function listening() { sockServer.listen(0, () => {
callback(null); return cb(null, sockServer);
}); });
} else { } else {
callback(null); return cb(null);
}
};
} }
},
function launch(callback) {
// Expand arg strings, e.g. {dropFile} -> DOOR32.SYS
var args = _.clone(self.exeInfo.args); // we need a copy so the original is not modified
for(var i = 0; i < args.length; ++i) { require('util').inherits(Door, events.EventEmitter);
Door.prototype.run = function() {
const self = this;
this.prepareSocketIoServer( (err, sockServer) => {
if(err) {
this.client.log.warn( { error : err.toString() }, 'Failed executing door');
return self.emit('finished');
}
// Expand arg strings, e.g. {dropFile} -> DOOR32.SYS
let args = _.clone(self.exeInfo.args); // we need a copy so the original is not modified
for(let i = 0; i < args.length; ++i) {
args[i] = self.exeInfo.args[i].format({ args[i] = self.exeInfo.args[i].format({
dropFile : self.exeInfo.dropFile, dropFile : self.exeInfo.dropFile,
node : self.exeInfo.node.toString(), node : self.exeInfo.node.toString(),
//inhSocket : self.exeInfo.inhSocket.toString(),
srvPort : sockServer ? sockServer.address().port.toString() : '-1', srvPort : sockServer ? sockServer.address().port.toString() : '-1',
userId : self.client.user.userId.toString(), userId : self.client.user.userId.toString(),
}); });
} }
var door = pty.spawn(self.exeInfo.cmd, args, { const door = pty.spawn(self.exeInfo.cmd, args, {
cols : self.client.term.termWidth, cols : self.client.term.termWidth,
rows : self.client.term.termHeight, rows : self.client.term.termHeight,
// :TODO: cwd // :TODO: cwd
@ -118,19 +117,17 @@ Door.prototype.run = function() {
self.client.term.output.pipe(door); self.client.term.output.pipe(door);
door.on('data', doorData); door.on('data', self.doorDataHandler);
door.on('close', function closed() { door.once('close', () => {
restore(door); return self.restoreIo(door);
}); });
} else if('socket' === self.exeInfo.io) { } else if('socket' === self.exeInfo.io) {
self.client.log.debug( self.client.log.debug( { port : sockServer.address().port }, 'Using temporary socket server for door I/O');
{ port : sockServer.address().port },
'Using temporary socket server for door I/O');
} }
door.on('exit', function exited(code) { door.once('exit', exitCode => {
self.client.log.info( { code : code }, 'Door exited'); self.client.log.info( { exitCode : exitCode }, 'Door exited');
if(sockServer) { if(sockServer) {
sockServer.close(); sockServer.close();
@ -138,19 +135,12 @@ Door.prototype.run = function() {
// we may not get a close // we may not get a close
if('stdio' === self.exeInfo.io) { if('stdio' === self.exeInfo.io) {
restore(door); return self.restoreIo(door);
} }
door.removeAllListeners(); door.removeAllListeners();
self.emit('finished'); self.emit('finished');
}); });
} });
],
function complete(err) {
if(err) {
self.client.log.warn( { error : err.toString() }, 'Failed executing door');
}
}
);
}; };

202
core/event_scheduler.js Normal file
View File

@ -0,0 +1,202 @@
/* jslint node: true */
'use strict';
// ENiGMA½
const PluginModule = require('./plugin_module.js').PluginModule;
const Config = require('./config.js').config;
const Log = require('./logger.js').log;
const _ = require('lodash');
const later = require('later');
const path = require('path');
exports.getModule = EventSchedulerModule;
exports.EventSchedulerModule = EventSchedulerModule; // allow for loadAndStart
exports.moduleInfo = {
name : 'Event Scheduler',
desc : 'Support for scheduling arbritary events',
author : 'NuSkooler',
};
const SCHEDULE_REGEXP = /(?:^|or )?(@watch\:)([^\0]+)?$/;
const ACTION_REGEXP = /\@(method|execute)\:([^\0]+)?$/;
class ScheduledEvent {
constructor(events, name) {
this.name = name;
this.schedule = this.parseScheduleString(events[name].schedule);
this.action = this.parseActionSpec(events[name].action);
if(this.action) {
this.action.args = events[name].args;
}
}
get isValid() {
if((!this.schedule || (!this.schedule.sched && !this.schedule.watchFile)) || !this.action) {
return false;
}
if('method' === this.action.type && !this.action.location) {
return false;
}
return true;
}
parseScheduleString(schedStr) {
if(!schedStr) {
return false;
}
let schedule = {};
const m = SCHEDULE_REGEXP.exec(schedStr);
if(m) {
schedStr = schedStr.substr(0, m.index).trim();
if('@watch:' === m[1]) {
schedule.watchFile = m[2];
}
}
if(schedStr.length > 0) {
const sched = later.parse.text(schedStr);
if(-1 === sched.error) {
schedule.sched = sched;
}
}
// return undefined if we couldn't parse out anything useful
if(!_.isEmpty(schedule)) {
return schedule;
}
}
parseActionSpec(actionSpec) {
if(actionSpec) {
if('@' === actionSpec[0]) {
const m = ACTION_REGEXP.exec(actionSpec);
if(m) {
if(m[2].indexOf(':') > -1) {
const parts = m[2].split(':');
return {
type : m[1],
location : parts[0],
what : parts[1],
};
} else {
return {
type : m[1],
what : m[2],
};
}
}
} else {
return {
type : 'execute',
what : actionSpec,
};
}
}
}
}
function EventSchedulerModule(options) {
PluginModule.call(this, options);
if(_.has(Config, 'eventScheduler')) {
this.moduleConfig = Config.eventScheduler;
}
const self = this;
this.runningActions = new Set();
this.performAction = function(schedEvent) {
if(self.runningActions.has(schedEvent.name)) {
return; // already running
}
self.runningActions.add(schedEvent.name);
if('method' === schedEvent.action.type) {
const modulePath = path.join(__dirname, '../', schedEvent.action.location); // enigma-bbs base + supplied location (path/file.js')
try {
const methodModule = require(modulePath);
methodModule[schedEvent.action.what](schedEvent.action.args, err => {
if(err) {
Log.debug(
{ error : err.toString(), eventName : schedEvent.name, action : schedEvent.action },
'Error while performing scheduled event action');
}
self.runningActions.delete(schedEvent.name);
});
} catch(e) {
Log.warn(
{ error : e.toString(), eventName : schedEvent.name, action : schedEvent.action },
'Failed to perform scheduled event action');
self.runningActions.delete(schedEvent.name);
}
}
};
}
// convienence static method for direct load + start
EventSchedulerModule.loadAndStart = function(cb) {
const loadModuleEx = require('./module_util.js').loadModuleEx;
const loadOpts = {
name : path.basename(__filename, '.js'),
path : __dirname,
};
loadModuleEx(loadOpts, (err, mod) => {
if(err) {
return cb(err);
}
const modInst = new mod.getModule();
modInst.startup( err => {
return cb(err);
});
});
};
EventSchedulerModule.prototype.startup = function(cb) {
this.eventTimers = [];
const self = this;
if(this.moduleConfig && _.has(this.moduleConfig, 'events')) {
const events = Object.keys(this.moduleConfig.events).map( name => {
return new ScheduledEvent(this.moduleConfig.events, name);
});
events.forEach( schedEvent => {
if(!schedEvent.isValid) {
Log.warn( { eventName : schedEvent.name }, 'Invalid scheduled event entry');
return;
}
if(schedEvent.schedule.sched) {
this.eventTimers.push(later.setInterval( () => {
self.performAction(schedEvent);
}, schedEvent.schedule.sched));
}
// :TODO: handle watchfile -> performAction
});
}
cb(null);
};
EventSchedulerModule.prototype.shutdown = function(cb) {
if(this.eventTimers) {
this.eventTimers.forEach( et => et.clear() );
}
cb(null);
};

View File

@ -132,6 +132,7 @@ function MenuModule(options) {
if(err) { if(err) {
console.log(err) console.log(err)
// :TODO: what to do exactly????? // :TODO: what to do exactly?????
return self.prevMenu();
} }
self.finishedLoading(); self.finishedLoading();

View File

@ -243,7 +243,14 @@ Message.prototype.load = function(options, cb) {
'WHERE message_uuid=? ' + 'WHERE message_uuid=? ' +
'LIMIT 1;', 'LIMIT 1;',
[ options.uuid ], [ options.uuid ],
function row(err, msgRow) { (err, msgRow) => {
if(err) {
return callback(err);
}
if(!msgRow) {
return callback(new Error('Message (no longer) available'));
}
self.messageId = msgRow.message_id; self.messageId = msgRow.message_id;
self.areaTag = msgRow.area_tag; self.areaTag = msgRow.area_tag;
self.messageUuid = msgRow.message_uuid; self.messageUuid = msgRow.message_uuid;

View File

@ -1,16 +1,17 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
let msgDb = require('./database.js').dbs.message; const msgDb = require('./database.js').dbs.message;
let Config = require('./config.js').config; const Config = require('./config.js').config;
let Message = require('./message.js'); const Message = require('./message.js');
let Log = require('./logger.js').log; const Log = require('./logger.js').log;
let checkAcs = require('./acs_util.js').checkAcs; const checkAcs = require('./acs_util.js').checkAcs;
let msgNetRecord = require('./msg_network.js').recordMessage; const msgNetRecord = require('./msg_network.js').recordMessage;
let async = require('async'); const async = require('async');
let _ = require('lodash'); const _ = require('lodash');
let assert = require('assert'); const assert = require('assert');
const moment = require('moment');
exports.getAvailableMessageConferences = getAvailableMessageConferences; exports.getAvailableMessageConferences = getAvailableMessageConferences;
exports.getSortedAvailMessageConferences = getSortedAvailMessageConferences; exports.getSortedAvailMessageConferences = getSortedAvailMessageConferences;
@ -27,6 +28,7 @@ exports.getNewMessagesInAreaForUser = getNewMessagesInAreaForUser;
exports.getMessageAreaLastReadId = getMessageAreaLastReadId; exports.getMessageAreaLastReadId = getMessageAreaLastReadId;
exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId; exports.updateMessageAreaLastReadId = updateMessageAreaLastReadId;
exports.persistMessage = persistMessage; exports.persistMessage = persistMessage;
exports.trimMessageAreasScheduledEvent = trimMessageAreasScheduledEvent;
const CONF_AREA_RW_ACS_DEFAULT = 'GM[users]'; const CONF_AREA_RW_ACS_DEFAULT = 'GM[users]';
const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]'; const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]';
@ -182,7 +184,7 @@ function getMessageAreaByTag(areaTag, optionalConfTag) {
// No confTag to work with - we'll have to search through them all // No confTag to work with - we'll have to search through them all
// //
var area; var area;
_.forEach(confs, (v, k) => { _.forEach(confs, (v) => {
if(_.has(v, [ 'areas', areaTag ])) { if(_.has(v, [ 'areas', areaTag ])) {
area = v.areas[areaTag]; area = v.areas[areaTag];
return false; // stop iteration return false; // stop iteration
@ -464,3 +466,126 @@ function persistMessage(message, cb) {
cb cb
); );
} }
// method exposed for event scheduler
function trimMessageAreasScheduledEvent(args, cb) {
function trimMessageAreaByMaxMessages(areaInfo, cb) {
if(0 === areaInfo.maxMessages) {
return cb(null);
}
msgDb.run(
`DELETE FROM message
WHERE message_id IN
(SELECT message_id
FROM message
WHERE area_tag = ?
ORDER BY message_id
LIMIT (MAX(0, (SELECT COUNT()
FROM message
WHERE area_tag = ?) - ${areaInfo.maxMessages}
))
);`,
[ areaInfo.areaTag, areaInfo.areaTag],
err => {
if(err) {
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxMessages' }, 'Error trimming message area');
} else {
Log.debug( { areaInfo : areaInfo, type : 'maxMessages' }, 'Area trimmed successfully');
}
return cb(err);
}
);
}
function trimMessageAreaByMaxAgeDays(areaInfo, cb) {
if(0 === areaInfo.maxAgeDays) {
return cb(null);
}
msgDb.run(
`DELETE FROM message
WHERE area_tag = ? AND modified_timestamp < date('now', '-${areaInfo.maxAgeDays} days');`,
[ areaInfo.areaTag ],
err => {
if(err) {
Log.warn( { areaInfo : areaInfo, error : err.toString(), type : 'maxAgeDays' }, 'Error trimming message area');
} else {
Log.debug( { areaInfo : areaInfo, type : 'maxAgeDays' }, 'Area trimmed successfully');
}
return cb(err);
}
);
}
async.waterfall(
[
function getAreaTags(callback) {
let areaTags = [];
msgDb.each(
`SELECT DISTINCT area_tag
FROM message;`,
(err, row) => {
if(err) {
return callback(err);
}
areaTags.push(row.area_tag);
},
err => {
return callback(err, areaTags);
}
);
},
function prepareAreaInfo(areaTags, callback) {
let areaInfos = [];
// determine maxMessages & maxAgeDays per area
areaTags.forEach(areaTag => {
let maxMessages = Config.messageAreaDefaults.maxMessages;
let maxAgeDays = Config.messageAreaDefaults.maxAgeDays;
const area = getMessageAreaByTag(areaTag); // note: we don't know the conf here
if(area) {
if(area.maxMessages) {
maxMessages = area.maxMessages;
}
if(area.maxAgeDays) {
maxAgeDays = area.maxAgeDays;
}
}
areaInfos.push( {
areaTag : areaTag,
maxMessages : maxMessages,
maxAgeDays : maxAgeDays,
} );
});
return callback(null, areaInfos);
},
function trimAreas(areaInfos, callback) {
async.each(
areaInfos,
(areaInfo, next) => {
trimMessageAreaByMaxMessages(areaInfo, err => {
if(err) {
return next(err);
}
trimMessageAreaByMaxAgeDays(areaInfo, err => {
return next(err);
});
});
},
callback
);
}
],
err => {
return cb(err);
}
);
}

View File

@ -1140,6 +1140,8 @@ function FTNMessageScanTossModule() {
require('util').inherits(FTNMessageScanTossModule, MessageScanTossModule); require('util').inherits(FTNMessageScanTossModule, MessageScanTossModule);
// :TODO: *scheduled* portion of this stuff should probably use event_scheduler - @immediate would still use record().
FTNMessageScanTossModule.prototype.startup = function(cb) { FTNMessageScanTossModule.prototype.startup = function(cb) {
Log.info(`${exports.moduleInfo.name} Scanner/Tosser starting up`); Log.info(`${exports.moduleInfo.name} Scanner/Tosser starting up`);

View File

@ -165,7 +165,7 @@ function AbracadabraModule(options) {
const doorInstance = new door.Door(self.client, exeInfo); const doorInstance = new door.Door(self.client, exeInfo);
doorInstance.on('finished', () => { doorInstance.once('finished', () => {
self.prevMenu(); self.prevMenu();
}); });

View File

@ -1,18 +1,16 @@
/* jslint node: true */ /* jslint node: true */
'use strict'; 'use strict';
var MenuModule = require('../core/menu_module.js').MenuModule; const MenuModule = require('../core/menu_module.js').MenuModule;
var Log = require('../core/logger.js').log; const resetScreen = require('../core/ansi_term.js').resetScreen;
var resetScreen = require('../core/ansi_term.js').resetScreen;
var async = require('async'); const async = require('async');
var _ = require('lodash'); const _ = require('lodash');
var http = require('http'); const http = require('http');
var net = require('net'); const net = require('net');
var crypto = require('crypto'); const crypto = require('crypto');
var buffers = require('buffers');
var packageJson = require('../package.json'); const packageJson = require('../package.json');
/* /*
Expected configuration block: Expected configuration block:

View File

@ -939,6 +939,10 @@
value: { command: "DL" } value: { command: "DL" }
action: @menu:doorDarkLands action: @menu:doorDarkLands
} }
{
value: { command: "DP" }
action: @menu:doorParty
}
] ]
} }
@ -1006,6 +1010,16 @@
door: tw door: tw
} }
} }
doorParty: {
desc: Using DoorParty!
module: @systemModule:door_party
config: {
username: XXXXXXXX
password: XXXXXXXX
bbsTag: XX
}
}
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
// Message Area Menu // Message Area Menu
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////

View File

@ -133,7 +133,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
callback(0 === self.messageList.length ? new Error('No messages in area') : null); callback(0 === self.messageList.length ? new Error('No messages in area') : null);
} else { } else {
messageArea.getMessageListForArea( { client : self.client }, self.messageAreaTag, function msgs(err, msgList) { messageArea.getMessageListForArea( { client : self.client }, self.messageAreaTag, function msgs(err, msgList) {
if(msgList && 0 === msgList.length) { if(!msgList || 0 === msgList.length) {
callback(new Error('No messages in area')); callback(new Error('No messages in area'));
} else { } else {
self.messageList = msgList; self.messageList = msgList;
@ -210,6 +210,7 @@ MessageListModule.prototype.mciReady = function(mciData, cb) {
function complete(err) { function complete(err) {
if(err) { if(err) {
self.client.log.error( { error : err.toString() }, 'Error loading message list'); self.client.log.error( { error : err.toString() }, 'Error loading message list');
} }
cb(err); cb(err);
} }