Skip to content

Commit

Permalink
prevent spam messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten committed Dec 21, 2021
1 parent 8f7eab2 commit f00f850
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions frontend/ui/src/pages/Inbox/MessageInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ const MessageInput = (props: Props) => {
const [uploadedFileUrl, setUploadedFileUrl] = useState<string | null>(null);
const [fileUploadErrorPopUp, setFileUploadErrorPopUp] = useState<string>('');
const [loadingSelector, setLoadingSelector] = useState(false);
const [blockSpam, setBlockSpam] = useState(false);
const prevConversationId = usePrevious(conversation.id);

const textAreaRef = useRef(null);
Expand Down Expand Up @@ -237,6 +238,7 @@ const MessageInput = (props: Props) => {
if (canSendMessage()) {
setSelectedSuggestedReply(null);
setSelectedTemplate(null);
setBlockSpam(true);

sendMessages(
selectedTemplate || selectedSuggestedReply
Expand All @@ -255,6 +257,7 @@ const MessageInput = (props: Props) => {
}
).then(() => {
setInput('');
setBlockSpam(false);
removeElementFromInput();
});
}
Expand All @@ -267,7 +270,7 @@ const MessageInput = (props: Props) => {
(event.ctrlKey && event.key === 'Enter')
) {
event.preventDefault();
if (input.trim().length > 0) {
if (input.trim().length > 0 && !blockSpam) {
sendMessage();
}
}
Expand Down Expand Up @@ -371,8 +374,7 @@ const MessageInput = (props: Props) => {
type="button"
styleVariant="outline-big"
onClick={toggleSuggestedReplies}
dataCy={cySuggestionsButton}
>
dataCy={cySuggestionsButton}>
<div className={styles.suggestionButton}>
Suggestions
<ChevronDownIcon className={hasSuggestions() ? styles.chevronUp : styles.chevronDown} />
Expand Down Expand Up @@ -453,9 +455,8 @@ const MessageInput = (props: Props) => {
(input.trim().length != 0 || canSendMessage()) && styles.sendButtonActive
}`}
onClick={sendMessage}
disabled={input.trim().length == 0 && !canSendMessage()}
data-cy={cyMessageSendButton}
>
disabled={(input.trim().length == 0 && !canSendMessage()) || blockSpam}
data-cy={cyMessageSendButton}>
<div className={styles.sendButtonText}>
<Paperplane />
</div>
Expand All @@ -464,8 +465,7 @@ const MessageInput = (props: Props) => {
</form>
<div
className={styles.linebreakHint}
style={textAreaRef?.current?.value?.length > 0 ? {visibility: 'visible'} : {visibility: 'hidden'}}
>
style={textAreaRef?.current?.value?.length > 0 ? {visibility: 'visible'} : {visibility: 'hidden'}}>
{'Shift + Enter to add line'}
</div>
</div>
Expand Down

0 comments on commit f00f850

Please sign in to comment.