2019-02-16 04:55:18 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
2023-08-24 03:04:22 +00:00
|
|
|
const { MenuModule, MenuFlags } = require('./menu_module');
|
2022-06-05 20:04:25 +00:00
|
|
|
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 = {
|
2022-06-05 20:04:25 +00:00
|
|
|
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);
|
2023-08-24 00:06:48 +00:00
|
|
|
this.setMergedFlag(MenuFlags.NoHistory);
|
2019-02-16 04:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initSequence() {
|
|
|
|
const filter = {
|
2022-06-05 20:04:25 +00:00
|
|
|
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) => {
|
2022-06-05 20:04:25 +00:00
|
|
|
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();
|
|
|
|
}
|
2019-09-12 03:56:54 +00:00
|
|
|
|
2019-09-12 04:03:24 +00:00
|
|
|
// don't include results without ACS
|
|
|
|
this.messageList = filterMessageListByReadACS(this.client, messageList);
|
2019-09-12 03:56:54 +00:00
|
|
|
|
2019-02-16 04:55:18 +00:00
|
|
|
this.finishedLoading();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
finishedLoading() {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!this.messageList || 0 === this.messageList.length) {
|
2019-02-16 04:55:18 +00:00
|
|
|
return this.gotoMenu(
|
2023-08-24 03:04:22 +00:00
|
|
|
this.menuConfig.config.noResultsMenu || 'messageSearchNoResults'
|
2019-02-16 04:55:18 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const menuOpts = {
|
2022-06-05 20:04:25 +00:00
|
|
|
extraArgs: {
|
|
|
|
messageList: this.messageList,
|
|
|
|
noUpdateLastReadId: true,
|
2019-02-16 04:55:18 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
return this.gotoMenu(
|
|
|
|
this.menuConfig.config.messageListMenu || 'messageAreaMessageList',
|
|
|
|
menuOpts
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|