mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-22 18:56:00 +02:00
* 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
5 changed files with 116 additions and 134 deletions
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…
Add table
Add a link
Reference in a new issue