enigma-bbs/core/whos_online.js

82 lines
2.4 KiB
JavaScript
Raw Normal View History

2015-11-26 01:00:13 +00:00
/* jslint node: true */
'use strict';
// ENiGMA½
const { MenuModule } = require('./menu_module.js');
const {
getActiveConnectionList,
UserVisibleConnections,
} = require('./client_connections.js');
const { Errors } = require('./enig_error.js');
2015-11-26 01:00:13 +00:00
// deps
const async = require('async');
const _ = require('lodash');
2015-11-26 01:00:13 +00:00
exports.moduleInfo = {
name: "Who's Online",
desc: 'Who is currently online',
author: 'NuSkooler',
packageName: 'codes.l33t.enigma.whosonline',
2015-11-26 01:00:13 +00:00
};
const MciViewIds = {
onlineList: 1,
2015-11-26 01:00:13 +00:00
};
exports.getModule = class WhosOnlineModule extends MenuModule {
constructor(options) {
super(options);
}
2015-11-26 01:00:13 +00:00
mciReady(mciData, cb) {
super.mciReady(mciData, err => {
if (err) {
return cb(err);
}
2015-11-26 01:00:13 +00:00
async.series(
[
next => {
return this.prepViewController('online', 0, mciData.menu, next);
},
next => {
const onlineListView = this.viewControllers.online.getView(
MciViewIds.onlineList
);
if (!onlineListView) {
return cb(
Errors.MissingMci(
`Missing online list MCI ${MciViewIds.onlineList}`
)
);
}
const onlineList = getActiveConnectionList(UserVisibleConnections)
.slice(0, onlineListView.height)
.map(oe =>
Object.assign(oe, {
text: oe.userName,
timeOn: _.upperFirst(oe.timeOn.humanize()),
})
);
2015-11-26 01:00:13 +00:00
onlineListView.setItems(onlineList);
onlineListView.redraw();
return next(null);
},
],
err => {
if (err) {
this.client.log.error(
{ error: err.message },
"Error loading who's online"
);
}
return cb(err);
}
);
});
}
2015-11-26 01:00:13 +00:00
};