diff --git a/core/my_messages.js b/core/my_messages.js index 721e1f9d..65a9335d 100644 --- a/core/my_messages.js +++ b/core/my_messages.js @@ -5,6 +5,9 @@ const MenuModule = require('./menu_module.js').MenuModule; const Message = require('./message.js'); const UserProps = require('./user_property.js'); +const { + hasMessageConfAndAreaRead +} = require('./message_area.js'); exports.moduleInfo = { name : 'My Messages', @@ -30,7 +33,27 @@ exports.getModule = class MyMessagesModule extends MenuModule { this.client.log.warn( { error : err.message }, 'Error finding messages addressed to current user'); return this.prevMenu(); } - this.messageList = messageList; + + // + // 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; + }); + this.finishedLoading(); }); }