mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-07-22 10:45:56 +02:00
* Code cleanup and eslint since -- remove unused variables, clean up RegExs, so on...
This commit is contained in:
parent
a106050ba3
commit
ac1433e84b
112 changed files with 1375 additions and 1898 deletions
|
@ -40,9 +40,9 @@ function getAvailableMessageConferences(client, options) {
|
|||
options = options || { includeSystemInternal : false };
|
||||
|
||||
assert(client || true === options.noClient);
|
||||
|
||||
// perform ACS check per conf & omit system_internal if desired
|
||||
return _.omitBy(Config.messageConferences, (conf, confTag) => {
|
||||
|
||||
// perform ACS check per conf & omit system_internal if desired
|
||||
return _.omitBy(Config.messageConferences, (conf, confTag) => {
|
||||
if(!options.includeSystemInternal && 'system_internal' === confTag) {
|
||||
return true;
|
||||
}
|
||||
|
@ -60,15 +60,15 @@ function getSortedAvailMessageConferences(client, options) {
|
|||
});
|
||||
|
||||
sortAreasOrConfs(confs, 'conf');
|
||||
|
||||
|
||||
return confs;
|
||||
}
|
||||
|
||||
// Return an *object* of available areas within |confTag|
|
||||
function getAvailableMessageAreasByConfTag(confTag, options) {
|
||||
options = options || {};
|
||||
|
||||
// :TODO: confTag === "" then find default
|
||||
|
||||
// :TODO: confTag === "" then find default
|
||||
|
||||
if(_.has(Config.messageConferences, [ confTag, 'areas' ])) {
|
||||
const areas = Config.messageConferences[confTag].areas;
|
||||
|
@ -92,9 +92,9 @@ function getSortedAvailMessageAreasByConfTag(confTag, options) {
|
|||
area : v,
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
sortAreasOrConfs(areas, 'area');
|
||||
|
||||
|
||||
return areas;
|
||||
}
|
||||
|
||||
|
@ -103,7 +103,7 @@ function getDefaultMessageConferenceTag(client, disableAcsCheck) {
|
|||
// Find the first conference marked 'default'. If found,
|
||||
// inspect |client| against *read* ACS using defaults if not
|
||||
// specified.
|
||||
//
|
||||
//
|
||||
// If the above fails, just go down the list until we get one
|
||||
// that passes.
|
||||
//
|
||||
|
@ -116,14 +116,14 @@ function getDefaultMessageConferenceTag(client, disableAcsCheck) {
|
|||
const conf = Config.messageConferences[defaultConf];
|
||||
if(true === disableAcsCheck || client.acs.hasMessageConfRead(conf)) {
|
||||
return defaultConf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// just use anything we can
|
||||
defaultConf = _.findKey(Config.messageConferences, (conf, confTag) => {
|
||||
return 'system_internal' !== confTag && (true === disableAcsCheck || client.acs.hasMessageConfRead(conf));
|
||||
});
|
||||
|
||||
|
||||
return defaultConf;
|
||||
}
|
||||
|
||||
|
@ -138,19 +138,19 @@ function getDefaultMessageAreaTagByConfTag(client, confTag, disableAcsCheck) {
|
|||
confTag = confTag || getDefaultMessageConferenceTag(client);
|
||||
|
||||
if(confTag && _.has(Config.messageConferences, [ confTag, 'areas' ])) {
|
||||
const areaPool = Config.messageConferences[confTag].areas;
|
||||
const areaPool = Config.messageConferences[confTag].areas;
|
||||
let defaultArea = _.findKey(areaPool, o => o.default);
|
||||
if(defaultArea) {
|
||||
const area = areaPool[defaultArea];
|
||||
if(true === disableAcsCheck || client.acs.hasMessageAreaRead(area)) {
|
||||
return defaultArea;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
defaultArea = _.findKey(areaPool, (area) => {
|
||||
return (true === disableAcsCheck || client.acs.hasMessageAreaRead(area));
|
||||
return (true === disableAcsCheck || client.acs.hasMessageAreaRead(area));
|
||||
});
|
||||
|
||||
|
||||
return defaultArea;
|
||||
}
|
||||
}
|
||||
|
@ -159,18 +159,6 @@ function getMessageConferenceByTag(confTag) {
|
|||
return Config.messageConferences[confTag];
|
||||
}
|
||||
|
||||
function getMessageConfByAreaTag(areaTag) {
|
||||
const confs = Config.messageConferences;
|
||||
let conf;
|
||||
_.forEach(confs, (v) => {
|
||||
if(_.has(v, [ 'areas', areaTag ])) {
|
||||
conf = v;
|
||||
return false; // stop iteration
|
||||
}
|
||||
});
|
||||
return conf;
|
||||
}
|
||||
|
||||
function getMessageConfTagByAreaTag(areaTag) {
|
||||
const confs = Config.messageConferences;
|
||||
return Object.keys(confs).find( (confTag) => {
|
||||
|
@ -194,9 +182,9 @@ function getMessageAreaByTag(areaTag, optionalConfTag) {
|
|||
if(_.has(v, [ 'areas', areaTag ])) {
|
||||
area = v.areas[areaTag];
|
||||
return false; // stop iteration
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return area;
|
||||
}
|
||||
}
|
||||
|
@ -206,7 +194,7 @@ function changeMessageConference(client, confTag, cb) {
|
|||
[
|
||||
function getConf(callback) {
|
||||
const conf = getMessageConferenceByTag(confTag);
|
||||
|
||||
|
||||
if(conf) {
|
||||
callback(null, conf);
|
||||
} else {
|
||||
|
@ -216,7 +204,7 @@ function changeMessageConference(client, confTag, cb) {
|
|||
function getDefaultAreaInConf(conf, callback) {
|
||||
const areaTag = getDefaultMessageAreaTagByConfTag(client, confTag);
|
||||
const area = getMessageAreaByTag(areaTag, confTag);
|
||||
|
||||
|
||||
if(area) {
|
||||
callback(null, conf, { areaTag : areaTag, area : area } );
|
||||
} else {
|
||||
|
@ -229,7 +217,7 @@ function changeMessageConference(client, confTag, cb) {
|
|||
} else {
|
||||
return callback(null, conf, areaInfo);
|
||||
}
|
||||
},
|
||||
},
|
||||
function changeConferenceAndArea(conf, areaInfo, callback) {
|
||||
const newProps = {
|
||||
message_conf_tag : confTag,
|
||||
|
@ -258,12 +246,12 @@ function changeMessageAreaWithOptions(client, areaTag, options, cb) {
|
|||
[
|
||||
function getArea(callback) {
|
||||
const area = getMessageAreaByTag(areaTag);
|
||||
return callback(area ? null : new Error('Invalid message areaTag'), area);
|
||||
return callback(area ? null : new Error('Invalid message areaTag'), area);
|
||||
},
|
||||
function validateAccess(area, callback) {
|
||||
//
|
||||
// Need at least *read* to access the area
|
||||
//
|
||||
//
|
||||
// Need at least *read* to access the area
|
||||
//
|
||||
if(!client.acs.hasMessageAreaRead(area)) {
|
||||
return callback(new Error('Access denied to message area'));
|
||||
} else {
|
||||
|
@ -294,7 +282,7 @@ function changeMessageAreaWithOptions(client, areaTag, options, cb) {
|
|||
}
|
||||
|
||||
//
|
||||
// Temporairly -- e.g. non-persisted -- change to an area and it's
|
||||
// Temporairly -- e.g. non-persisted -- change to an area and it's
|
||||
// associated underlying conference. ACS is checked for both.
|
||||
//
|
||||
// This is useful for example when doing a new scan
|
||||
|
@ -312,7 +300,7 @@ function tempChangeMessageConfAndArea(client, areaTag) {
|
|||
if(!client.acs.hasMessageConfRead(conf) || !client.acs.hasMessageAreaRead(area)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
client.user.properties.message_conf_tag = confTag;
|
||||
client.user.properties.message_area_tag = areaTag;
|
||||
|
||||
|
@ -324,7 +312,7 @@ function changeMessageArea(client, areaTag, cb) {
|
|||
}
|
||||
|
||||
function getMessageFromRow(row) {
|
||||
return {
|
||||
return {
|
||||
messageId : row.message_id,
|
||||
messageUuid : row.message_uuid,
|
||||
replyToMsgId : row.reply_to_message_id,
|
||||
|
@ -346,8 +334,8 @@ function getNewMessageDataInAreaForUserSql(userId, areaTag, lastMessageId, what)
|
|||
//
|
||||
// * Only messages > |lastMessageId| should be returned/counted
|
||||
//
|
||||
const selectWhat = ('count' === what) ?
|
||||
'COUNT() AS count' :
|
||||
const selectWhat = ('count' === what) ?
|
||||
'COUNT() AS count' :
|
||||
'message_id, message_uuid, reply_to_message_id, to_user_name, from_user_name, subject, modified_timestamp, view_count';
|
||||
|
||||
let sql =
|
||||
|
@ -386,7 +374,7 @@ function getNewMessageCountInAreaForUser(userId, areaTag, cb) {
|
|||
msgDb.get(sql, (err, row) => {
|
||||
return callback(err, row ? row.count : 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
],
|
||||
cb
|
||||
);
|
||||
|
@ -421,7 +409,7 @@ function getNewMessagesInAreaForUser(userId, areaTag, cb) {
|
|||
function complete(err) {
|
||||
cb(err, msgList);
|
||||
}
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
function getMessageListForArea(options, areaTag, cb) {
|
||||
|
@ -435,7 +423,7 @@ function getMessageListForArea(options, areaTag, cb) {
|
|||
|
||||
/*
|
||||
[
|
||||
{
|
||||
{
|
||||
messageId, messageUuid, replyToId, toUserName, fromUserName, subject, modTimestamp,
|
||||
status(new|old),
|
||||
viewCount
|
||||
|
@ -448,13 +436,13 @@ function getMessageListForArea(options, areaTag, cb) {
|
|||
async.series(
|
||||
[
|
||||
function fetchMessages(callback) {
|
||||
let sql =
|
||||
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 = ?`;
|
||||
|
||||
if(Message.isPrivateAreaTag(areaTag)) {
|
||||
sql +=
|
||||
sql +=
|
||||
` AND message_id IN (
|
||||
SELECT message_id
|
||||
FROM message_meta
|
||||
|
@ -462,7 +450,7 @@ function getMessageListForArea(options, areaTag, cb) {
|
|||
)`;
|
||||
}
|
||||
|
||||
sql += ' ORDER BY message_id;';
|
||||
sql += ' ORDER BY message_id;';
|
||||
|
||||
msgDb.each(
|
||||
sql,
|
||||
|
@ -551,12 +539,12 @@ function updateMessageAreaLastReadId(userId, areaTag, messageId, allowOlder, cb)
|
|||
],
|
||||
function complete(err, didUpdate) {
|
||||
if(err) {
|
||||
Log.debug(
|
||||
{ error : err.toString(), userId : userId, areaTag : areaTag, messageId : messageId },
|
||||
Log.debug(
|
||||
{ error : err.toString(), userId : userId, areaTag : areaTag, messageId : messageId },
|
||||
'Failed updating area last read ID');
|
||||
} else {
|
||||
if(true === didUpdate) {
|
||||
Log.trace(
|
||||
Log.trace(
|
||||
{ userId : userId, areaTag : areaTag, messageId : messageId },
|
||||
'Area last read ID updated');
|
||||
}
|
||||
|
@ -574,7 +562,7 @@ function persistMessage(message, cb) {
|
|||
},
|
||||
function recordToMessageNetworks(callback) {
|
||||
return msgNetRecord(message, callback);
|
||||
}
|
||||
}
|
||||
],
|
||||
cb
|
||||
);
|
||||
|
@ -582,7 +570,7 @@ function persistMessage(message, cb) {
|
|||
|
||||
// method exposed for event scheduler
|
||||
function trimMessageAreasScheduledEvent(args, cb) {
|
||||
|
||||
|
||||
function trimMessageAreaByMaxMessages(areaInfo, cb) {
|
||||
if(0 === areaInfo.maxMessages) {
|
||||
return cb(null);
|
||||
|
@ -605,7 +593,7 @@ function trimMessageAreasScheduledEvent(args, cb) {
|
|||
Log.debug( { areaInfo : areaInfo, type : 'maxMessages', count : this.changes }, 'Area trimmed successfully');
|
||||
}
|
||||
return cb(err);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -690,7 +678,7 @@ function trimMessageAreasScheduledEvent(args, cb) {
|
|||
|
||||
trimMessageAreaByMaxAgeDays(areaInfo, err => {
|
||||
return next(err);
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
callback
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue