enigma-bbs/core/my_messages.js

70 lines
2.0 KiB
JavaScript
Raw Normal View History

2019-02-16 04:55:18 +00:00
/* jslint node: true */
'use strict';
// ENiGMA½
const MenuModule = require('./menu_module.js').MenuModule;
const Message = require('./message.js');
const UserProps = require('./user_property.js');
const { filterMessageListByReadACS } = require('./message_area.js');
2019-02-16 04:55:18 +00:00
exports.moduleInfo = {
name: 'My Messages',
desc: 'Finds messages addressed to the current user.',
author: 'NuSkooler',
2019-02-16 04:55:18 +00:00
};
exports.getModule = class MyMessagesModule extends MenuModule {
constructor(options) {
super(options);
}
initSequence() {
const filter = {
toUserName: [
this.client.user.username,
this.client.user.getProperty(UserProps.RealName),
],
sort: 'modTimestamp',
resultType: 'messageList',
limit: 1024 * 16, // we want some sort of limit...
2019-02-16 04:55:18 +00:00
};
Message.findMessages(filter, (err, messageList) => {
if (err) {
this.client.log.warn(
{ error: err.message },
'Error finding messages addressed to current user'
);
2019-02-16 04:55:18 +00:00
return this.prevMenu();
}
// don't include results without ACS
this.messageList = filterMessageListByReadACS(this.client, messageList);
2019-02-16 04:55:18 +00:00
this.finishedLoading();
});
}
finishedLoading() {
if (!this.messageList || 0 === this.messageList.length) {
2019-02-16 04:55:18 +00:00
return this.gotoMenu(
this.menuConfig.config.noResultsMenu || 'messageSearchNoResults',
{ menuFlags: ['popParent'] }
2019-02-16 04:55:18 +00:00
);
}
const menuOpts = {
extraArgs: {
messageList: this.messageList,
noUpdateLastReadId: true,
2019-02-16 04:55:18 +00:00
},
menuFlags: ['popParent'],
2019-02-16 04:55:18 +00:00
};
return this.gotoMenu(
this.menuConfig.config.messageListMenu || 'messageAreaMessageList',
menuOpts
);
}
};