mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
fix: add toast on rate limit hit for reactions
This commit is contained in:
parent
bffc9eddd5
commit
135b9cf34d
5 changed files with 15 additions and 6 deletions
|
@ -484,6 +484,7 @@
|
|||
"clearAllReactions": "Are you sure you want to clear all $emoji$ ?",
|
||||
"expandedReactionsText": "Show Less",
|
||||
"reactionNotification": "Reacts to a message with $emoji$",
|
||||
"rateLimitReactMessage": "Slow down! You've sent too many emoji reacts. Try again soon",
|
||||
"otherSingular": "$number$ other",
|
||||
"otherPlural": "$number$ others",
|
||||
"reactionPopup": "reacted with",
|
||||
|
|
|
@ -5,7 +5,7 @@ import { Action, OpenGroupReactionResponse, Reaction } from '../../../../types/R
|
|||
import { getEmojiDataFromNative } from '../../../../util/emoji';
|
||||
import { Reactions } from '../../../../util/reactions';
|
||||
import { OnionSending } from '../../../onions/onionSend';
|
||||
import { UserUtils } from '../../../utils';
|
||||
import { ToastUtils, UserUtils } from '../../../utils';
|
||||
import { OpenGroupPollingUtils } from '../opengroupV2/OpenGroupPollingUtils';
|
||||
import { getUsBlindedInThatServer } from './knownBlindedkeys';
|
||||
import { batchGlobalIsSuccess, parseBatchGlobalStatusCode } from './sogsV3BatchPoll';
|
||||
|
@ -58,6 +58,8 @@ export const sendSogsReactionOnionV4 = async (
|
|||
}
|
||||
|
||||
if (Reactions.hitRateLimit()) {
|
||||
ToastUtils.pushRateLimitHitReactions();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -277,3 +277,7 @@ export function pushNoMediaUntilApproved() {
|
|||
export function pushMustBeApproved() {
|
||||
pushToastError('mustBeApproved', window.i18n('mustBeApproved'));
|
||||
}
|
||||
|
||||
export function pushRateLimitHitReactions() {
|
||||
pushToastInfo('reactRateLimit', '', window?.i18n?.('rateLimitReactMessage')); // because otherwise test fails
|
||||
}
|
||||
|
|
|
@ -87,6 +87,7 @@ export type LocalizerKeys =
|
|||
| 'enterNewPassword'
|
||||
| 'expandedReactionsText'
|
||||
| 'openMessageRequestInbox'
|
||||
| 'rateLimitReactMessage'
|
||||
| 'enterPassword'
|
||||
| 'enterSessionIDOfRecipient'
|
||||
| 'join'
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
getUsBlindedInThatServer,
|
||||
isUsAnySogsFromCache,
|
||||
} from '../session/apis/open_group_api/sogsv3/knownBlindedkeys';
|
||||
import { UserUtils } from '../session/utils';
|
||||
import { ToastUtils, UserUtils } from '../session/utils';
|
||||
|
||||
import { Action, OpenGroupReactionList, ReactionList, RecentReactions } from '../types/Reaction';
|
||||
import { getRecentReactions, saveRecentReations } from '../util/storage';
|
||||
|
@ -17,14 +17,14 @@ const rateTimeLimit = 60 * 1000;
|
|||
const latestReactionTimestamps: Array<number> = [];
|
||||
|
||||
function hitRateLimit(): boolean {
|
||||
const timestamp = Date.now();
|
||||
latestReactionTimestamps.push(timestamp);
|
||||
const now = Date.now();
|
||||
latestReactionTimestamps.push(now);
|
||||
|
||||
if (latestReactionTimestamps.length > rateCountLimit) {
|
||||
const firstTimestamp = latestReactionTimestamps[0];
|
||||
if (timestamp - firstTimestamp < rateTimeLimit) {
|
||||
if (now - firstTimestamp < rateTimeLimit) {
|
||||
latestReactionTimestamps.pop();
|
||||
window.log.warn('Only 20 reactions are allowed per minute');
|
||||
window.log.warn(`Only ${rateCountLimit} reactions are allowed per minute`);
|
||||
return true;
|
||||
} else {
|
||||
latestReactionTimestamps.shift();
|
||||
|
@ -86,6 +86,7 @@ const sendMessageReaction = async (messageId: string, emoji: string) => {
|
|||
}
|
||||
|
||||
if (hitRateLimit()) {
|
||||
ToastUtils.pushRateLimitHitReactions();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue