* Fix bug causing private mail to be skipped during new scan
* Some code cleanup: spaces -> indents * Resolve TODO removing Message.MetaCategories: Just use string names * Misc ES5 -> ES6 * Fix bug in module loader when require() fails * Some DRY in new_scan.js
This commit is contained in:
parent
51e4dccbfe
commit
f0919b5227
|
@ -97,7 +97,7 @@ function loadMenu(options, cb) {
|
||||||
menuName : options.name,
|
menuName : options.name,
|
||||||
menuConfig : modData.config,
|
menuConfig : modData.config,
|
||||||
extraArgs : options.extraArgs,
|
extraArgs : options.extraArgs,
|
||||||
client : options.client,
|
client : options.client,
|
||||||
});
|
});
|
||||||
callback(null, moduleInstance);
|
callback(null, moduleInstance);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
|
|
@ -68,13 +68,6 @@ Message.WellKnownAreaTags = {
|
||||||
Bulletin : 'local_bulletin',
|
Bulletin : 'local_bulletin',
|
||||||
};
|
};
|
||||||
|
|
||||||
// :TODO: FTN stuff really doesn't belong here - move it elsewhere and/or just use the names directly when needed
|
|
||||||
Message.MetaCategories = {
|
|
||||||
System : 1, // ENiGMA1/2 stuff
|
|
||||||
FtnProperty : 2, // Various FTN network properties, ftn_cost, ftn_origin, ...
|
|
||||||
FtnKludge : 3, // FTN kludges -- PATH, MSGID, ...
|
|
||||||
};
|
|
||||||
|
|
||||||
Message.SystemMetaNames = {
|
Message.SystemMetaNames = {
|
||||||
LocalToUserID : 'local_to_user_id',
|
LocalToUserID : 'local_to_user_id',
|
||||||
LocalFromUserID : 'local_from_user_id',
|
LocalFromUserID : 'local_from_user_id',
|
||||||
|
|
|
@ -32,23 +32,23 @@ const CONF_AREA_RW_ACS_DEFAULT = 'GM[users]';
|
||||||
const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]';
|
const AREA_MANAGE_ACS_DEFAULT = 'GM[sysops]';
|
||||||
|
|
||||||
const AREA_ACS_DEFAULT = {
|
const AREA_ACS_DEFAULT = {
|
||||||
read : CONF_AREA_RW_ACS_DEFAULT,
|
read : CONF_AREA_RW_ACS_DEFAULT,
|
||||||
write : CONF_AREA_RW_ACS_DEFAULT,
|
write : CONF_AREA_RW_ACS_DEFAULT,
|
||||||
manage : AREA_MANAGE_ACS_DEFAULT,
|
manage : AREA_MANAGE_ACS_DEFAULT,
|
||||||
};
|
};
|
||||||
|
|
||||||
function getAvailableMessageConferences(client, options) {
|
function getAvailableMessageConferences(client, options) {
|
||||||
options = options || { includeSystemInternal : false };
|
options = options || { includeSystemInternal : false };
|
||||||
|
|
||||||
// perform ACS check per conf & omit system_internal if desired
|
// perform ACS check per conf & omit system_internal if desired
|
||||||
return _.omit(Config.messageConferences, (v, k) => {
|
return _.omit(Config.messageConferences, (v, k) => {
|
||||||
if(!options.includeSystemInternal && 'system_internal' === k) {
|
if(!options.includeSystemInternal && 'system_internal' === k) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT;
|
const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT;
|
||||||
return !checkAcs(client, readAcs);
|
return !checkAcs(client, readAcs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSortedAvailMessageConferences(client, options) {
|
function getSortedAvailMessageConferences(client, options) {
|
||||||
|
@ -75,19 +75,19 @@ function getAvailableMessageAreasByConfTag(confTag, options) {
|
||||||
// :TODO: confTag === "" then find default
|
// :TODO: confTag === "" then find default
|
||||||
|
|
||||||
if(_.has(Config.messageConferences, [ confTag, 'areas' ])) {
|
if(_.has(Config.messageConferences, [ confTag, 'areas' ])) {
|
||||||
const areas = Config.messageConferences[confTag].areas;
|
const areas = Config.messageConferences[confTag].areas;
|
||||||
|
|
||||||
if(!options.client || true === options.noAcsCheck) {
|
if(!options.client || true === options.noAcsCheck) {
|
||||||
// everything - no ACS checks
|
// everything - no ACS checks
|
||||||
return areas;
|
return areas;
|
||||||
} else {
|
} else {
|
||||||
// perform ACS check per area
|
// perform ACS check per area
|
||||||
return _.omit(areas, (v, k) => {
|
return _.omit(areas, v => {
|
||||||
const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT;
|
const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT;
|
||||||
return !checkAcs(options.client, readAcs);
|
return !checkAcs(options.client, readAcs);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
||||||
|
@ -95,7 +95,7 @@ function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
||||||
return {
|
return {
|
||||||
areaTag : k,
|
areaTag : k,
|
||||||
area : v,
|
area : v,
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
areas.sort((a, b) => {
|
areas.sort((a, b) => {
|
||||||
|
@ -322,16 +322,16 @@ function getNewMessagesInAreaForUser(userId, areaTag, cb) {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function getMessages(lastMessageId, callback) {
|
function getMessages(lastMessageId, callback) {
|
||||||
var sql =
|
let sql =
|
||||||
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count ' +
|
`SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count
|
||||||
'FROM message ' +
|
FROM message
|
||||||
'WHERE area_tag ="' + areaTag + '" AND message_id > ' + lastMessageId;
|
WHERE area_tag = "${areaTag}" AND message_id > ${lastMessageId}`;
|
||||||
|
|
||||||
if(Message.WellKnownAreaTags.Private === areaTag) {
|
if(Message.WellKnownAreaTags.Private === areaTag) {
|
||||||
sql +=
|
sql +=
|
||||||
' AND message_id in (' +
|
` AND message_id in (
|
||||||
'SELECT message_id from message_meta where meta_category=' + Message.MetaCategories.System +
|
SELECT message_id from message_meta where meta_category ="System"
|
||||||
' AND meta_name="' + Message.SystemMetaNames.LocalToUserID + '" and meta_value=' + userId + ')';
|
AND meta_name ="${Message.SystemMetaNames.LocalToUserID}" AND meta_value =${userId})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
sql += ' ORDER BY message_id;';
|
sql += ' ORDER BY message_id;';
|
||||||
|
|
|
@ -2,15 +2,14 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
let Config = require('./config.js').config;
|
const Config = require('./config.js').config;
|
||||||
let miscUtil = require('./misc_util.js');
|
|
||||||
|
|
||||||
// standard/deps
|
// deps
|
||||||
let fs = require('fs');
|
const fs = require('fs');
|
||||||
let paths = require('path');
|
const paths = require('path');
|
||||||
let _ = require('lodash');
|
const _ = require('lodash');
|
||||||
let assert = require('assert');
|
const assert = require('assert');
|
||||||
let async = require('async');
|
const async = require('async');
|
||||||
|
|
||||||
// exports
|
// exports
|
||||||
exports.loadModuleEx = loadModuleEx;
|
exports.loadModuleEx = loadModuleEx;
|
||||||
|
@ -25,25 +24,22 @@ function loadModuleEx(options, cb) {
|
||||||
const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
|
const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
|
||||||
|
|
||||||
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
||||||
cb(new Error('Module "' + options.name + '" is disabled'));
|
return cb(new Error('Module "' + options.name + '" is disabled'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var mod;
|
let mod;
|
||||||
try {
|
try {
|
||||||
mod = require(paths.join(options.path, options.name + '.js'));
|
mod = require(paths.join(options.path, options.name + '.js'));
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
cb(e);
|
return cb(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_.isObject(mod.moduleInfo)) {
|
if(!_.isObject(mod.moduleInfo)) {
|
||||||
cb(new Error('Module is missing "moduleInfo" section'));
|
return cb(new Error('Module is missing "moduleInfo" section'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_.isFunction(mod.getModule)) {
|
if(!_.isFunction(mod.getModule)) {
|
||||||
cb(new Error('Invalid or missing "getModule" method for module!'));
|
return cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ref configuration, if any, for convience to the module
|
// Ref configuration, if any, for convience to the module
|
||||||
|
@ -53,11 +49,10 @@ function loadModuleEx(options, cb) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadModule(name, category, cb) {
|
function loadModule(name, category, cb) {
|
||||||
var path = Config.paths[category];
|
const path = Config.paths[category];
|
||||||
|
|
||||||
if(!_.isString(path)) {
|
if(!_.isString(path)) {
|
||||||
cb(new Error('Not sure where to look for "' + name + '" of category "' + category + '"'));
|
return cb(new Error(`Not sure where to look for "${name}" of category "${category}"`));
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) {
|
loadModuleEx( { name : name, path : path, category : category }, function loaded(err, mod) {
|
||||||
|
|
142
core/new_scan.js
142
core/new_scan.js
|
@ -2,13 +2,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
// ENiGMA½
|
// ENiGMA½
|
||||||
var msgArea = require('./message_area.js');
|
const msgArea = require('./message_area.js');
|
||||||
var Message = require('./message.js');
|
const MenuModule = require('./menu_module.js').MenuModule;
|
||||||
var MenuModule = require('./menu_module.js').MenuModule;
|
const ViewController = require('../core/view_controller.js').ViewController;
|
||||||
var ViewController = require('../core/view_controller.js').ViewController;
|
|
||||||
|
|
||||||
var _ = require('lodash');
|
// deps
|
||||||
var async = require('async');
|
const _ = require('lodash');
|
||||||
|
const async = require('async');
|
||||||
|
|
||||||
exports.moduleInfo = {
|
exports.moduleInfo = {
|
||||||
name : 'New Scan',
|
name : 'New Scan',
|
||||||
|
@ -60,65 +60,74 @@ function NewScanModule(options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.newScanMessageConference = function(cb) {
|
this.newScanMessageConference = function(cb) {
|
||||||
// lazy init
|
// lazy init
|
||||||
if(!self.sortedMessageConfs) {
|
if(!self.sortedMessageConfs) {
|
||||||
const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc.
|
const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc.
|
||||||
|
|
||||||
self.sortedMessageConfs = _.map(msgArea.getAvailableMessageConferences(self.client, getAvailOpts), (v, k) => {
|
self.sortedMessageConfs = _.map(msgArea.getAvailableMessageConferences(self.client, getAvailOpts), (v, k) => {
|
||||||
return {
|
return {
|
||||||
confTag : k,
|
confTag : k,
|
||||||
conf : v,
|
conf : v,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
//
|
//
|
||||||
// Sort conferences by name, other than 'system_internal' which should
|
// Sort conferences by name, other than 'system_internal' which should
|
||||||
// always come first such that we display private mails/etc. before
|
// always come first such that we display private mails/etc. before
|
||||||
// other conferences & areas
|
// other conferences & areas
|
||||||
//
|
//
|
||||||
self.sortedMessageConfs.sort((a, b) => {
|
self.sortedMessageConfs.sort((a, b) => {
|
||||||
if('system_internal' === a.confTag) {
|
if('system_internal' === a.confTag) {
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
return a.conf.name.localeCompare(b.conf.name);
|
return a.conf.name.localeCompare(b.conf.name);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
self.currentScanAux.conf = self.currentScanAux.conf || 0;
|
self.currentScanAux.conf = self.currentScanAux.conf || 0;
|
||||||
self.currentScanAux.area = self.currentScanAux.area || 0;
|
self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentConf = self.sortedMessageConfs[self.currentScanAux.conf];
|
const currentConf = self.sortedMessageConfs[self.currentScanAux.conf];
|
||||||
|
|
||||||
async.series(
|
async.series(
|
||||||
[
|
[
|
||||||
function scanArea(callback) {
|
function scanArea(callback) {
|
||||||
//self.currentScanAux.area = self.currentScanAux.area || 0;
|
//self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||||
|
|
||||||
self.newScanMessageArea(currentConf, function areaScanComplete(err) {
|
self.newScanMessageArea(currentConf, () => {
|
||||||
if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) {
|
if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) {
|
||||||
self.currentScanAux.conf += 1;
|
self.currentScanAux.conf += 1;
|
||||||
self.currentScanAux.area = 0;
|
self.currentScanAux.area = 0;
|
||||||
|
|
||||||
self.newScanMessageConference(cb); // recursive to next conf
|
self.newScanMessageConference(cb); // recursive to next conf
|
||||||
//callback(null);
|
//callback(null);
|
||||||
} else {
|
} else {
|
||||||
self.updateScanStatus(self.scanCompleteMsg);
|
self.updateScanStatus(self.scanCompleteMsg);
|
||||||
callback(new Error('No more conferences'));
|
callback(new Error('No more conferences'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
cb
|
cb
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.newScanMessageArea = function(conf, cb) {
|
this.newScanMessageArea = function(conf, cb) {
|
||||||
// :TODO: it would be nice to cache this - must be done by conf!
|
// :TODO: it would be nice to cache this - must be done by conf!
|
||||||
const sortedAreas = msgArea.getSortedAvailMessageAreasByConfTag(conf.confTag, { client : self.client } );
|
const sortedAreas = msgArea.getSortedAvailMessageAreasByConfTag(conf.confTag, { client : self.client } );
|
||||||
const currentArea = sortedAreas[self.currentScanAux.area];
|
const currentArea = sortedAreas[self.currentScanAux.area];
|
||||||
|
|
||||||
|
function getFormatObj() {
|
||||||
|
return {
|
||||||
|
confName : conf.conf.name,
|
||||||
|
confDesc : conf.conf.desc,
|
||||||
|
areaName : currentArea.area.name,
|
||||||
|
areaDesc : currentArea.area.desc
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Scan and update index until we find something. If results are found,
|
// Scan and update index until we find something. If results are found,
|
||||||
// we'll goto the list module & show them.
|
// we'll goto the list module & show them.
|
||||||
|
@ -136,12 +145,7 @@ function NewScanModule(options) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
function updateStatusScanStarted(callback) {
|
function updateStatusScanStarted(callback) {
|
||||||
self.updateScanStatus(self.scanStartFmt.format({
|
self.updateScanStatus(self.scanStartFmt.format(getFormatObj()));
|
||||||
confName : conf.conf.name,
|
|
||||||
confDesc : conf.conf.desc,
|
|
||||||
areaName : currentArea.area.name,
|
|
||||||
areaDesc : currentArea.area.desc,
|
|
||||||
}));
|
|
||||||
callback(null);
|
callback(null);
|
||||||
},
|
},
|
||||||
function newScanAreaAndGetMessages(callback) {
|
function newScanAreaAndGetMessages(callback) {
|
||||||
|
@ -149,26 +153,17 @@ function NewScanModule(options) {
|
||||||
self.client.user.userId, currentArea.areaTag, function msgs(err, msgList) {
|
self.client.user.userId, currentArea.areaTag, function msgs(err, msgList) {
|
||||||
if(!err) {
|
if(!err) {
|
||||||
if(0 === msgList.length) {
|
if(0 === msgList.length) {
|
||||||
self.updateScanStatus(self.scanFinishNoneFmt.format({
|
self.updateScanStatus(self.scanFinishNoneFmt.format(getFormatObj()));
|
||||||
confName : conf.conf.name,
|
|
||||||
confDesc : conf.conf.desc,
|
|
||||||
areaName : currentArea.area.name,
|
|
||||||
areaDesc : currentArea.area.desc,
|
|
||||||
}));
|
|
||||||
} else {
|
} else {
|
||||||
self.updateScanStatus(self.scanFinishNewFmt.format({
|
const formatObj = Object.assign(getFormatObj(), { count : msgList.length } );
|
||||||
confName : conf.conf.name,
|
self.updateScanStatus(self.scanFinishNewFmt.format(formatObj));
|
||||||
confDesc : conf.conf.desc,
|
|
||||||
areaName : currentArea.area.name,
|
|
||||||
count : msgList.length,
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback(err, msgList);
|
callback(err, msgList);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
function displayMessageList(msgList, callback) {
|
function displayMessageList(msgList) {
|
||||||
if(msgList && msgList.length > 0) {
|
if(msgList && msgList.length > 0) {
|
||||||
var nextModuleOpts = {
|
var nextModuleOpts = {
|
||||||
extraArgs: {
|
extraArgs: {
|
||||||
|
@ -183,7 +178,7 @@ function NewScanModule(options) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
cb
|
cb // no more areas
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -216,7 +211,7 @@ NewScanModule.prototype.mciReady = function(mciData, cb) {
|
||||||
NewScanModule.super_.prototype.mciReady.call(self, mciData, callback);
|
NewScanModule.super_.prototype.mciReady.call(self, mciData, callback);
|
||||||
},
|
},
|
||||||
function loadFromConfig(callback) {
|
function loadFromConfig(callback) {
|
||||||
var loadOpts = {
|
const loadOpts = {
|
||||||
callingMenu : self,
|
callingMenu : self,
|
||||||
mciMap : mciData.menu,
|
mciMap : mciData.menu,
|
||||||
noInput : true,
|
noInput : true,
|
||||||
|
@ -227,13 +222,12 @@ NewScanModule.prototype.mciReady = function(mciData, cb) {
|
||||||
function performCurrentStepScan(callback) {
|
function performCurrentStepScan(callback) {
|
||||||
switch(self.currentStep) {
|
switch(self.currentStep) {
|
||||||
case 'messageConferences' :
|
case 'messageConferences' :
|
||||||
self.newScanMessageConference(function scanComplete(err) {
|
self.newScanMessageConference( () => {
|
||||||
callback(null); // finished
|
callback(null); // finished
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default :
|
default : return callback(null);
|
||||||
callback(null);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|
Loading…
Reference in New Issue