mirror of
https://github.com/Qortal/Qortal-Hub.git
synced 2025-07-23 04:36:52 +00:00
cases
This commit is contained in:
@@ -101,43 +101,41 @@ export const ChatDirect = ({ myAddress, isNewChat, selectedDirect, setSelectedDi
|
||||
const decryptMessages = (encryptedMessages: any[], isInitiated: boolean)=> {
|
||||
try {
|
||||
return new Promise((res, rej)=> {
|
||||
chrome?.runtime?.sendMessage({ action: "decryptDirect", payload: {
|
||||
window.sendMessage("decryptDirect", {
|
||||
data: encryptedMessages,
|
||||
involvingAddress: selectedDirect?.address
|
||||
}}, (response) => {
|
||||
|
||||
if (!response?.error) {
|
||||
|
||||
processWithNewMessages(response, selectedDirect?.address)
|
||||
|
||||
res(response)
|
||||
if(isInitiated){
|
||||
involvingAddress: selectedDirect?.address,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
processWithNewMessages(response, selectedDirect?.address);
|
||||
res(response);
|
||||
|
||||
const formatted = response.map((item: any)=> {
|
||||
return {
|
||||
if (isInitiated) {
|
||||
const formatted = response.map((item) => ({
|
||||
...item,
|
||||
id: item.signature,
|
||||
text: item.message,
|
||||
unread: item?.sender === myAddress ? false : true
|
||||
}
|
||||
} )
|
||||
setMessages((prev)=> [...prev, ...formatted])
|
||||
} else {
|
||||
const formatted = response.map((item: any)=> {
|
||||
return {
|
||||
unread: item?.sender === myAddress ? false : true,
|
||||
}));
|
||||
setMessages((prev) => [...prev, ...formatted]);
|
||||
} else {
|
||||
const formatted = response.map((item) => ({
|
||||
...item,
|
||||
id: item.signature,
|
||||
text: item.message,
|
||||
unread: false
|
||||
}
|
||||
} )
|
||||
setMessages(formatted)
|
||||
hasInitialized.current = true
|
||||
|
||||
unread: false,
|
||||
}));
|
||||
setMessages(formatted);
|
||||
hasInitialized.current = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
rej(response.error)
|
||||
});
|
||||
rej(response.error);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
@@ -246,43 +244,52 @@ const sendChatDirect = async ({ chatReference = undefined, messageText, otherDat
|
||||
|
||||
if(!directTo) return
|
||||
return new Promise((res, rej)=> {
|
||||
chrome?.runtime?.sendMessage({ action: "sendChatDirect", payload: {
|
||||
directTo, chatReference, messageText, otherData, publicKeyOfRecipient, address: directTo
|
||||
}}, async (response) => {
|
||||
|
||||
if (!response?.error) {
|
||||
if(isNewChatVar){
|
||||
|
||||
let getRecipientName = null
|
||||
try {
|
||||
getRecipientName = await getNameInfo(response.recipient)
|
||||
} catch (error) {
|
||||
|
||||
window.sendMessage("sendChatDirect", {
|
||||
directTo,
|
||||
chatReference,
|
||||
messageText,
|
||||
otherData,
|
||||
publicKeyOfRecipient,
|
||||
address: directTo,
|
||||
})
|
||||
.then(async (response) => {
|
||||
if (!response?.error) {
|
||||
if (isNewChatVar) {
|
||||
let getRecipientName = null;
|
||||
try {
|
||||
getRecipientName = await getNameInfo(response.recipient);
|
||||
} catch (error) {
|
||||
console.error("Error fetching recipient name:", error);
|
||||
}
|
||||
setSelectedDirect({
|
||||
address: response.recipient,
|
||||
name: getRecipientName,
|
||||
timestamp: Date.now(),
|
||||
sender: myAddress,
|
||||
senderName: myName,
|
||||
});
|
||||
setNewChat(null);
|
||||
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: response.recipient,
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat();
|
||||
}, 400);
|
||||
}
|
||||
setSelectedDirect({
|
||||
"address": response.recipient,
|
||||
"name": getRecipientName,
|
||||
"timestamp": Date.now(),
|
||||
"sender": myAddress,
|
||||
"senderName": myName
|
||||
})
|
||||
setNewChat(null)
|
||||
window.sendMessage("addTimestampEnterChat", {
|
||||
timestamp: Date.now(),
|
||||
groupId: response.recipient,
|
||||
}).catch((error) => {
|
||||
console.error("Failed to add timestamp:", error.message || "An error occurred");
|
||||
});
|
||||
|
||||
setTimeout(() => {
|
||||
getTimestampEnterChat()
|
||||
}, 400);
|
||||
res(response);
|
||||
return;
|
||||
}
|
||||
res(response)
|
||||
return
|
||||
}
|
||||
rej(response.error)
|
||||
});
|
||||
rej(response.error);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error(error)
|
||||
|
@@ -424,16 +424,23 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
|
||||
const sendChatGroup = async ({groupId, typeMessage = undefined, chatReference = undefined, messageText}: any)=> {
|
||||
try {
|
||||
return new Promise((res, rej)=> {
|
||||
chrome?.runtime?.sendMessage({ action: "sendChatGroup", payload: {
|
||||
groupId, typeMessage, chatReference, messageText
|
||||
}}, (response) => {
|
||||
|
||||
if (!response?.error) {
|
||||
res(response)
|
||||
return
|
||||
}
|
||||
rej(response.error)
|
||||
});
|
||||
window.sendMessage("sendChatGroup", {
|
||||
groupId,
|
||||
typeMessage,
|
||||
chatReference,
|
||||
messageText,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
res(response);
|
||||
return;
|
||||
}
|
||||
rej(response.error);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
})
|
||||
} catch (error) {
|
||||
throw new Error(error)
|
||||
|
@@ -86,38 +86,34 @@ export const getTempPublish = async () => {
|
||||
export const decryptPublishes = async (encryptedMessages: any[], secretKey) => {
|
||||
try {
|
||||
return await new Promise((res, rej) => {
|
||||
chrome?.runtime?.sendMessage(
|
||||
{
|
||||
action: "decryptSingleForPublishes",
|
||||
payload: {
|
||||
data: encryptedMessages,
|
||||
secretKeyObject: secretKey,
|
||||
skipDecodeBase64: true,
|
||||
},
|
||||
},
|
||||
(response) => {
|
||||
window.sendMessage("decryptSingleForPublishes", {
|
||||
data: encryptedMessages,
|
||||
secretKeyObject: secretKey,
|
||||
skipDecodeBase64: true,
|
||||
})
|
||||
.then((response) => {
|
||||
if (!response?.error) {
|
||||
res(response);
|
||||
// if(hasInitialized.current){
|
||||
|
||||
// setMessages((prev)=> [...prev, ...formatted])
|
||||
// setMessages((prev) => [...prev, ...formatted]);
|
||||
// } else {
|
||||
// const formatted = response.map((item: any)=> {
|
||||
// return {
|
||||
// ...item,
|
||||
// id: item.signature,
|
||||
// text: item.text,
|
||||
// unread: false
|
||||
// }
|
||||
// } )
|
||||
// setMessages(formatted)
|
||||
// hasInitialized.current = true
|
||||
|
||||
// const formatted = response.map((item) => ({
|
||||
// ...item,
|
||||
// id: item.signature,
|
||||
// text: item.text,
|
||||
// unread: false
|
||||
// }));
|
||||
// setMessages(formatted);
|
||||
// hasInitialized.current = true;
|
||||
// }
|
||||
return;
|
||||
}
|
||||
rej(response.error);
|
||||
}
|
||||
);
|
||||
})
|
||||
.catch((error) => {
|
||||
rej(error.message || "An error occurred");
|
||||
});
|
||||
|
||||
});
|
||||
} catch (error) {}
|
||||
};
|
||||
|
Reference in New Issue
Block a user