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