This commit is contained in:
PhilReact 2024-10-28 13:32:50 +02:00
parent c9055e4b68
commit 4d570068ef
3 changed files with 90 additions and 25 deletions

View File

@ -19,6 +19,8 @@ import {
getLTCBalance,
getNameInfo,
getTempPublish,
getTimestampEnterChat,
getTimestampGroupAnnouncement,
getUserInfo,
getUserSettings,
inviteToGroup,
@ -1037,4 +1039,57 @@ export async function balanceCase(request, event) {
event.origin
);
}
}
export async function getTimestampEnterChatCase(request, event) {
try {
const response = await getTimestampEnterChat();
event.source.postMessage(
{
requestId: request.requestId,
action: "getTimestampEnterChat",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "getTimestampEnterChat",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}
export async function getGroupNotificationTimestampCase(request, event) {
try {
const response = await getTimestampGroupAnnouncement();
event.source.postMessage(
{
requestId: request.requestId,
action: "getGroupNotificationTimestamp",
payload: response,
type: "backgroundMessageResponse",
},
event.origin
);
} catch (error) {
event.source.postMessage(
{
requestId: request.requestId,
action: "getGroupNotificationTimestamp",
error: error?.message,
type: "backgroundMessageResponse",
},
event.origin
);
}
}

View File

@ -44,7 +44,9 @@ import {
getCustomNodesFromStorageCase,
getDataPublishesCase,
getGroupDataSingleCase,
getGroupNotificationTimestampCase,
getTempPublishCase,
getTimestampEnterChatCase,
getUserSettingsCase,
getWalletInfoCase,
inviteToGroupCase,
@ -2734,7 +2736,7 @@ async function setChatHeadsDirect(data) {
});
}
async function getTimestampEnterChat() {
export async function getTimestampEnterChat() {
const wallet = await getSaveWallet();
const address = wallet.address0;
const key = `enter-chat-timestamp-${address}`;
@ -2746,7 +2748,7 @@ async function getTimestampEnterChat() {
return {};
}
}
async function getTimestampGroupAnnouncement() {
export async function getTimestampGroupAnnouncement() {
const wallet = await getSaveWallet();
const address = wallet.address0;
const key = `group-announcement-${address}`;
@ -3030,6 +3032,12 @@ function setupMessageListener() {
case "getGroupDataSingle":
getGroupDataSingleCase(request, event);
break;
case "getTimestampEnterChat":
getTimestampEnterChatCase(request, event);
break;
case "getGroupNotificationTimestamp":
getGroupNotificationTimestampCase(request, event);
break;
default:
console.error("Unknown action:", request.action);
}

View File

@ -503,18 +503,19 @@ export const Group = ({
const getTimestampEnterChat = async () => {
try {
return new Promise((res, rej) => {
chrome?.runtime?.sendMessage(
{
action: "getTimestampEnterChat",
},
(response) => {
if (!response?.error) {
setTimestampEnterData(response);
res(response);
}
rej(response.error);
}
);
window.sendMessage("getTimestampEnterChat")
.then((response) => {
if (!response?.error) {
setTimestampEnterData(response);
res(response);
return;
}
rej(response.error);
})
.catch((error) => {
rej(error.message || "An error occurred");
});
});
} catch (error) {}
};
@ -550,18 +551,19 @@ export const Group = ({
const getGroupAnnouncements = async () => {
try {
return new Promise((res, rej) => {
chrome?.runtime?.sendMessage(
{
action: "getGroupNotificationTimestamp",
},
(response) => {
if (!response?.error) {
setGroupAnnouncements(response);
res(response);
}
rej(response.error);
window.sendMessage("getGroupNotificationTimestamp")
.then((response) => {
if (!response?.error) {
setGroupAnnouncements(response);
res(response);
return;
}
);
rej(response.error);
})
.catch((error) => {
rej(error.message || "An error occurred");
});
});
} catch (error) {}
};