This commit is contained in:
Calvin Montgomery 2017-03-01 20:46:01 -08:00
parent a80512aa60
commit d4db459ff9
3 changed files with 13 additions and 15 deletions

View File

@ -2,7 +2,7 @@
"author": "Calvin Montgomery",
"name": "CyTube",
"description": "Online media synchronizer and chat",
"version": "3.29.0",
"version": "3.30.0",
"repository": {
"url": "http://github.com/calzoneman/sync"
},

View File

@ -91,10 +91,8 @@ function Channel(name) {
var self = this;
db.channels.load(this, function (err) {
if (err && err !== "Channel is not registered") {
self.emit("loadFail", "Failed to load channel data from the database");
// Force channel to be unloaded, so that it will load properly when
// the database connection comes back
self.emit("empty");
self.emit("loadFail", "Failed to load channel data from the database. Please try again later.");
self.setFlag(Flags.C_ERROR);
return;
} else {
self.initModules();
@ -197,14 +195,11 @@ Channel.prototype.loadState = function () {
}
const self = this;
function errorLoad(msg) {
if (self.modules.customization) {
self.modules.customization.load({
motd: msg
});
}
self.setFlag(Flags.C_READY | Flags.C_ERROR);
function errorLoad(msg, suggestTryAgain = true) {
const extra = suggestTryAgain ? " Please try again later." : "";
self.emit("loadFail", "Failed to load channel data from the database: " +
msg + extra);
self.setFlag(Flags.C_ERROR);
}
ChannelStore.load(this.id, this.uniqueName).then(data => {
@ -224,7 +219,7 @@ Channel.prototype.loadState = function () {
"for assistance.";
Logger.errlog.log(err.stack);
errorLoad(message);
errorLoad(message, false);
}).catch(err => {
if (err.code === 'ENOENT') {
Object.keys(this.modules).forEach(m => {
@ -235,7 +230,7 @@ Channel.prototype.loadState = function () {
} else {
const message = "An error occurred when loading this channel's data from " +
"disk. Please contact an administrator for assistance. " +
`The error was: ${err}`;
`The error was: ${err}.`;
Logger.errlog.log(err.stack);
errorLoad(message);

View File

@ -216,6 +216,9 @@ Server.prototype.getChannel = function (name) {
c.on("empty", function () {
self.unloadChannel(c);
});
c.waitFlag(Flags.C_ERROR, () => {
self.unloadChannel(c, { skipSave: true });
});
self.channels.push(c);
return c;
};