Migrate old MOTDs and don't replace \n with <br> after

This commit is contained in:
calzoneman 2015-01-08 20:06:41 -06:00
parent 56d6eb8026
commit 80c4c90bcf
5 changed files with 17 additions and 27 deletions

View file

@ -163,10 +163,7 @@ Channel.prototype.loadState = function () {
var errorLoad = function (msg) { var errorLoad = function (msg) {
if (self.modules.customization) { if (self.modules.customization) {
self.modules.customization.load({ self.modules.customization.load({
motd: { motd: msg
motd: msg,
html: msg
}
}); });
} }

View file

@ -17,10 +17,7 @@ function CustomizationModule(channel) {
ChannelModule.apply(this, arguments); ChannelModule.apply(this, arguments);
this.css = ""; this.css = "";
this.js = ""; this.js = "";
this.motd = { this.motd = "";
motd: "",
html: ""
};
} }
CustomizationModule.prototype = Object.create(ChannelModule.prototype); CustomizationModule.prototype = Object.create(ChannelModule.prototype);
@ -35,12 +32,15 @@ CustomizationModule.prototype.load = function (data) {
} }
if ("motd" in data) { if ("motd" in data) {
this.motd = { if (typeof data.motd === "object" && data.motd.motd) {
motd: data.motd.motd || "" // Old style MOTD, convert to new
}; this.motd = XSS.sanitizeHTML(data.motd.motd).replace(
/\n/g, "<br>\n");
this.motd.motd = XSS.sanitizeHTML(this.motd.motd); } else if (typeof data.motd === "string") {
this.motd.html = this.motd.motd.replace(/\n/g, "<br>"); // The MOTD is filtered before it is saved, however it is also
// re-filtered on load in case the filtering rules change
this.motd = XSS.sanitizeHTML(data.motd);
}
} }
}; };
@ -51,12 +51,7 @@ CustomizationModule.prototype.save = function (data) {
}; };
CustomizationModule.prototype.setMotd = function (motd) { CustomizationModule.prototype.setMotd = function (motd) {
motd = XSS.sanitizeHTML(motd); this.motd = XSS.sanitizeHTML(motd);
var html = motd.replace(/\n/g, "<br>");
this.motd = {
motd: motd,
html: html
};
this.sendMotd(this.channel.users); this.sendMotd(this.channel.users);
}; };

View file

@ -175,11 +175,10 @@ Callbacks = {
} }
}, },
setMotd: function(data) { setMotd: function(motd) {
CHANNEL.motd = data.html; CHANNEL.motd = motd;
CHANNEL.motd_text = data.motd; $("#motd").html(motd);
$("#motd").html(CHANNEL.motd); $("#cs-motdtext").val(motd);
$("#cs-motdtext").val(CHANNEL.motd_text);
if (data.motd != "") { if (data.motd != "") {
$("#motdwrap").show(); $("#motdwrap").show();
$("#motd").show(); $("#motd").show();

View file

@ -19,7 +19,6 @@ var CHANNEL = {
css: "", css: "",
js: "", js: "",
motd: "", motd: "",
motd_text: "",
name: false, name: false,
usercount: 0, usercount: 0,
emotes: [] emotes: []

View file

@ -900,7 +900,7 @@ function handleModPermissions() {
})(); })();
$("#cs-csstext").val(CHANNEL.css); $("#cs-csstext").val(CHANNEL.css);
$("#cs-jstext").val(CHANNEL.js); $("#cs-jstext").val(CHANNEL.js);
$("#cs-motdtext").val(CHANNEL.motd_text); $("#cs-motdtext").val(CHANNEL.motd);
setParentVisible("a[href='#cs-motdeditor']", hasPermission("motdedit")); setParentVisible("a[href='#cs-motdeditor']", hasPermission("motdedit"));
setParentVisible("a[href='#cs-permedit']", CLIENT.rank >= 3); setParentVisible("a[href='#cs-permedit']", CLIENT.rank >= 3);
setParentVisible("a[href='#cs-banlist']", hasPermission("ban")); setParentVisible("a[href='#cs-banlist']", hasPermission("ban"));