This commit is contained in:
PhilReact 2024-10-29 06:49:25 +02:00
parent cbd372bc07
commit 4da55da54e
13 changed files with 603 additions and 359 deletions

View File

@ -6,8 +6,10 @@ import {
banFromGroup, banFromGroup,
cancelBan, cancelBan,
cancelInvitationToGroup, cancelInvitationToGroup,
checkThreads,
clearAllNotifications, clearAllNotifications,
createGroup, createGroup,
decryptSingleFunc,
decryptWallet, decryptWallet,
findUsableApi, findUsableApi,
getApiKeyFromStorage, getApiKeyFromStorage,
@ -23,6 +25,7 @@ import {
getTimestampGroupAnnouncement, getTimestampGroupAnnouncement,
getUserInfo, getUserInfo,
getUserSettings, getUserSettings,
handleActiveGroupDataFromSocket,
inviteToGroup, inviteToGroup,
joinGroup, joinGroup,
kickFromGroup, kickFromGroup,
@ -37,10 +40,12 @@ import {
sendCoin, sendCoin,
setChatHeads, setChatHeads,
setGroupData, setGroupData,
updateThreadActivity,
walletVersion, walletVersion,
} from "./background"; } from "./background";
import { encryptAndPublishSymmetricKeyGroupChat } from "./backgroundFunctions/encryption"; import { decryptGroupEncryption, encryptAndPublishSymmetricKeyGroupChat, publishGroupEncryptedResource, publishOnQDN } from "./backgroundFunctions/encryption";
import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from "./constants/codes"; import { PUBLIC_NOTIFICATION_CODE_FIRST_SECRET_KEY } from "./constants/codes";
import { encryptSingle } from "./qdn/encryption/group-encryption";
export function versionCase(request, event) { export function versionCase(request, event) {
event.source.postMessage( event.source.postMessage(
@ -1182,3 +1187,232 @@ export async function encryptAndPublishSymmetricKeyGroupChatCase(
); );
} }
} }
export async function publishGroupEncryptedResourceCase(request, event) {
try {
const {encryptedData, identifier} = request.payload;
const response = await publishGroupEncryptedResource({encryptedData, identifier});
event.source.postMessage(
{
requestId: request.requestId,
action: "publishGroupEncryptedResource",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "publishGroupEncryptedResource",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function publishOnQDNCase(request, event) {
try {
const {data, identifier, service, title,
description,
category,
tag1,
tag2,
tag3,
tag4,
tag5, uploadType} = request.payload;
const response = await publishOnQDN({data, identifier, service, title,
description,
category,
tag1,
tag2,
tag3,
tag4,
tag5, uploadType});
event.source.postMessage(
{
requestId: request.requestId,
action: "publishOnQDN",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "publishOnQDN",
error: error?.message || 'Unable to publish',
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function handleActiveGroupDataFromSocketCase(request, event) {
try {
const {groups, directs} = request.payload;
const response = await handleActiveGroupDataFromSocket({groups, directs});
event.source.postMessage(
{
requestId: request.requestId,
action: "handleActiveGroupDataFromSocket",
payload: true,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "handleActiveGroupDataFromSocket",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function getThreadActivityCase(request, event) {
try {
const response = await checkThreads(true)
event.source.postMessage(
{
requestId: request.requestId,
action: "getThreadActivity",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "getThreadActivity",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function updateThreadActivityCase(request, event) {
try {
const { threadId, qortalName, groupId, thread} = request.payload;
const response = await updateThreadActivity({ threadId, qortalName, groupId, thread });
event.source.postMessage(
{
requestId: request.requestId,
action: "updateThreadActivity",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "updateThreadActivity",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function decryptGroupEncryptionCase(request, event) {
try {
const { data} = request.payload;
const response = await decryptGroupEncryption({ data });
event.source.postMessage(
{
requestId: request.requestId,
action: "decryptGroupEncryption",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "decryptGroupEncryption",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function encryptSingleCase(request, event) {
try {
const { data, secretKeyObject, typeNumber} = request.payload;
const response = await encryptSingle({ data, secretKeyObject, typeNumber });
event.source.postMessage(
{
requestId: request.requestId,
action: "encryptSingle",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "encryptSingle",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function decryptSingleCase(request, event) {
try {
const { data, secretKeyObject, skipDecodeBase64} = request.payload;
const response = await decryptSingleFunc({ data, secretKeyObject, skipDecodeBase64 });
event.source.postMessage(
{
requestId: request.requestId,
action: "decryptSingle",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "decryptSingle",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}

View File

@ -39,17 +39,22 @@ import {
cancelInvitationToGroupCase, cancelInvitationToGroupCase,
clearAllNotificationsCase, clearAllNotificationsCase,
createGroupCase, createGroupCase,
decryptGroupEncryptionCase,
decryptSingleCase,
decryptWalletCase, decryptWalletCase,
encryptAndPublishSymmetricKeyGroupChatCase, encryptAndPublishSymmetricKeyGroupChatCase,
encryptSingleCase,
getApiKeyCase, getApiKeyCase,
getCustomNodesFromStorageCase, getCustomNodesFromStorageCase,
getDataPublishesCase, getDataPublishesCase,
getGroupDataSingleCase, getGroupDataSingleCase,
getGroupNotificationTimestampCase, getGroupNotificationTimestampCase,
getTempPublishCase, getTempPublishCase,
getThreadActivityCase,
getTimestampEnterChatCase, getTimestampEnterChatCase,
getUserSettingsCase, getUserSettingsCase,
getWalletInfoCase, getWalletInfoCase,
handleActiveGroupDataFromSocketCase,
inviteToGroupCase, inviteToGroupCase,
joinGroupCase, joinGroupCase,
kickFromGroupCase, kickFromGroupCase,
@ -59,6 +64,8 @@ import {
nameCase, nameCase,
notificationCase, notificationCase,
notifyAdminRegenerateSecretKeyCase, notifyAdminRegenerateSecretKeyCase,
publishGroupEncryptedResourceCase,
publishOnQDNCase,
registerNameCase, registerNameCase,
removeAdminCase, removeAdminCase,
saveTempPublishCase, saveTempPublishCase,
@ -67,6 +74,7 @@ import {
setChatHeadsCase, setChatHeadsCase,
setCustomNodesCase, setCustomNodesCase,
setGroupDataCase, setGroupDataCase,
updateThreadActivityCase,
userInfoCase, userInfoCase,
validApiCase, validApiCase,
versionCase, versionCase,
@ -470,7 +478,12 @@ async function getThreadActivity() {
} }
} }
async function updateThreadActivity({ threadId, qortalName, groupId, thread }) { export async function updateThreadActivity({
threadId,
qortalName,
groupId,
thread,
}) {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000; // One week in milliseconds const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000; // One week in milliseconds
@ -707,7 +720,7 @@ const handleNotification = async (groups) => {
} }
}; };
const checkThreads = async (bringBack) => { export const checkThreads = async (bringBack) => {
try { try {
let myName = ""; let myName = "";
const userData = await getUserInfo(); const userData = await getUserInfo();
@ -1567,7 +1580,7 @@ const getStoredData = async (key) => {
}); });
}; };
async function handleActiveGroupDataFromSocket({ groups, directs }) { export async function handleActiveGroupDataFromSocket({ groups, directs }) {
try { try {
chrome.runtime.sendMessage({ chrome.runtime.sendMessage({
action: "SET_GROUPS", action: "SET_GROUPS",
@ -1799,7 +1812,7 @@ async function sendChatDirect({
return _response; return _response;
} }
async function decryptSingleFunc({ export async function decryptSingleFunc({
messages, messages,
secretKeyObject, secretKeyObject,
skipDecodeBase64, skipDecodeBase64,
@ -3042,8 +3055,32 @@ function setupMessageListener() {
case "encryptAndPublishSymmetricKeyGroupChat": case "encryptAndPublishSymmetricKeyGroupChat":
encryptAndPublishSymmetricKeyGroupChatCase(request, event); encryptAndPublishSymmetricKeyGroupChatCase(request, event);
break; break;
case "publishGroupEncryptedResource":
publishGroupEncryptedResourceCase(request, event);
break;
case "publishOnQDN":
publishOnQDNCase(request, event);
break;
case "handleActiveGroupDataFromSocket":
handleActiveGroupDataFromSocketCase(request, event);
break;
case "getThreadActivity":
getThreadActivityCase(request, event);
break;
case "updateThreadActivity":
updateThreadActivityCase(request, event);
case "decryptGroupEncryption":
decryptGroupEncryptionCase(request, event);
break;
case "encryptSingle":
encryptSingleCase(request, event);
break;
case "decryptSingle":
decryptSingleCase(request, event);
break;
default: default:
console.error("Unknown action:", request.action); console.error("Unknown action:", request.action);
break
} }
}); });
} }

View File

@ -201,10 +201,7 @@ export const AppPublish = ({ names, categories }) => {
setIsLoading("Publishing... Please wait."); setIsLoading("Publishing... Please wait.");
const fileBase64 = await fileToBase64(file); const fileBase64 = await fileToBase64(file);
await new Promise((res, rej) => { await new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishOnQDN", {
{
action: "publishOnQDN",
payload: {
data: fileBase64, data: fileBase64,
service: appType, service: appType,
title, title,
@ -215,17 +212,19 @@ export const AppPublish = ({ names, categories }) => {
tag3, tag3,
tag4, tag4,
tag5, tag5,
uploadType: 'zip' uploadType: "zip",
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return; return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
setInfoSnack({ setInfoSnack({
type: "success", type: "success",

View File

@ -75,23 +75,21 @@ export const AnnouncementDiscussion = ({
if (!selectedAnnouncement) return; if (!selectedAnnouncement) return;
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishGroupEncryptedResource", {
{
action: "publishGroupEncryptedResource",
payload: {
encryptedData, encryptedData,
identifier, identifier,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) {} } catch (error) {}
}; };

View File

@ -125,42 +125,43 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
return return
} }
return new Promise((res, rej)=> { return new Promise((res, rej)=> {
chrome?.runtime?.sendMessage({ action: "decryptSingle", payload: { window.sendMessage("decryptSingle", {
data: encryptedMessages, data: encryptedMessages,
secretKeyObject: secretKey secretKeyObject: secretKey,
}}, (response) => { })
.then((response) => {
if (!response?.error) { if (!response?.error) {
const filterUImessages = encryptedMessages.filter((item)=> !isExtMsg(item.data)) const filterUIMessages = encryptedMessages.filter((item) => !isExtMsg(item.data));
const decodedUIMessages = decodeBase64ForUIChatMessages(filterUImessages) const decodedUIMessages = decodeBase64ForUIChatMessages(filterUIMessages);
const combineUIAndExtensionMsgs = [...decodedUIMessages, ...response] const combineUIAndExtensionMsgs = [...decodedUIMessages, ...response];
processWithNewMessages(combineUIAndExtensionMsgs?.map((item)=> { processWithNewMessages(
return { combineUIAndExtensionMsgs.map((item) => ({
...item, ...item,
...(item?.decryptedData || {}) ...(item?.decryptedData || {}),
} })),
}), selectedGroup) selectedGroup
res(combineUIAndExtensionMsgs) );
if(isInitiated){ res(combineUIAndExtensionMsgs);
const formatted = combineUIAndExtensionMsgs.filter((rawItem)=> !rawItem?.chatReference).map((item: any)=> { if (isInitiated) {
return { const formatted = combineUIAndExtensionMsgs
.filter((rawItem) => !rawItem?.chatReference)
.map((item) => ({
...item, ...item,
id: item.signature, id: item.signature,
text: item?.decryptedData?.message || "", text: item?.decryptedData?.message || "",
repliedTo: item?.repliedTo || item?.decryptedData?.repliedTo, repliedTo: item?.repliedTo || item?.decryptedData?.repliedTo,
unread: item?.sender === myAddress ? false : !!item?.chatReference ? false : true, unread: item?.sender === myAddress ? false : !!item?.chatReference ? false : true,
isNotEncrypted: !!item?.messageText isNotEncrypted: !!item?.messageText,
} }));
} ) setMessages((prev) => [...prev, ...formatted]);
setMessages((prev)=> [...prev, ...formatted])
setChatReferences((prev) => { setChatReferences((prev) => {
let organizedChatReferences = { ...prev }; const organizedChatReferences = { ...prev };
combineUIAndExtensionMsgs combineUIAndExtensionMsgs
.filter((rawItem) => rawItem && rawItem.chatReference && rawItem.decryptedData?.type === 'reaction') .filter((rawItem) => rawItem && rawItem.chatReference && rawItem.decryptedData?.type === "reaction")
.forEach((item) => { .forEach((item) => {
try { try {
const content = item.decryptedData?.content; const content = item.decryptedData?.content;
@ -168,45 +169,37 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
const newTimestamp = item.timestamp; const newTimestamp = item.timestamp;
const contentState = item.decryptedData?.contentState; const contentState = item.decryptedData?.contentState;
if (!content || typeof content !== 'string' || !sender || typeof sender !== 'string' || !newTimestamp) { if (!content || typeof content !== "string" || !sender || typeof sender !== "string" || !newTimestamp) {
console.warn("Invalid content, sender, or timestamp in reaction data", item); console.warn("Invalid content, sender, or timestamp in reaction data", item);
return; return;
} }
// Initialize chat reference and reactions if not present
organizedChatReferences[item.chatReference] = { organizedChatReferences[item.chatReference] = {
...(organizedChatReferences[item.chatReference] || {}), ...(organizedChatReferences[item.chatReference] || {}),
reactions: organizedChatReferences[item.chatReference]?.reactions || {} reactions: organizedChatReferences[item.chatReference]?.reactions || {},
}; };
organizedChatReferences[item.chatReference].reactions[content] = organizedChatReferences[item.chatReference].reactions[content] =
organizedChatReferences[item.chatReference].reactions[content] || []; organizedChatReferences[item.chatReference].reactions[content] || [];
// Remove any existing reactions from the same sender before adding the new one
let latestTimestampForSender = null; let latestTimestampForSender = null;
// Track the latest reaction timestamp for the same content and sender
organizedChatReferences[item.chatReference].reactions[content] = organizedChatReferences[item.chatReference].reactions[content] =
organizedChatReferences[item.chatReference].reactions[content].filter((reaction) => { organizedChatReferences[item.chatReference].reactions[content].filter((reaction) => {
if (reaction.sender === sender) { if (reaction.sender === sender) {
// Track the latest timestamp for this sender
latestTimestampForSender = Math.max(latestTimestampForSender || 0, reaction.timestamp); latestTimestampForSender = Math.max(latestTimestampForSender || 0, reaction.timestamp);
} }
return reaction.sender !== sender; return reaction.sender !== sender;
}); });
// Compare with the latest tracked timestamp for this sender
if (latestTimestampForSender && newTimestamp < latestTimestampForSender) { if (latestTimestampForSender && newTimestamp < latestTimestampForSender) {
// Ignore this item if it's older than the latest known reaction
return; return;
} }
// Add the new reaction only if contentState is true
if (contentState !== false) { if (contentState !== false) {
organizedChatReferences[item.chatReference].reactions[content].push(item); organizedChatReferences[item.chatReference].reactions[content].push(item);
} }
// If the reactions for a specific content are empty, clean up the object
if (organizedChatReferences[item.chatReference].reactions[content].length === 0) { if (organizedChatReferences[item.chatReference].reactions[content].length === 0) {
delete organizedChatReferences[item.chatReference].reactions[content]; delete organizedChatReferences[item.chatReference].reactions[content];
} }
@ -217,27 +210,24 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
return organizedChatReferences; return organizedChatReferences;
}); });
} else { } else {
const formatted = combineUIAndExtensionMsgs.filter((rawItem)=> !rawItem?.chatReference).map((item: any)=> { const formatted = combineUIAndExtensionMsgs
return { .filter((rawItem) => !rawItem?.chatReference)
.map((item) => ({
...item, ...item,
id: item.signature, id: item.signature,
text: item?.decryptedData?.message || "", text: item?.decryptedData?.message || "",
repliedTo: item?.repliedTo || item?.decryptedData?.repliedTo, repliedTo: item?.repliedTo || item?.decryptedData?.repliedTo,
isNotEncrypted: !!item?.messageText, isNotEncrypted: !!item?.messageText,
unread: false unread: false,
} }));
} ) setMessages(formatted);
setMessages(formatted)
setChatReferences((prev) => { setChatReferences((prev) => {
let organizedChatReferences = { ...prev }; const organizedChatReferences = { ...prev };
combineUIAndExtensionMsgs combineUIAndExtensionMsgs
.filter((rawItem) => rawItem && rawItem.chatReference && rawItem.decryptedData?.type === 'reaction') .filter((rawItem) => rawItem && rawItem.chatReference && rawItem.decryptedData?.type === "reaction")
.forEach((item) => { .forEach((item) => {
try { try {
const content = item.decryptedData?.content; const content = item.decryptedData?.content;
@ -245,45 +235,37 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
const newTimestamp = item.timestamp; const newTimestamp = item.timestamp;
const contentState = item.decryptedData?.contentState; const contentState = item.decryptedData?.contentState;
if (!content || typeof content !== 'string' || !sender || typeof sender !== 'string' || !newTimestamp) { if (!content || typeof content !== "string" || !sender || typeof sender !== "string" || !newTimestamp) {
console.warn("Invalid content, sender, or timestamp in reaction data", item); console.warn("Invalid content, sender, or timestamp in reaction data", item);
return; return;
} }
// Initialize chat reference and reactions if not present
organizedChatReferences[item.chatReference] = { organizedChatReferences[item.chatReference] = {
...(organizedChatReferences[item.chatReference] || {}), ...(organizedChatReferences[item.chatReference] || {}),
reactions: organizedChatReferences[item.chatReference]?.reactions || {} reactions: organizedChatReferences[item.chatReference]?.reactions || {},
}; };
organizedChatReferences[item.chatReference].reactions[content] = organizedChatReferences[item.chatReference].reactions[content] =
organizedChatReferences[item.chatReference].reactions[content] || []; organizedChatReferences[item.chatReference].reactions[content] || [];
// Remove any existing reactions from the same sender before adding the new one
let latestTimestampForSender = null; let latestTimestampForSender = null;
// Track the latest reaction timestamp for the same content and sender
organizedChatReferences[item.chatReference].reactions[content] = organizedChatReferences[item.chatReference].reactions[content] =
organizedChatReferences[item.chatReference].reactions[content].filter((reaction) => { organizedChatReferences[item.chatReference].reactions[content].filter((reaction) => {
if (reaction.sender === sender) { if (reaction.sender === sender) {
// Track the latest timestamp for this sender
latestTimestampForSender = Math.max(latestTimestampForSender || 0, reaction.timestamp); latestTimestampForSender = Math.max(latestTimestampForSender || 0, reaction.timestamp);
} }
return reaction.sender !== sender; return reaction.sender !== sender;
}); });
// Compare with the latest tracked timestamp for this sender
if (latestTimestampForSender && newTimestamp < latestTimestampForSender) { if (latestTimestampForSender && newTimestamp < latestTimestampForSender) {
// Ignore this item if it's older than the latest known reaction
return; return;
} }
// Add the new reaction only if contentState is true
if (contentState !== false) { if (contentState !== false) {
organizedChatReferences[item.chatReference].reactions[content].push(item); organizedChatReferences[item.chatReference].reactions[content].push(item);
} }
// If the reactions for a specific content are empty, clean up the object
if (organizedChatReferences[item.chatReference].reactions[content].length === 0) { if (organizedChatReferences[item.chatReference].reactions[content].length === 0) {
delete organizedChatReferences[item.chatReference].reactions[content]; delete organizedChatReferences[item.chatReference].reactions[content];
} }
@ -294,15 +276,14 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
return organizedChatReferences; return organizedChatReferences;
}); });
} }
} }
rej(response.error) rej(response.error);
})
.catch((error) => {
rej(error.message || "An error occurred");
}); });
}) })
} catch (error) { } catch (error) {
@ -418,17 +399,22 @@ export const ChatGroup = ({selectedGroup, secretKey, setSecretKey, getSecretKey,
const encryptChatMessage = async (data: string, secretKeyObject: any, reactiontypeNumber?: number)=> { const encryptChatMessage = async (data: string, secretKeyObject: any, reactiontypeNumber?: number)=> {
try { try {
return new Promise((res, rej)=> { return new Promise((res, rej)=> {
chrome?.runtime?.sendMessage({ action: "encryptSingle", payload: { window.sendMessage("encryptSingle", {
data, data,
secretKeyObject, secretKeyObject,
typeNumber: reactiontypeNumber typeNumber: reactiontypeNumber,
}}, (response) => { })
.then((response) => {
if (!response?.error) { if (!response?.error) {
res(response) res(response);
return;
} }
rej(response.error) rej(response.error);
})
.catch((error) => {
rej(error.message || "An error occurred");
}); });
}) })
} catch (error) { } catch (error) {

View File

@ -208,43 +208,42 @@ export const GroupAnnouncements = ({
const encryptChatMessage = async (data: string, secretKeyObject: any) => { const encryptChatMessage = async (data: string, secretKeyObject: any) => {
try { try {
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("encryptSingle", {
{
action: "encryptSingle",
payload: {
data, data,
secretKeyObject, secretKeyObject,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return; return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) {} } catch (error) {}
}; };
const publishAnc = async ({ encryptedData, identifier }: any) => { const publishAnc = async ({ encryptedData, identifier }: any) => {
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishGroupEncryptedResource", {
{
action: "publishGroupEncryptedResource",
payload: {
encryptedData, encryptedData,
identifier, identifier,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
}; };
const clearEditorContent = () => { const clearEditorContent = () => {

View File

@ -145,22 +145,23 @@ export const GroupMail = ({
const updateThreadActivity = async ({threadId, qortalName, groupId, thread}) => { const updateThreadActivity = async ({threadId, qortalName, groupId, thread}) => {
try { try {
await new Promise((res, rej) => { await new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("updateThreadActivity", {
{ threadId,
action: "updateThreadActivity", qortalName,
payload: { groupId,
threadId, qortalName, groupId, thread thread,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) { } catch (error) {

View File

@ -94,46 +94,42 @@ export const publishGroupEncryptedResource = async ({
identifier, identifier,
}) => { }) => {
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishGroupEncryptedResource", {
{
action: "publishGroupEncryptedResource",
payload: {
encryptedData, encryptedData,
identifier, identifier,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
}; };
export const encryptSingleFunc = async (data: string, secretKeyObject: any) => { export const encryptSingleFunc = async (data: string, secretKeyObject: any) => {
try { try {
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("encryptSingle", {
{
action: "encryptSingle",
payload: {
data, data,
secretKeyObject, secretKeyObject,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return; return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) {} } catch (error) {}
}; };

View File

@ -199,21 +199,20 @@ export const getGroupMembers = async (groupNumber: number) => {
export const decryptResource = async (data: string) => { export const decryptResource = async (data: string) => {
try { try {
return new Promise((res, rej) => { return new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("decryptGroupEncryption", {
{
action: "decryptGroupEncryption",
payload: {
data, data,
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return; return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) {} } catch (error) {}
}; };

View File

@ -24,12 +24,8 @@ export const ListOfThreadPostsWatched = () => {
const getPosts = async () => { const getPosts = async () => {
try { try {
await new Promise((res, rej) => { await new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("getThreadActivity", {})
{ .then((response) => {
action: "getThreadActivity",
payload: {},
},
(response) => {
if (!response?.error) { if (!response?.error) {
if (!response) { if (!response) {
res(null); res(null);
@ -50,8 +46,11 @@ export const ListOfThreadPostsWatched = () => {
return; return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
} catch (error) { } catch (error) {
} finally { } finally {

View File

@ -74,13 +74,13 @@ export const WebSocketActive = ({ myAddress, setIsLoadingGroups }) => {
).sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0)); ).sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0));
chrome?.runtime?.sendMessage({ window.sendMessage("handleActiveGroupDataFromSocket", {
action: 'handleActiveGroupDataFromSocket',
payload: {
groups: sortedGroups, groups: sortedGroups,
directs: sortedDirects, directs: sortedDirects,
}, }).catch((error) => {
console.error("Failed to handle active group data from socket:", error.message || "An error occurred");
}); });
} }
} catch (error) { } catch (error) {
console.error('Error parsing onmessage data:', error); console.error('Error parsing onmessage data:', error);

View File

@ -63,24 +63,22 @@ const [isLoading, setIsLoading] = useState(false)
setIsLoading(true); setIsLoading(true);
const avatarBase64 = await fileToBase64(avatarFile) const avatarBase64 = await fileToBase64(avatarFile)
await new Promise((res, rej) => { await new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishOnQDN", {
{
action: "publishOnQDN",
payload: {
data: avatarBase64, data: avatarBase64,
identifier: "qortal_avatar", identifier: "qortal_avatar",
service: 'THUMBNAIL' service: "THUMBNAIL",
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
setAvatarFile(null); setAvatarFile(null);
setTempAvatar(`data:image/webp;base64,${avatarBase64}`) setTempAvatar(`data:image/webp;base64,${avatarBase64}`)

View File

@ -87,24 +87,22 @@ export const Save = ({isDesktop}) => {
publishFee: fee.fee + ' QORT' publishFee: fee.fee + ' QORT'
}) })
const response = await new Promise((res, rej) => { const response = await new Promise((res, rej) => {
chrome?.runtime?.sendMessage( window.sendMessage("publishOnQDN", {
{
action: "publishOnQDN",
payload: {
data: encryptData, data: encryptData,
identifier: "ext_saved_settings", identifier: "ext_saved_settings",
service: 'DOCUMENT_PRIVATE' service: "DOCUMENT_PRIVATE",
}, })
}, .then((response) => {
(response) => {
if (!response?.error) { if (!response?.error) {
res(response); res(response);
return return;
} }
rej(response.error); rej(response.error);
} })
); .catch((error) => {
rej(error.message || "An error occurred");
});
}); });
if(response?.identifier){ if(response?.identifier){
setOldPinnedApps(pinnedApps) setOldPinnedApps(pinnedApps)