Skip to content

Commit 487d9f7

Browse files
committed
fix: #13086 move rateLimit check
so it doesn't get triggered if there were errors
1 parent 4caae73 commit 487d9f7

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/api/chats.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,6 @@ chatsAPI.sortPublicRooms = async (caller, { roomIds, scores }) => {
109109
chatsAPI.get = async (caller, { uid, roomId }) => await messaging.loadRoom(caller.uid, { uid, roomId });
110110

111111
chatsAPI.post = async (caller, data) => {
112-
if (await rateLimitExceeded(caller, 'lastChatMessageTime')) {
113-
throw new Error('[[error:too-many-messages]]');
114-
}
115112
if (!data || !data.roomId || !caller.uid) {
116113
throw new Error('[[error:invalid-data]]');
117114
}
@@ -122,7 +119,13 @@ chatsAPI.post = async (caller, data) => {
122119
}));
123120

124121
await messaging.canMessageRoom(caller.uid, data.roomId);
125-
const message = await messaging.sendMessage({
122+
await messaging.checkContent(data.message);
123+
124+
if (await rateLimitExceeded(caller, 'lastChatMessageTime')) {
125+
throw new Error('[[error:too-many-messages]]');
126+
}
127+
128+
const message = await messaging.addMessage({
126129
uid: caller.uid,
127130
roomId: data.roomId,
128131
content: data.message,

0 commit comments

Comments
 (0)