diff --git a/src/channel/chat.js b/src/channel/chat.js index 83d252a7..4637cd19 100644 --- a/src/channel/chat.js +++ b/src/channel/chat.js @@ -125,13 +125,12 @@ ChatModule.prototype.restrictNewAccount = function restrictNewAccount(user, data if (user.account.effectiveRank < 2 && this.channel.modules.options) { const firstSeen = user.getFirstSeenTime(); const opts = this.channel.modules.options; - // TODO: configurable times - if (firstSeen > Date.now() - opts.get("new_user_chat_delay")) { + if (firstSeen > Date.now() - opts.get("new_user_chat_delay")*1000) { user.socket.emit("spamFiltered", { reason: "NEW_USER_CHAT" }); return true; - } else if ((firstSeen > Date.now() - opts.get("new_user_chat_link_delay")) + } else if ((firstSeen > Date.now() - opts.get("new_user_chat_link_delay")*1000) && data.msg.match(LINK)) { user.socket.emit("spamFiltered", { reason: "NEW_USER_CHAT_LINK" @@ -201,7 +200,7 @@ ChatModule.prototype.handlePm = function (user, data) { msg: "You must be signed in to send PMs" }); } - + // Restrict new accounts/IPs from chatting and posting links if (this.restrictNewAccount(user, data)) { return; diff --git a/src/channel/opts.js b/src/channel/opts.js index 14b37728..acabee46 100644 --- a/src/channel/opts.js +++ b/src/channel/opts.js @@ -26,8 +26,8 @@ function OptionsModule(channel) { torbanned: false, // Block connections from Tor exit nodes allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f) playlist_max_per_user: 0, // Maximum number of playlist items per user - new_user_chat_delay: 10 * 60 * 1000, // Minimum account/IP age to chat - new_user_chat_link_delay: 60 * 60 * 1000 // Minimum account/IP age to post links + new_user_chat_delay: 10 * 60, // Minimum account/IP age to chat + new_user_chat_link_delay: 60 * 60 // Minimum account/IP age to post links }; } @@ -274,14 +274,14 @@ OptionsModule.prototype.handleSetOptions = function (user, data) { } if ("new_user_chat_delay" in data) { - var delay = parseInt(data.new_user_chat_delay); + var delay = data.new_user_chat_delay; if (!isNaN(delay) && delay >= 0) { this.opts.new_user_chat_delay = delay; } } if ("new_user_chat_link_delay" in data) { - var delay = parseInt(data.new_user_chat_link_delay); + var delay = data.new_user_chat_link_delay; if (!isNaN(delay) && delay >= 0) { this.opts.new_user_chat_link_delay = delay; } diff --git a/www/js/ui.js b/www/js/ui.js index a5410905..2e6b6869 100644 --- a/www/js/ui.js +++ b/www/js/ui.js @@ -636,6 +636,36 @@ $(".cs-textbox").keyup(function () { }, 1000); }); +$(".cs-textbox-timeinput").keyup(function (event) { + var box = $(this); + var key = box.attr("id").replace("cs-", ""); + var value = box.val(); + var lastkey = Date.now(); + box.data("lastkey", lastkey); + + setTimeout(function () { + if (box.data("lastkey") !== lastkey || box.val() !== value) { + return; + } + + $("#cs-textbox-timeinput-validation-error-" + key).remove(); + $(event.target).parent().removeClass("has-error"); + var data = {}; + try { + data[key] = parseTimeout(value); + } catch (error) { + var msg = "Invalid timespan value '" + value + "'. Please use the format " + + "HH:MM:SS or enter a single number for the number of seconds."; + var validationError = $("

").addClass("text-danger").text(msg) + .attr("id", "cs-textbox-timeinput-validation-error-" + key); + validationError.insertAfter(event.target); + $(event.target).parent().addClass("has-error"); + return; + } + socket.emit("setOptions", data); + }, 1000); +}); + $("#cs-chanlog-refresh").click(function () { socket.emit("readChanLog"); }); diff --git a/www/js/util.js b/www/js/util.js index fb721348..cc8d97de 100644 --- a/www/js/util.js +++ b/www/js/util.js @@ -759,18 +759,23 @@ function applyOpts() { } } -function showPollMenu() { - function parseTimeout(t) { - var m; - if (m = t.match(/^(\d+):(\d+)$/)) { - return parseInt(m[1], 10) * 60 + parseInt(m[2], 10); - } else if (m = t.match(/^(\d+)$/)) { - return parseInt(m[1], 10); - } else { - throw new Error("Invalid timeout value '" + t + "'"); - } +function parseTimeout(t) { + var m; + if (m = t.match(/^(\d+):(\d+):(\d+)$/)) { + // HH:MM:SS + return parseInt(m[1], 10) * 3600 + parseInt(m[2], 10) * 60 + parseInt(m[3], 10); + } else if (m = t.match(/^(\d+):(\d+)$/)) { + // MM:SS + return parseInt(m[1], 10) * 60 + parseInt(m[2], 10); + } else if (m = t.match(/^(\d+)$/)) { + // Seconds + return parseInt(m[1], 10); + } else { + throw new Error("Invalid timeout value '" + t + "'"); } +} +function showPollMenu() { $("#pollwrap .poll-menu").remove(); var menu = $("

").addClass("well poll-menu") .prependTo($("#pollwrap")); @@ -930,8 +935,8 @@ function handleModPermissions() { $("#cs-torbanned").prop("checked", CHANNEL.opts.torbanned); $("#cs-allow_ascii_control").prop("checked", CHANNEL.opts.allow_ascii_control); $("#cs-playlist_max_per_user").val(CHANNEL.opts.playlist_max_per_user || 0); - $("#cs-new_user_chat_delay").val(CHANNEL.opts.new_user_chat_delay || 0); - $("#cs-new_user_chat_link_delay").val(CHANNEL.opts.new_user_chat_link_delay || 0); + $("#cs-new_user_chat_delay").val(formatTime(CHANNEL.opts.new_user_chat_delay || 0)); + $("#cs-new_user_chat_link_delay").val(formatTime(CHANNEL.opts.new_user_chat_link_delay || 0)); (function() { if(typeof CHANNEL.opts.maxlength != "number") { $("#cs-maxlength").val("");