2016-02-03 04:35:59 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
2018-06-23 03:26:46 +00:00
|
|
|
// ENiGMA½
|
2023-08-24 00:06:48 +00:00
|
|
|
const { MenuModule, MenuFlags } = require('./menu_module.js');
|
2022-06-05 20:04:25 +00:00
|
|
|
const messageArea = require('./message_area.js');
|
|
|
|
const { Errors } = require('./enig_error.js');
|
2018-06-23 03:26:46 +00:00
|
|
|
|
|
|
|
// deps
|
2022-06-05 20:04:25 +00:00
|
|
|
const async = require('async');
|
|
|
|
const _ = require('lodash');
|
2016-02-03 04:35:59 +00:00
|
|
|
|
|
|
|
exports.moduleInfo = {
|
2022-06-05 20:04:25 +00:00
|
|
|
name: 'Message Conference List',
|
|
|
|
desc: 'Module for listing / choosing message conferences',
|
|
|
|
author: 'NuSkooler',
|
2016-02-03 04:35:59 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
const MciViewIds = {
|
2022-06-05 20:04:25 +00:00
|
|
|
confList: 1,
|
|
|
|
confDesc: 2, // description updated @ index update
|
|
|
|
customRangeStart: 10, // updated @ index update
|
2016-02-03 04:35:59 +00:00
|
|
|
};
|
|
|
|
|
2017-01-26 05:18:05 +00:00
|
|
|
exports.getModule = class MessageConfListModule extends MenuModule {
|
2018-06-22 05:15:04 +00:00
|
|
|
constructor(options) {
|
|
|
|
super(options);
|
|
|
|
|
2023-08-24 00:06:48 +00:00
|
|
|
// always include noHistory flag
|
|
|
|
this.setMergedFlag(MenuFlags.NoHistory);
|
|
|
|
|
2018-07-22 21:59:00 +00:00
|
|
|
this.initList();
|
2018-06-22 05:15:04 +00:00
|
|
|
|
|
|
|
this.menuMethods = {
|
2022-06-05 20:04:25 +00:00
|
|
|
changeConference: (formData, extraArgs, cb) => {
|
|
|
|
if (1 === formData.submitId) {
|
2018-07-22 21:59:00 +00:00
|
|
|
const conf = this.messageConfs[formData.value.conf];
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
messageArea.changeMessageConference(
|
|
|
|
this.client,
|
|
|
|
conf.confTag,
|
|
|
|
err => {
|
|
|
|
if (err) {
|
|
|
|
this.client.term.pipeWrite(
|
|
|
|
`\n|00Cannot change conference: ${err.message}\n`
|
|
|
|
);
|
|
|
|
return this.prevMenuOnTimeout(1000, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (conf.hasArt) {
|
|
|
|
const menuOpts = {
|
|
|
|
extraArgs: {
|
|
|
|
confTag: conf.confTag,
|
|
|
|
},
|
2023-08-24 00:06:48 +00:00
|
|
|
menuFlags: [ MenuFlags.NoHistory ],
|
2022-06-05 20:04:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return this.gotoMenu(
|
|
|
|
this.menuConfig.config.changeConfPreArtMenu ||
|
|
|
|
'changeMessageConfPreArt',
|
|
|
|
menuOpts,
|
|
|
|
cb
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.prevMenu(cb);
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
);
|
2018-06-22 05:15:04 +00:00
|
|
|
} else {
|
|
|
|
return cb(null);
|
|
|
|
}
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
mciReady(mciData, cb) {
|
|
|
|
super.mciReady(mciData, err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
2018-06-22 05:15:04 +00:00
|
|
|
return cb(err);
|
|
|
|
}
|
|
|
|
|
|
|
|
async.series(
|
|
|
|
[
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
2018-07-22 21:59:00 +00:00
|
|
|
return this.prepViewController('confList', 0, mciData.menu, next);
|
2018-06-22 05:15:04 +00:00
|
|
|
},
|
2022-06-05 20:04:25 +00:00
|
|
|
next => {
|
|
|
|
const confListView = this.viewControllers.confList.getView(
|
|
|
|
MciViewIds.confList
|
|
|
|
);
|
|
|
|
if (!confListView) {
|
|
|
|
return next(
|
|
|
|
Errors.MissingMci(
|
|
|
|
`Missing conf list MCI ${MciViewIds.confList}`
|
|
|
|
)
|
|
|
|
);
|
2018-07-22 21:59:00 +00:00
|
|
|
}
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-07-22 21:59:00 +00:00
|
|
|
confListView.on('index update', idx => {
|
|
|
|
this.selectionIndexUpdate(idx);
|
|
|
|
});
|
2018-06-22 05:15:04 +00:00
|
|
|
|
2018-07-22 21:59:00 +00:00
|
|
|
confListView.setItems(this.messageConfs);
|
|
|
|
confListView.redraw();
|
2018-07-23 01:06:43 +00:00
|
|
|
this.selectionIndexUpdate(0);
|
2018-07-22 21:59:00 +00:00
|
|
|
return next(null);
|
2022-06-05 20:04:25 +00:00
|
|
|
},
|
2018-06-22 05:15:04 +00:00
|
|
|
],
|
2018-07-22 21:59:00 +00:00
|
|
|
err => {
|
2022-06-05 20:04:25 +00:00
|
|
|
if (err) {
|
|
|
|
this.client.log.error(
|
|
|
|
{ error: err.message },
|
|
|
|
'Failed loading message conference list'
|
|
|
|
);
|
2018-07-22 21:59:00 +00:00
|
|
|
}
|
2018-06-22 05:15:04 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
2018-07-22 21:59:00 +00:00
|
|
|
|
|
|
|
selectionIndexUpdate(idx) {
|
|
|
|
const conf = this.messageConfs[idx];
|
2022-06-05 20:04:25 +00:00
|
|
|
if (!conf) {
|
2018-07-22 21:59:00 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setViewText('confList', MciViewIds.confDesc, conf.desc);
|
2022-06-05 20:04:25 +00:00
|
|
|
this.updateCustomViewTextsWithFilter(
|
|
|
|
'confList',
|
|
|
|
MciViewIds.customRangeStart,
|
|
|
|
conf
|
|
|
|
);
|
2018-07-22 21:59:00 +00:00
|
|
|
}
|
|
|
|
|
2022-06-05 20:04:25 +00:00
|
|
|
initList() {
|
2018-07-22 21:59:00 +00:00
|
|
|
let index = 1;
|
2022-06-05 20:04:25 +00:00
|
|
|
this.messageConfs = messageArea
|
|
|
|
.getSortedAvailMessageConferences(this.client)
|
|
|
|
.map(conf => {
|
|
|
|
return {
|
|
|
|
index: index++,
|
|
|
|
confTag: conf.confTag,
|
|
|
|
name: conf.conf.name,
|
|
|
|
text: conf.conf.name,
|
|
|
|
desc: conf.conf.desc,
|
|
|
|
areaCount: Object.keys(conf.conf.areas || {}).length,
|
|
|
|
hasArt: _.isString(conf.conf.art),
|
|
|
|
};
|
|
|
|
});
|
2018-07-22 21:59:00 +00:00
|
|
|
}
|
2017-01-26 05:18:05 +00:00
|
|
|
};
|