From 5d92ac2ce3eeb0e6d8f1c1f1ca2941dde74756ee Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Mon, 13 May 2024 22:36:56 +0100
Subject: dont send message if >1000 graphemes (#3995)

---
 src/screens/Messages/Conversation/MessageInput.web.tsx | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

(limited to 'src/screens/Messages/Conversation/MessageInput.web.tsx')

diff --git a/src/screens/Messages/Conversation/MessageInput.web.tsx b/src/screens/Messages/Conversation/MessageInput.web.tsx
index a2f255bdc..2ee03bb31 100644
--- a/src/screens/Messages/Conversation/MessageInput.web.tsx
+++ b/src/screens/Messages/Conversation/MessageInput.web.tsx
@@ -2,8 +2,11 @@ import React from 'react'
 import {Pressable, StyleSheet, View} from 'react-native'
 import {msg} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
+import Graphemer from 'graphemer'
 import TextareaAutosize from 'react-textarea-autosize'
 
+import {MAX_DM_GRAPHEME_LENGTH} from '#/lib/constants'
+import * as Toast from '#/view/com/util/Toast'
 import {atoms as a, useTheme} from '#/alf'
 import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
 
@@ -21,9 +24,13 @@ export function MessageInput({
     if (message.trim() === '') {
       return
     }
+    if (new Graphemer().countGraphemes(message) > MAX_DM_GRAPHEME_LENGTH) {
+      Toast.show(_(msg`Message is too long`))
+      return
+    }
     onSendMessage(message.trimEnd())
     setMessage('')
-  }, [message, onSendMessage])
+  }, [message, onSendMessage, _])
 
   const onKeyDown = React.useCallback(
     (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
-- 
cgit 1.4.1

