More filtering of messages results without ACS
+ filterMessageListByReadACS() * Use filterMessageListByReadACS() in my messages * Use filterMessageListByReadACS() in message search
This commit is contained in:
parent
36afcc0298
commit
afd6d4265f
|
@ -33,6 +33,7 @@ exports.changeMessageConference = changeMessageConference;
|
|||
exports.changeMessageArea = changeMessageArea;
|
||||
exports.hasMessageConfAndAreaRead = hasMessageConfAndAreaRead;
|
||||
exports.filterMessageAreaTagsByReadACS = filterMessageAreaTagsByReadACS;
|
||||
exports.filterMessageListByReadACS = filterMessageListByReadACS;
|
||||
exports.tempChangeMessageConfAndArea = tempChangeMessageConfAndArea;
|
||||
exports.getMessageListForArea = getMessageListForArea;
|
||||
exports.getNewMessageCountInAreaForUser = getNewMessageCountInAreaForUser;
|
||||
|
@ -420,6 +421,29 @@ function filterMessageAreaTagsByReadACS(client, areaTags) {
|
|||
});
|
||||
}
|
||||
|
||||
function filterMessageListByReadACS(client, messageList) {
|
||||
//
|
||||
// Filter out messages belonging to conf/areas the user
|
||||
// doesn't have access to.
|
||||
//
|
||||
|
||||
// Keep a cache around for quick lookup.
|
||||
const acsCache = new Map(); // areaTag:boolean
|
||||
|
||||
return messageList.filter(msg => {
|
||||
let cached = acsCache.get(msg.areaTag);
|
||||
if(false === cached) {
|
||||
return false;
|
||||
}
|
||||
if(true === cached) {
|
||||
return true;
|
||||
}
|
||||
cached = hasMessageConfAndAreaRead(client, msg.areaTag);
|
||||
acsCache.set(msg.areaTag, cached);
|
||||
return cached;
|
||||
});
|
||||
}
|
||||
|
||||
function getNewMessageCountInAreaForUser(userId, areaTag, cb) {
|
||||
getMessageAreaLastReadId(userId, areaTag, (err, lastMessageId) => {
|
||||
lastMessageId = lastMessageId || 0;
|
||||
|
|
|
@ -7,6 +7,8 @@ const {
|
|||
getSortedAvailMessageConferences,
|
||||
getAvailableMessageAreasByConfTag,
|
||||
getSortedAvailMessageAreasByConfTag,
|
||||
hasMessageConfAndAreaRead,
|
||||
filterMessageListByReadACS,
|
||||
} = require('./message_area.js');
|
||||
const Errors = require('./enig_error.js').Errors;
|
||||
const Message = require('./message.js');
|
||||
|
@ -101,6 +103,14 @@ exports.getModule = class MessageBaseSearch extends MenuModule {
|
|||
limit : 2048, // :TODO: best way to handle this? we should probably let the user know if some results are returned
|
||||
};
|
||||
|
||||
const returnNoResults = () => {
|
||||
return this.gotoMenu(
|
||||
this.menuConfig.config.noResultsMenu || 'messageSearchNoResults',
|
||||
{ menuFlags : [ 'popParent' ] },
|
||||
cb
|
||||
);
|
||||
};
|
||||
|
||||
if(isAdvanced) {
|
||||
filter.toUserName = value.toUserName;
|
||||
filter.fromUserName = value.fromUserName;
|
||||
|
@ -113,7 +123,11 @@ exports.getModule = class MessageBaseSearch extends MenuModule {
|
|||
(area, areaTag) => areaTag
|
||||
);
|
||||
} else if(value.areaTag) {
|
||||
filter.areaTag = value.areaTag; // specific conf + area
|
||||
if(hasMessageConfAndAreaRead(this.client, value.areaTag)) {
|
||||
filter.areaTag = value.areaTag; // specific conf + area
|
||||
} else {
|
||||
return returnNoResults();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,12 +136,14 @@ exports.getModule = class MessageBaseSearch extends MenuModule {
|
|||
return cb(err);
|
||||
}
|
||||
|
||||
// don't include results without ACS -- if the user searched by
|
||||
// explicit conf/area tag, we should have already filtered (above)
|
||||
if(!value.confTag && !value.areaTag) {
|
||||
messageList = filterMessageListByReadACS(this.client, messageList);
|
||||
}
|
||||
|
||||
if(0 === messageList.length) {
|
||||
return this.gotoMenu(
|
||||
this.menuConfig.config.noResultsMenu || 'messageSearchNoResults',
|
||||
{ menuFlags : [ 'popParent' ] },
|
||||
cb
|
||||
);
|
||||
return returnNoResults();
|
||||
}
|
||||
|
||||
const menuOpts = {
|
||||
|
|
|
@ -6,7 +6,7 @@ const MenuModule = require('./menu_module.js').MenuModule;
|
|||
const Message = require('./message.js');
|
||||
const UserProps = require('./user_property.js');
|
||||
const {
|
||||
hasMessageConfAndAreaRead
|
||||
filterMessageListByReadACS
|
||||
} = require('./message_area.js');
|
||||
|
||||
exports.moduleInfo = {
|
||||
|
@ -34,25 +34,8 @@ exports.getModule = class MyMessagesModule extends MenuModule {
|
|||
return this.prevMenu();
|
||||
}
|
||||
|
||||
//
|
||||
// We need to filter out messages belonging to conf/areas the user
|
||||
// doesn't have access to.
|
||||
//
|
||||
// Keep a cache around for quick lookup.
|
||||
//
|
||||
const acsCache = new Map(); // areaTag:boolean
|
||||
this.messageList = messageList.filter(msg => {
|
||||
let cached = acsCache.get(msg.areaTag);
|
||||
if(false === cached) {
|
||||
return false;
|
||||
}
|
||||
if(true === cached) {
|
||||
return true;
|
||||
}
|
||||
cached = hasMessageConfAndAreaRead(this.client, msg.areaTag);
|
||||
acsCache.set(msg.areaTag, cached);
|
||||
return cached;
|
||||
});
|
||||
// don't include results without ACS
|
||||
this.messageList = filterMessageListByReadACS(this.client, messageList);
|
||||
|
||||
this.finishedLoading();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue