feat: new ACP config for max length of remote chat messages, #13174

This commit is contained in:
Julian Lam
2025-03-07 15:04:18 -05:00
parent 44354dac5e
commit 81509b13f3
4 changed files with 15 additions and 5 deletions

View File

@@ -67,6 +67,7 @@
"maximumAboutMeLength": 1000,
"maximumUsersInChatRoom": 0,
"maximumChatMessageLength": 1000,
"maximumRemoteChatMessageLength": 5000,
"maximumChatRoomNameLength": 50,
"maximumProfileImageSize": 256,
"maximumCoverImageSize": 2048,

View File

@@ -5,6 +5,8 @@
"disable-editing": "Disable chat message editing/deletion",
"disable-editing-help": "Administrators and global moderators are exempt from this restriction",
"max-length": "Maximum length of chat messages",
"max-length-remote": "Maximum length of remote chat messages",
"max-length-remote-help": "This value is usually set higher than the chat message maximum for local users as remote messages tend to be longer (with @ mentions, etc.)",
"max-chat-room-name-length": "Maximum length of chat room names",
"max-room-size": "Maximum number of users in chat rooms",
"delay": "Time between chat messages (ms)",

View File

@@ -6,10 +6,11 @@ const meta = require('../meta');
const plugins = require('../plugins');
const db = require('../database');
const user = require('../user');
const utils = require('../utils');
module.exports = function (Messaging) {
Messaging.sendMessage = async (data) => {
await Messaging.checkContent(data.content);
await Messaging.checkContent(data.content, utils.isNumber(data.uid));
const inRoom = await Messaging.isUserInRoom(data.uid, data.roomId);
if (!inRoom) {
throw new Error('[[error:not-allowed]]');
@@ -18,20 +19,20 @@ module.exports = function (Messaging) {
return await Messaging.addMessage(data);
};
Messaging.checkContent = async (content) => {
Messaging.checkContent = async (content, local = true) => {
if (!content) {
throw new Error('[[error:invalid-chat-message]]');
}
const maximumChatMessageLength = meta.config.maximumChatMessageLength || 1000;
const maximum = meta.config[local ? 'maximumChatMessageLength' : 'maximumRemoteChatMessageLength'];
content = String(content).trim();
let { length } = content;
({ content, length } = await plugins.hooks.fire('filter:messaging.checkContent', { content, length }));
if (!content) {
throw new Error('[[error:invalid-chat-message]]');
}
if (length > maximumChatMessageLength) {
throw new Error(`[[error:chat-message-too-long, ${maximumChatMessageLength}]]`);
if (length > maximum) {
throw new Error(`[[error:chat-message-too-long, ${maximum}]]`);
}
};

View File

@@ -44,6 +44,12 @@
<input id="maximumChatMessageLength" type="text" class="form-control" value="1000" data-field="maximumChatMessageLength">
</div>
<div class="mb-3">
<label class="form-label" for="maximumRemoteChatMessageLength">[[admin/settings/chat:max-length-remote]]</label>
<input id="maximumRemoteChatMessageLength" type="text" class="form-control" value="5000" data-field="maximumRemoteChatMessageLength">
<p class="form-text">[[admin/settings/chat:max-length-remote-help]]</p>
</div>
<div class="mb-3">
<label class="form-label" for="maximumUsersInChatRoom">[[admin/settings/chat:max-room-size]]</label>
<input id="maximumUsersInChatRoom" type="text" class="form-control" value="0" data-field="maximumUsersInChatRoom">