mirror of
https://github.com/NuSkooler/enigma-bbs.git
synced 2025-06-06 04:37:12 +02:00
User interrupts & node module ready to rock. ...maybe with bugs?
This commit is contained in:
parent
d9238ee6a5
commit
fe44f2c4d6
9 changed files with 198 additions and 68 deletions
|
@ -19,18 +19,26 @@ module.exports = class UserInterruptQueue
|
|||
this.queue = [];
|
||||
}
|
||||
|
||||
static queueGlobal(interruptItem, connections) {
|
||||
connections.forEach(conn => {
|
||||
conn.interruptQueue.queueItem(interruptItem);
|
||||
static queue(interruptItem, opts) {
|
||||
opts = opts || {};
|
||||
if(!opts.clients) {
|
||||
let omitNodes = [];
|
||||
if(Array.isArray(opts.omit)) {
|
||||
omitNodes = opts.omit;
|
||||
} else if(opts.omit) {
|
||||
omitNodes = [ opts.omit ];
|
||||
}
|
||||
omitNodes = omitNodes.map(n => _.isNumber(n) ? n : n.node);
|
||||
opts.clients = getActiveConnections(true).filter(ac => !omitNodes.includes(ac.node));
|
||||
}
|
||||
if(!Array.isArray(opts.clients)) {
|
||||
opts.clients = [ opts.clients ];
|
||||
}
|
||||
opts.clients.forEach(c => {
|
||||
c.interruptQueue.queueItem(interruptItem);
|
||||
});
|
||||
}
|
||||
|
||||
// common shortcut: queue global, all active clients minus |client|
|
||||
static queueGlobalOtherActive(interruptItem, client) {
|
||||
const otherConnections = getActiveConnections(true).filter(ac => ac.node !== client.node);
|
||||
return UserInterruptQueue.queueGlobal(interruptItem, otherConnections );
|
||||
}
|
||||
|
||||
queueItem(interruptItem) {
|
||||
if(!_.isString(interruptItem.contents) && !_.isString(interruptItem.text)) {
|
||||
return;
|
||||
|
@ -52,12 +60,17 @@ module.exports = class UserInterruptQueue
|
|||
return this.queue.length > 0;
|
||||
}
|
||||
|
||||
displayNext(cb) {
|
||||
displayNext(options, cb) {
|
||||
if(!cb && _.isFunction(options)) {
|
||||
cb = options;
|
||||
options = {};
|
||||
}
|
||||
const interruptItem = this.queue.pop();
|
||||
if(!interruptItem) {
|
||||
return cb(null);
|
||||
}
|
||||
|
||||
Object.assign(interruptItem, options);
|
||||
return interruptItem ? this.displayWithItem(interruptItem, cb) : cb(null);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue