mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-18 03:31:03 +01:00
feat: introduce new ACP setting for newbie chat message delay, defaults to 2 minutes
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
"chatEditDuration": 0,
|
||||
"chatDeleteDuration": 0,
|
||||
"chatMessageDelay": 2000,
|
||||
"newbieChatMessageDelay": 120000,
|
||||
"notificationSendDelay": 60,
|
||||
"newbiePostDelayThreshold": 3,
|
||||
"postQueue": 0,
|
||||
|
||||
@@ -7,7 +7,8 @@
|
||||
"max-length": "Maximum length of chat messages",
|
||||
"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 in milliseconds",
|
||||
"delay": "Time between chat messages (ms)",
|
||||
"newbieDelay": "... for new users (ms)",
|
||||
"notification-delay": "Notification delay for chat messages",
|
||||
"notification-delay-help": "Additional messages sent between this time are collated, and the user is notified once per delay period. Set this to 0 to disable the delay.",
|
||||
"restrictions.seconds-edit-after": "Number of seconds a chat message will remain editable.",
|
||||
|
||||
@@ -14,11 +14,17 @@ const socketHelpers = require('../socket.io/helpers');
|
||||
|
||||
const chatsAPI = module.exports;
|
||||
|
||||
function rateLimitExceeded(caller) {
|
||||
async function rateLimitExceeded(caller) {
|
||||
const session = caller.request ? caller.request.session : caller.session; // socket vs req
|
||||
const now = Date.now();
|
||||
const [isAdmin, reputation] = await Promise.all([
|
||||
user.isAdministrator(caller.uid),
|
||||
user.getUserField(caller.uid, 'reputation'),
|
||||
]);
|
||||
const newbie = !isAdmin && meta.config.newbiePostDelayThreshold > reputation;
|
||||
const delay = newbie ? meta.config.newbieChatMessageDelay : meta.config.chatMessageDelay;
|
||||
session.lastChatMessageTime = session.lastChatMessageTime || 0;
|
||||
if (now - session.lastChatMessageTime < meta.config.chatMessageDelay) {
|
||||
if (now - session.lastChatMessageTime < delay) {
|
||||
return true;
|
||||
}
|
||||
session.lastChatMessageTime = now;
|
||||
@@ -34,7 +40,7 @@ chatsAPI.list = async (caller, { page, perPage }) => {
|
||||
};
|
||||
|
||||
chatsAPI.create = async function (caller, data) {
|
||||
if (rateLimitExceeded(caller)) {
|
||||
if (await rateLimitExceeded(caller)) {
|
||||
throw new Error('[[error:too-many-messages]]');
|
||||
}
|
||||
if (!data) {
|
||||
@@ -71,7 +77,7 @@ chatsAPI.create = async function (caller, data) {
|
||||
chatsAPI.get = async (caller, { uid, roomId }) => await messaging.loadRoom(caller.uid, { uid, roomId });
|
||||
|
||||
chatsAPI.post = async (caller, data) => {
|
||||
if (rateLimitExceeded(caller)) {
|
||||
if (await rateLimitExceeded(caller)) {
|
||||
throw new Error('[[error:too-many-messages]]');
|
||||
}
|
||||
if (!data || !data.roomId || !caller.uid) {
|
||||
|
||||
@@ -49,11 +49,16 @@
|
||||
<input id="maximumUsersInChatRoom" type="text" class="form-control" value="0" data-field="maximumUsersInChatRoom">
|
||||
</div>
|
||||
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="chatMessageDelay">[[admin/settings/chat:delay]]</label>
|
||||
<input id="chatMessageDelay" type="text" class="form-control" value="200" data-field="chatMessageDelay">
|
||||
</div>
|
||||
<fieldset class="row">
|
||||
<div class="mb-3 col-sm-6">
|
||||
<label class="form-label" for="chatMessageDelay">[[admin/settings/chat:delay]]</label>
|
||||
<input id="chatMessageDelay" type="text" class="form-control" data-field="chatMessageDelay">
|
||||
</div>
|
||||
<div class="mb-3 col-sm-6">
|
||||
<label class="form-label" for="newbieChatMessageDelay">[[admin/settings/chat:newbieDelay]]</label>
|
||||
<input id="newbieChatMessageDelay" type="text" class="form-control" data-field="newbieChatMessageDelay">
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="notificationSendDelay">[[admin/settings/chat:notification-delay]]</label>
|
||||
|
||||
Reference in New Issue
Block a user