Move channel register/delete reload logic to message bus
This commit is contained in:
parent
d16cfb7328
commit
791a712a68
|
|
@ -2,7 +2,7 @@
|
||||||
"author": "Calvin Montgomery",
|
"author": "Calvin Montgomery",
|
||||||
"name": "CyTube",
|
"name": "CyTube",
|
||||||
"description": "Online media synchronizer and chat",
|
"description": "Online media synchronizer and chat",
|
||||||
"version": "3.47.0",
|
"version": "3.47.1",
|
||||||
"repository": {
|
"repository": {
|
||||||
"url": "http://github.com/calzoneman/sync"
|
"url": "http://github.com/calzoneman/sync"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,8 @@ var Server = function () {
|
||||||
|
|
||||||
const globalMessageBus = this.initModule.getGlobalMessageBus();
|
const globalMessageBus = this.initModule.getGlobalMessageBus();
|
||||||
globalMessageBus.on('UserProfileChanged', this.handleUserProfileChange.bind(this));
|
globalMessageBus.on('UserProfileChanged', this.handleUserProfileChange.bind(this));
|
||||||
|
globalMessageBus.on('ChannelDeleted', this.handleChannelDelete.bind(this));
|
||||||
|
globalMessageBus.on('ChannelRegistered', this.handleChannelRegister.bind(this));
|
||||||
|
|
||||||
// database init ------------------------------------------------------
|
// database init ------------------------------------------------------
|
||||||
var Database = require("./database");
|
var Database = require("./database");
|
||||||
|
|
@ -428,3 +430,57 @@ Server.prototype.handleUserProfileChange = function (event) {
|
||||||
LOGGER.error('handleUserProfileChange failed: %s', error);
|
LOGGER.error('handleUserProfileChange failed: %s', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Server.prototype.handleChannelDelete = function (event) {
|
||||||
|
try {
|
||||||
|
const lname = event.channel.toLowerCase();
|
||||||
|
|
||||||
|
this.channels.forEach(channel => {
|
||||||
|
if (channel.dead) return;
|
||||||
|
|
||||||
|
if (channel.uniqueName === lname) {
|
||||||
|
channel.clearFlag(Flags.C_REGISTERED);
|
||||||
|
|
||||||
|
const users = Array.prototype.slice.call(channel.users);
|
||||||
|
users.forEach(u => {
|
||||||
|
u.kick('Channel deleted');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!channel.dead) {
|
||||||
|
channel.emit('empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info('Processed deleted channel %s', lname);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
LOGGER.error('handleChannelDelete failed: %s', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Server.prototype.handleChannelRegister = function (event) {
|
||||||
|
try {
|
||||||
|
const lname = event.channel.toLowerCase();
|
||||||
|
|
||||||
|
this.channels.forEach(channel => {
|
||||||
|
if (channel.dead) return;
|
||||||
|
|
||||||
|
if (channel.uniqueName === lname) {
|
||||||
|
channel.clearFlag(Flags.C_REGISTERED);
|
||||||
|
|
||||||
|
const users = Array.prototype.slice.call(channel.users);
|
||||||
|
users.forEach(u => {
|
||||||
|
u.kick('Channel reloading');
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!channel.dead) {
|
||||||
|
channel.emit('empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
LOGGER.info('Processed registered channel %s', lname);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
LOGGER.error('handleChannelRegister failed: %s', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -268,18 +268,10 @@ async function handleNewChannel(req, res) {
|
||||||
Logger.eventlog.log("[channel] " + user.name + "@" +
|
Logger.eventlog.log("[channel] " + user.name + "@" +
|
||||||
req.realIP +
|
req.realIP +
|
||||||
" registered channel " + name);
|
" registered channel " + name);
|
||||||
var sv = Server.getServer();
|
globalMessageBus.emit('ChannelRegistered', {
|
||||||
if (sv.isChannelLoaded(name)) {
|
channel: name
|
||||||
var chan = sv.getChannel(name);
|
|
||||||
var users = Array.prototype.slice.call(chan.users);
|
|
||||||
users.forEach(function (u) {
|
|
||||||
u.kick("Channel reloading");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!chan.dead) {
|
|
||||||
chan.emit("empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
channels.push({
|
channels.push({
|
||||||
name: name
|
name: name
|
||||||
});
|
});
|
||||||
|
|
@ -338,19 +330,11 @@ async function handleDeleteChannel(req, res) {
|
||||||
req.realIP + " deleted channel " +
|
req.realIP + " deleted channel " +
|
||||||
name);
|
name);
|
||||||
}
|
}
|
||||||
var sv = Server.getServer();
|
|
||||||
if (sv.isChannelLoaded(name)) {
|
globalMessageBus.emit('ChannelDeleted', {
|
||||||
var chan = sv.getChannel(name);
|
channel: name
|
||||||
chan.clearFlag(require("../flags").C_REGISTERED);
|
|
||||||
var users = Array.prototype.slice.call(chan.users);
|
|
||||||
users.forEach(function (u) {
|
|
||||||
u.kick("Channel reloading");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!chan.dead) {
|
|
||||||
chan.emit("empty");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
db.channels.listUserChannels(user.name, function (err2, channels) {
|
db.channels.listUserChannels(user.name, function (err2, channels) {
|
||||||
sendPug(res, "account-channels", {
|
sendPug(res, "account-channels", {
|
||||||
channels: err2 ? [] : channels,
|
channels: err2 ? [] : channels,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue