mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
feat: new ACP config for max length of remote chat messages, #13174
This commit is contained in:
@@ -67,6 +67,7 @@
|
|||||||
"maximumAboutMeLength": 1000,
|
"maximumAboutMeLength": 1000,
|
||||||
"maximumUsersInChatRoom": 0,
|
"maximumUsersInChatRoom": 0,
|
||||||
"maximumChatMessageLength": 1000,
|
"maximumChatMessageLength": 1000,
|
||||||
|
"maximumRemoteChatMessageLength": 5000,
|
||||||
"maximumChatRoomNameLength": 50,
|
"maximumChatRoomNameLength": 50,
|
||||||
"maximumProfileImageSize": 256,
|
"maximumProfileImageSize": 256,
|
||||||
"maximumCoverImageSize": 2048,
|
"maximumCoverImageSize": 2048,
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
"disable-editing": "Disable chat message editing/deletion",
|
"disable-editing": "Disable chat message editing/deletion",
|
||||||
"disable-editing-help": "Administrators and global moderators are exempt from this restriction",
|
"disable-editing-help": "Administrators and global moderators are exempt from this restriction",
|
||||||
"max-length": "Maximum length of chat messages",
|
"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-chat-room-name-length": "Maximum length of chat room names",
|
||||||
"max-room-size": "Maximum number of users in chat rooms",
|
"max-room-size": "Maximum number of users in chat rooms",
|
||||||
"delay": "Time between chat messages (ms)",
|
"delay": "Time between chat messages (ms)",
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ const meta = require('../meta');
|
|||||||
const plugins = require('../plugins');
|
const plugins = require('../plugins');
|
||||||
const db = require('../database');
|
const db = require('../database');
|
||||||
const user = require('../user');
|
const user = require('../user');
|
||||||
|
const utils = require('../utils');
|
||||||
|
|
||||||
module.exports = function (Messaging) {
|
module.exports = function (Messaging) {
|
||||||
Messaging.sendMessage = async (data) => {
|
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);
|
const inRoom = await Messaging.isUserInRoom(data.uid, data.roomId);
|
||||||
if (!inRoom) {
|
if (!inRoom) {
|
||||||
throw new Error('[[error:not-allowed]]');
|
throw new Error('[[error:not-allowed]]');
|
||||||
@@ -18,20 +19,20 @@ module.exports = function (Messaging) {
|
|||||||
return await Messaging.addMessage(data);
|
return await Messaging.addMessage(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
Messaging.checkContent = async (content) => {
|
Messaging.checkContent = async (content, local = true) => {
|
||||||
if (!content) {
|
if (!content) {
|
||||||
throw new Error('[[error:invalid-chat-message]]');
|
throw new Error('[[error:invalid-chat-message]]');
|
||||||
}
|
}
|
||||||
|
|
||||||
const maximumChatMessageLength = meta.config.maximumChatMessageLength || 1000;
|
const maximum = meta.config[local ? 'maximumChatMessageLength' : 'maximumRemoteChatMessageLength'];
|
||||||
content = String(content).trim();
|
content = String(content).trim();
|
||||||
let { length } = content;
|
let { length } = content;
|
||||||
({ content, length } = await plugins.hooks.fire('filter:messaging.checkContent', { content, length }));
|
({ content, length } = await plugins.hooks.fire('filter:messaging.checkContent', { content, length }));
|
||||||
if (!content) {
|
if (!content) {
|
||||||
throw new Error('[[error:invalid-chat-message]]');
|
throw new Error('[[error:invalid-chat-message]]');
|
||||||
}
|
}
|
||||||
if (length > maximumChatMessageLength) {
|
if (length > maximum) {
|
||||||
throw new Error(`[[error:chat-message-too-long, ${maximumChatMessageLength}]]`);
|
throw new Error(`[[error:chat-message-too-long, ${maximum}]]`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,12 @@
|
|||||||
<input id="maximumChatMessageLength" type="text" class="form-control" value="1000" data-field="maximumChatMessageLength">
|
<input id="maximumChatMessageLength" type="text" class="form-control" value="1000" data-field="maximumChatMessageLength">
|
||||||
</div>
|
</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">
|
<div class="mb-3">
|
||||||
<label class="form-label" for="maximumUsersInChatRoom">[[admin/settings/chat:max-room-size]]</label>
|
<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">
|
<input id="maximumUsersInChatRoom" type="text" class="form-control" value="0" data-field="maximumUsersInChatRoom">
|
||||||
|
|||||||
Reference in New Issue
Block a user