mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-04-20 10:05:56 +00:00
fix message size
This commit is contained in:
parent
4cafd57abe
commit
fe9a7acdaa
@ -319,7 +319,7 @@ function App() {
|
||||
useState<string>("");
|
||||
const [isMain, setIsMain] = useState<boolean>(true);
|
||||
const isMainRef = useRef(false);
|
||||
const [authenticatePassword, setAuthenticatePassword] = useState<string>("1234567890");
|
||||
const [authenticatePassword, setAuthenticatePassword] = useState<string>("");
|
||||
const [sendqortState, setSendqortState] = useState<any>(null);
|
||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||
const [
|
||||
|
@ -377,7 +377,8 @@ useEffect(() => {
|
||||
|
||||
const sendMessage = async ()=> {
|
||||
try {
|
||||
|
||||
if(messageSize > 4000) return
|
||||
|
||||
|
||||
if(+balance < 4) throw new Error('You need at least 4 QORT to send a message')
|
||||
if(isSending) return
|
||||
@ -674,7 +675,6 @@ useEffect(() => {
|
||||
|
||||
<CustomButton
|
||||
onClick={()=> {
|
||||
if(messageSize > 4000) return
|
||||
|
||||
if(isSending) return
|
||||
sendMessage()
|
||||
|
@ -562,6 +562,7 @@ const clearEditorContent = () => {
|
||||
|
||||
const sendMessage = async ()=> {
|
||||
try {
|
||||
if(messageSize > 4000) return
|
||||
if(isPrivate === null) throw new Error('Unable to determine if group is private')
|
||||
if(isSending) return
|
||||
if(+balance < 4) throw new Error('You need at least 4 QORT to send a message')
|
||||
@ -647,11 +648,19 @@ const clearEditorContent = () => {
|
||||
|
||||
handleUpdateRef.current = throttle(async () => {
|
||||
try {
|
||||
const htmlContent = editorRef.current.getHTML();
|
||||
const message64 = await objectToBase64(JSON.stringify(htmlContent))
|
||||
const secretKeyObject = await getSecretKey(false, true)
|
||||
const encryptSingle = await encryptChatMessage(message64, secretKeyObject)
|
||||
setMessageSize((encryptSingle?.length || 0) + 200);
|
||||
if(isPrivate){
|
||||
const htmlContent = editorRef.current.getHTML();
|
||||
const message64 = await objectToBase64(JSON.stringify(htmlContent))
|
||||
const secretKeyObject = await getSecretKey(false, true)
|
||||
const encryptSingle = await encryptChatMessage(message64, secretKeyObject)
|
||||
setMessageSize((encryptSingle?.length || 0) + 200);
|
||||
} else {
|
||||
const htmlContent = editorRef.current.getJSON();
|
||||
const message = JSON.stringify(htmlContent)
|
||||
const size = new Blob([message]).size
|
||||
setMessageSize(size + 300);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
// calc size error
|
||||
}
|
||||
@ -664,7 +673,7 @@ const clearEditorContent = () => {
|
||||
return () => {
|
||||
currentEditor.off("update", handleUpdateRef.current);
|
||||
};
|
||||
}, [editorRef, setMessageSize]);
|
||||
}, [editorRef, setMessageSize, isPrivate]);
|
||||
|
||||
useEffect(() => {
|
||||
if (hide) {
|
||||
@ -874,7 +883,7 @@ const clearEditorContent = () => {
|
||||
|
||||
<CustomButton
|
||||
onClick={()=> {
|
||||
if(messageSize > 4000) return
|
||||
|
||||
if(isSending) return
|
||||
sendMessage()
|
||||
}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user