From 986207b46bf02d46d53e74bbb64e16e9a87e8d22 Mon Sep 17 00:00:00 2001 From: Kethsar Date: Tue, 21 Mar 2023 17:52:52 -0700 Subject: [PATCH] Add max chat message length config option --- config.template.yaml | 2 ++ src/channel/chat.js | 4 ++-- src/config.js | 1 + src/web/routes/channel.js | 4 +++- templates/channel.pug | 2 +- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/config.template.yaml b/config.template.yaml index baba2a2a..f267b1fc 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -128,6 +128,8 @@ max-channels-per-user: 5 max-accounts-per-ip: 5 # Minimum number of seconds between guest logins from the same IP guest-login-delay: 60 +# Maximum character length of a chat message +max-chat-msg-length: 320 # Allows you to customize the path divider. The /r/ in http://localhost/r/yourchannel # Acceptable characters are a-z A-Z 0-9 _ and - diff --git a/src/channel/chat.js b/src/channel/chat.js index a6d53ea2..f14162e6 100644 --- a/src/channel/chat.js +++ b/src/channel/chat.js @@ -162,7 +162,7 @@ ChatModule.prototype.handleChatMsg = function (user, data) { return; } - data.msg = data.msg.substring(0, 320); + data.msg = data.msg.substring(0, Config.get("max-chat-msg-length")); // Restrict new accounts/IPs from chatting and posting links if (this.restrictNewAccount(user, data)) { @@ -248,7 +248,7 @@ ChatModule.prototype.handlePm = function (user, data) { } - data.msg = data.msg.substring(0, 320); + data.msg = data.msg.substring(0, Config.get("max-chat-msg-length")); var to = null; for (var i = 0; i < this.channel.users.length; i++) { if (this.channel.users[i].getLowerName() === data.to) { diff --git a/src/config.js b/src/config.js index adb1133f..7e4705aa 100644 --- a/src/config.js +++ b/src/config.js @@ -71,6 +71,7 @@ var defaults = { "max-channels-per-user": 5, "max-accounts-per-ip": 5, "guest-login-delay": 60, + "max-chat-msg-length": 320, aliases: { "purge-interval": 3600000, "max-age": 2592000000 diff --git a/src/web/routes/channel.js b/src/web/routes/channel.js index 6f55f0b2..4f24a91d 100644 --- a/src/web/routes/channel.js +++ b/src/web/routes/channel.js @@ -1,4 +1,5 @@ import CyTubeUtil from '../../utilities'; +import Config from '../../config'; import { sanitizeText } from '../../xss'; import { sendPug } from '../pug'; import * as HTTPStatus from '../httpstatus'; @@ -27,7 +28,8 @@ export default function initialize(app, ioConfig, chanPath, getBannedChannel) { sendPug(res, 'channel', { channelName: req.params.channel, - sioSource: `${socketBaseURL}/socket.io/socket.io.js` + sioSource: `${socketBaseURL}/socket.io/socket.io.js`, + maxMsgLen: Config.get("max-chat-msg-length") }); }); } diff --git a/templates/channel.pug b/templates/channel.pug index 855dbe5b..dc030cb0 100644 --- a/templates/channel.pug +++ b/templates/channel.pug @@ -46,7 +46,7 @@ html(lang="en") #userlist #messagebuffer.linewrap form(action="javascript:void(0)") - input#chatline.form-control(type="text", maxlength="320", style="display: none") + input#chatline.form-control(type="text", maxlength=`${maxMsgLen}`, style="display: none") #guestlogin.input-group span.input-group-addon Guest login input#guestname.form-control(type="text", placeholder="Name")