From 487d9f73205502397a6feb80f71903fdd99e5699 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Sun, 26 Jan 2025 10:57:22 -0500 Subject: [PATCH] fix: #13086 move rateLimit check so it doesn't get triggered if there were errors --- src/api/chats.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/api/chats.js b/src/api/chats.js index 703fae2606..e1538c4426 100644 --- a/src/api/chats.js +++ b/src/api/chats.js @@ -109,9 +109,6 @@ chatsAPI.sortPublicRooms = async (caller, { roomIds, scores }) => { chatsAPI.get = async (caller, { uid, roomId }) => await messaging.loadRoom(caller.uid, { uid, roomId }); chatsAPI.post = async (caller, data) => { - if (await rateLimitExceeded(caller, 'lastChatMessageTime')) { - throw new Error('[[error:too-many-messages]]'); - } if (!data || !data.roomId || !caller.uid) { throw new Error('[[error:invalid-data]]'); } @@ -122,7 +119,13 @@ chatsAPI.post = async (caller, data) => { })); await messaging.canMessageRoom(caller.uid, data.roomId); - const message = await messaging.sendMessage({ + await messaging.checkContent(data.message); + + if (await rateLimitExceeded(caller, 'lastChatMessageTime')) { + throw new Error('[[error:too-many-messages]]'); + } + + const message = await messaging.addMessage({ uid: caller.uid, roomId: data.roomId, content: data.message,