* 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,
|
||||
menuConfig : modData.config,
|
||||
extraArgs : options.extraArgs,
|
||||
client : options.client,
|
||||
client : options.client,
|
||||
});
|
||||
callback(null, moduleInstance);
|
||||
} catch(e) {
|
||||
|
|
|
@ -68,13 +68,6 @@ Message.WellKnownAreaTags = {
|
|||
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 = {
|
||||
LocalToUserID : 'local_to_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_ACS_DEFAULT = {
|
||||
read : CONF_AREA_RW_ACS_DEFAULT,
|
||||
write : CONF_AREA_RW_ACS_DEFAULT,
|
||||
manage : AREA_MANAGE_ACS_DEFAULT,
|
||||
read : CONF_AREA_RW_ACS_DEFAULT,
|
||||
write : CONF_AREA_RW_ACS_DEFAULT,
|
||||
manage : AREA_MANAGE_ACS_DEFAULT,
|
||||
};
|
||||
|
||||
function getAvailableMessageConferences(client, options) {
|
||||
options = options || { includeSystemInternal : false };
|
||||
options = options || { includeSystemInternal : false };
|
||||
|
||||
// perform ACS check per conf & omit system_internal if desired
|
||||
return _.omit(Config.messageConferences, (v, k) => {
|
||||
if(!options.includeSystemInternal && 'system_internal' === k) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT;
|
||||
return !checkAcs(client, readAcs);
|
||||
});
|
||||
return _.omit(Config.messageConferences, (v, k) => {
|
||||
if(!options.includeSystemInternal && 'system_internal' === k) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const readAcs = v.acs || CONF_AREA_RW_ACS_DEFAULT;
|
||||
return !checkAcs(client, readAcs);
|
||||
});
|
||||
}
|
||||
|
||||
function getSortedAvailMessageConferences(client, options) {
|
||||
|
@ -75,19 +75,19 @@ function getAvailableMessageAreasByConfTag(confTag, options) {
|
|||
// :TODO: confTag === "" then find default
|
||||
|
||||
if(_.has(Config.messageConferences, [ confTag, 'areas' ])) {
|
||||
const areas = Config.messageConferences[confTag].areas;
|
||||
const areas = Config.messageConferences[confTag].areas;
|
||||
|
||||
if(!options.client || true === options.noAcsCheck) {
|
||||
// everything - no ACS checks
|
||||
return areas;
|
||||
} else {
|
||||
// perform ACS check per area
|
||||
return _.omit(areas, (v, k) => {
|
||||
const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT;
|
||||
return !checkAcs(options.client, readAcs);
|
||||
});
|
||||
}
|
||||
}
|
||||
if(!options.client || true === options.noAcsCheck) {
|
||||
// everything - no ACS checks
|
||||
return areas;
|
||||
} else {
|
||||
// perform ACS check per area
|
||||
return _.omit(areas, v => {
|
||||
const readAcs = _.has(v, 'acs.read') ? v.acs.read : CONF_AREA_RW_ACS_DEFAULT;
|
||||
return !checkAcs(options.client, readAcs);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
||||
|
@ -95,7 +95,7 @@ function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
|||
return {
|
||||
areaTag : k,
|
||||
area : v,
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
areas.sort((a, b) => {
|
||||
|
@ -322,16 +322,16 @@ function getNewMessagesInAreaForUser(userId, areaTag, cb) {
|
|||
});
|
||||
},
|
||||
function getMessages(lastMessageId, callback) {
|
||||
var sql =
|
||||
'SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count ' +
|
||||
'FROM message ' +
|
||||
'WHERE area_tag ="' + areaTag + '" AND message_id > ' + lastMessageId;
|
||||
let sql =
|
||||
`SELECT message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count
|
||||
FROM message
|
||||
WHERE area_tag = "${areaTag}" AND message_id > ${lastMessageId}`;
|
||||
|
||||
if(Message.WellKnownAreaTags.Private === areaTag) {
|
||||
sql +=
|
||||
' AND message_id in (' +
|
||||
'SELECT message_id from message_meta where meta_category=' + Message.MetaCategories.System +
|
||||
' AND meta_name="' + Message.SystemMetaNames.LocalToUserID + '" and meta_value=' + userId + ')';
|
||||
` AND message_id in (
|
||||
SELECT message_id from message_meta where meta_category ="System"
|
||||
AND meta_name ="${Message.SystemMetaNames.LocalToUserID}" AND meta_value =${userId})`;
|
||||
}
|
||||
|
||||
sql += ' ORDER BY message_id;';
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
'use strict';
|
||||
|
||||
// ENiGMA½
|
||||
let Config = require('./config.js').config;
|
||||
let miscUtil = require('./misc_util.js');
|
||||
const Config = require('./config.js').config;
|
||||
|
||||
// standard/deps
|
||||
let fs = require('fs');
|
||||
let paths = require('path');
|
||||
let _ = require('lodash');
|
||||
let assert = require('assert');
|
||||
let async = require('async');
|
||||
// deps
|
||||
const fs = require('fs');
|
||||
const paths = require('path');
|
||||
const _ = require('lodash');
|
||||
const assert = require('assert');
|
||||
const async = require('async');
|
||||
|
||||
// exports
|
||||
exports.loadModuleEx = loadModuleEx;
|
||||
|
@ -25,25 +24,22 @@ function loadModuleEx(options, cb) {
|
|||
const modConfig = _.isObject(Config[options.category]) ? Config[options.category][options.name] : null;
|
||||
|
||||
if(_.isObject(modConfig) && false === modConfig.enabled) {
|
||||
cb(new Error('Module "' + options.name + '" is disabled'));
|
||||
return;
|
||||
return cb(new Error('Module "' + options.name + '" is disabled'));
|
||||
}
|
||||
|
||||
var mod;
|
||||
try {
|
||||
let mod;
|
||||
try {
|
||||
mod = require(paths.join(options.path, options.name + '.js'));
|
||||
} catch(e) {
|
||||
cb(e);
|
||||
return cb(e);
|
||||
}
|
||||
|
||||
if(!_.isObject(mod.moduleInfo)) {
|
||||
cb(new Error('Module is missing "moduleInfo" section'));
|
||||
return;
|
||||
return cb(new Error('Module is missing "moduleInfo" section'));
|
||||
}
|
||||
|
||||
if(!_.isFunction(mod.getModule)) {
|
||||
cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
return;
|
||||
return cb(new Error('Invalid or missing "getModule" method for module!'));
|
||||
}
|
||||
|
||||
// Ref configuration, if any, for convience to the module
|
||||
|
@ -53,11 +49,10 @@ function loadModuleEx(options, cb) {
|
|||
}
|
||||
|
||||
function loadModule(name, category, cb) {
|
||||
var path = Config.paths[category];
|
||||
const path = Config.paths[category];
|
||||
|
||||
if(!_.isString(path)) {
|
||||
cb(new Error('Not sure where to look for "' + name + '" of category "' + category + '"'));
|
||||
return;
|
||||
return cb(new Error(`Not sure where to look for "${name}" of category "${category}"`));
|
||||
}
|
||||
|
||||
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';
|
||||
|
||||
// ENiGMA½
|
||||
var msgArea = require('./message_area.js');
|
||||
var Message = require('./message.js');
|
||||
var MenuModule = require('./menu_module.js').MenuModule;
|
||||
var ViewController = require('../core/view_controller.js').ViewController;
|
||||
const msgArea = require('./message_area.js');
|
||||
const MenuModule = require('./menu_module.js').MenuModule;
|
||||
const ViewController = require('../core/view_controller.js').ViewController;
|
||||
|
||||
var _ = require('lodash');
|
||||
var async = require('async');
|
||||
// deps
|
||||
const _ = require('lodash');
|
||||
const async = require('async');
|
||||
|
||||
exports.moduleInfo = {
|
||||
name : 'New Scan',
|
||||
|
@ -60,65 +60,74 @@ function NewScanModule(options) {
|
|||
}
|
||||
};
|
||||
|
||||
this.newScanMessageConference = function(cb) {
|
||||
this.newScanMessageConference = function(cb) {
|
||||
// lazy init
|
||||
if(!self.sortedMessageConfs) {
|
||||
const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc.
|
||||
if(!self.sortedMessageConfs) {
|
||||
const getAvailOpts = { includeSystemInternal : true }; // find new private messages, bulletins, etc.
|
||||
|
||||
self.sortedMessageConfs = _.map(msgArea.getAvailableMessageConferences(self.client, getAvailOpts), (v, k) => {
|
||||
return {
|
||||
confTag : k,
|
||||
conf : v,
|
||||
};
|
||||
});
|
||||
return {
|
||||
confTag : k,
|
||||
conf : v,
|
||||
};
|
||||
});
|
||||
|
||||
//
|
||||
// Sort conferences by name, other than 'system_internal' which should
|
||||
// always come first such that we display private mails/etc. before
|
||||
// other conferences & areas
|
||||
//
|
||||
self.sortedMessageConfs.sort((a, b) => {
|
||||
self.sortedMessageConfs.sort((a, b) => {
|
||||
if('system_internal' === a.confTag) {
|
||||
return -1;
|
||||
} else {
|
||||
return a.conf.name.localeCompare(b.conf.name);
|
||||
}
|
||||
});
|
||||
return -1;
|
||||
} else {
|
||||
return a.conf.name.localeCompare(b.conf.name);
|
||||
}
|
||||
});
|
||||
|
||||
self.currentScanAux.conf = self.currentScanAux.conf || 0;
|
||||
self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||
}
|
||||
self.currentScanAux.conf = self.currentScanAux.conf || 0;
|
||||
self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||
}
|
||||
|
||||
const currentConf = self.sortedMessageConfs[self.currentScanAux.conf];
|
||||
const currentConf = self.sortedMessageConfs[self.currentScanAux.conf];
|
||||
|
||||
async.series(
|
||||
[
|
||||
function scanArea(callback) {
|
||||
//self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||
|
||||
self.newScanMessageArea(currentConf, function areaScanComplete(err) {
|
||||
if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) {
|
||||
self.currentScanAux.conf += 1;
|
||||
self.currentScanAux.area = 0;
|
||||
|
||||
self.newScanMessageConference(cb); // recursive to next conf
|
||||
//callback(null);
|
||||
} else {
|
||||
self.updateScanStatus(self.scanCompleteMsg);
|
||||
callback(new Error('No more conferences'));
|
||||
}
|
||||
});
|
||||
}
|
||||
],
|
||||
cb
|
||||
async.series(
|
||||
[
|
||||
function scanArea(callback) {
|
||||
//self.currentScanAux.area = self.currentScanAux.area || 0;
|
||||
|
||||
self.newScanMessageArea(currentConf, () => {
|
||||
if(self.sortedMessageConfs.length > self.currentScanAux.conf + 1) {
|
||||
self.currentScanAux.conf += 1;
|
||||
self.currentScanAux.area = 0;
|
||||
|
||||
self.newScanMessageConference(cb); // recursive to next conf
|
||||
//callback(null);
|
||||
} else {
|
||||
self.updateScanStatus(self.scanCompleteMsg);
|
||||
callback(new Error('No more conferences'));
|
||||
}
|
||||
});
|
||||
}
|
||||
],
|
||||
cb
|
||||
);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
this.newScanMessageArea = function(conf, cb) {
|
||||
// :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];
|
||||
|
||||
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,
|
||||
// we'll goto the list module & show them.
|
||||
|
@ -136,12 +145,7 @@ function NewScanModule(options) {
|
|||
}
|
||||
},
|
||||
function updateStatusScanStarted(callback) {
|
||||
self.updateScanStatus(self.scanStartFmt.format({
|
||||
confName : conf.conf.name,
|
||||
confDesc : conf.conf.desc,
|
||||
areaName : currentArea.area.name,
|
||||
areaDesc : currentArea.area.desc,
|
||||
}));
|
||||
self.updateScanStatus(self.scanStartFmt.format(getFormatObj()));
|
||||
callback(null);
|
||||
},
|
||||
function newScanAreaAndGetMessages(callback) {
|
||||
|
@ -149,26 +153,17 @@ function NewScanModule(options) {
|
|||
self.client.user.userId, currentArea.areaTag, function msgs(err, msgList) {
|
||||
if(!err) {
|
||||
if(0 === msgList.length) {
|
||||
self.updateScanStatus(self.scanFinishNoneFmt.format({
|
||||
confName : conf.conf.name,
|
||||
confDesc : conf.conf.desc,
|
||||
areaName : currentArea.area.name,
|
||||
areaDesc : currentArea.area.desc,
|
||||
}));
|
||||
self.updateScanStatus(self.scanFinishNoneFmt.format(getFormatObj()));
|
||||
} else {
|
||||
self.updateScanStatus(self.scanFinishNewFmt.format({
|
||||
confName : conf.conf.name,
|
||||
confDesc : conf.conf.desc,
|
||||
areaName : currentArea.area.name,
|
||||
count : msgList.length,
|
||||
}));
|
||||
const formatObj = Object.assign(getFormatObj(), { count : msgList.length } );
|
||||
self.updateScanStatus(self.scanFinishNewFmt.format(formatObj));
|
||||
}
|
||||
}
|
||||
callback(err, msgList);
|
||||
}
|
||||
);
|
||||
},
|
||||
function displayMessageList(msgList, callback) {
|
||||
function displayMessageList(msgList) {
|
||||
if(msgList && msgList.length > 0) {
|
||||
var nextModuleOpts = {
|
||||
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);
|
||||
},
|
||||
function loadFromConfig(callback) {
|
||||
var loadOpts = {
|
||||
const loadOpts = {
|
||||
callingMenu : self,
|
||||
mciMap : mciData.menu,
|
||||
noInput : true,
|
||||
|
@ -227,13 +222,12 @@ NewScanModule.prototype.mciReady = function(mciData, cb) {
|
|||
function performCurrentStepScan(callback) {
|
||||
switch(self.currentStep) {
|
||||
case 'messageConferences' :
|
||||
self.newScanMessageConference(function scanComplete(err) {
|
||||
callback(null); // finished
|
||||
});
|
||||
break;
|
||||
self.newScanMessageConference( () => {
|
||||
callback(null); // finished
|
||||
});
|
||||
break;
|
||||
|
||||
default :
|
||||
callback(null);
|
||||
default : return callback(null);
|
||||
}
|
||||
}
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue