dont send message if >1000 graphemes (#3995)
parent
27bb73c701
commit
5d92ac2ce3
|
@ -36,6 +36,8 @@ export const MAX_DESCRIPTION = 256
|
||||||
|
|
||||||
export const MAX_GRAPHEME_LENGTH = 300
|
export const MAX_GRAPHEME_LENGTH = 300
|
||||||
|
|
||||||
|
export const MAX_DM_GRAPHEME_LENGTH = 1000
|
||||||
|
|
||||||
// Recommended is 100 per: https://www.w3.org/WAI/GL/WCAG20/tests/test3.html
|
// Recommended is 100 per: https://www.w3.org/WAI/GL/WCAG20/tests/test3.html
|
||||||
// but increasing limit per user feedback
|
// but increasing limit per user feedback
|
||||||
export const MAX_ALT_TEXT = 1000
|
export const MAX_ALT_TEXT = 1000
|
||||||
|
|
|
@ -11,9 +11,11 @@ import {
|
||||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
import Graphemer from 'graphemer'
|
||||||
|
|
||||||
import {HITSLOP_10} from '#/lib/constants'
|
import {HITSLOP_10, MAX_DM_GRAPHEME_LENGTH} from '#/lib/constants'
|
||||||
import {useHaptics} from 'lib/haptics'
|
import {useHaptics} from '#/lib/haptics'
|
||||||
|
import * as Toast from '#/view/com/util/Toast'
|
||||||
import {atoms as a, useTheme} from '#/alf'
|
import {atoms as a, useTheme} from '#/alf'
|
||||||
import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
|
import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
|
||||||
|
|
||||||
|
@ -39,13 +41,17 @@ export function MessageInput({
|
||||||
if (message.trim() === '') {
|
if (message.trim() === '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (new Graphemer().countGraphemes(message) > MAX_DM_GRAPHEME_LENGTH) {
|
||||||
|
Toast.show(_(msg`Message is too long`))
|
||||||
|
return
|
||||||
|
}
|
||||||
onSendMessage(message.trimEnd())
|
onSendMessage(message.trimEnd())
|
||||||
playHaptic()
|
playHaptic()
|
||||||
setMessage('')
|
setMessage('')
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
inputRef.current?.focus()
|
inputRef.current?.focus()
|
||||||
}, 100)
|
}, 100)
|
||||||
}, [message, onSendMessage, playHaptic])
|
}, [message, onSendMessage, playHaptic, _])
|
||||||
|
|
||||||
const onInputLayout = React.useCallback(
|
const onInputLayout = React.useCallback(
|
||||||
(e: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => {
|
(e: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => {
|
||||||
|
|
|
@ -2,8 +2,11 @@ import React from 'react'
|
||||||
import {Pressable, StyleSheet, View} from 'react-native'
|
import {Pressable, StyleSheet, View} from 'react-native'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
|
import Graphemer from 'graphemer'
|
||||||
import TextareaAutosize from 'react-textarea-autosize'
|
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 {atoms as a, useTheme} from '#/alf'
|
||||||
import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
|
import {PaperPlane_Stroke2_Corner0_Rounded as PaperPlane} from '#/components/icons/PaperPlane'
|
||||||
|
|
||||||
|
@ -21,9 +24,13 @@ export function MessageInput({
|
||||||
if (message.trim() === '') {
|
if (message.trim() === '') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (new Graphemer().countGraphemes(message) > MAX_DM_GRAPHEME_LENGTH) {
|
||||||
|
Toast.show(_(msg`Message is too long`))
|
||||||
|
return
|
||||||
|
}
|
||||||
onSendMessage(message.trimEnd())
|
onSendMessage(message.trimEnd())
|
||||||
setMessage('')
|
setMessage('')
|
||||||
}, [message, onSendMessage])
|
}, [message, onSendMessage, _])
|
||||||
|
|
||||||
const onKeyDown = React.useCallback(
|
const onKeyDown = React.useCallback(
|
||||||
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
(e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
|
Loading…
Reference in New Issue