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, getLTCBalance,
getNameInfo, getNameInfo,
getTempPublish, getTempPublish,
getTimestampEnterChat,
getTimestampGroupAnnouncement,
getUserInfo, getUserInfo,
getUserSettings, getUserSettings,
inviteToGroup, inviteToGroup,
@ -1037,4 +1039,57 @@ export async function balanceCase(request, event) {
event.origin 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, getCustomNodesFromStorageCase,
getDataPublishesCase, getDataPublishesCase,
getGroupDataSingleCase, getGroupDataSingleCase,
getGroupNotificationTimestampCase,
getTempPublishCase, getTempPublishCase,
getTimestampEnterChatCase,
getUserSettingsCase, getUserSettingsCase,
getWalletInfoCase, getWalletInfoCase,
inviteToGroupCase, inviteToGroupCase,
@ -2734,7 +2736,7 @@ async function setChatHeadsDirect(data) {
}); });
} }
async function getTimestampEnterChat() { export async function getTimestampEnterChat() {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
const key = `enter-chat-timestamp-${address}`; const key = `enter-chat-timestamp-${address}`;
@ -2746,7 +2748,7 @@ async function getTimestampEnterChat() {
return {}; return {};
} }
} }
async function getTimestampGroupAnnouncement() { export async function getTimestampGroupAnnouncement() {
const wallet = await getSaveWallet(); const wallet = await getSaveWallet();
const address = wallet.address0; const address = wallet.address0;
const key = `group-announcement-${address}`; const key = `group-announcement-${address}`;
@ -3030,6 +3032,12 @@ function setupMessageListener() {
case "getGroupDataSingle": case "getGroupDataSingle":
getGroupDataSingleCase(request, event); getGroupDataSingleCase(request, event);
break; break;
case "getTimestampEnterChat":
getTimestampEnterChatCase(request, event);
break;
case "getGroupNotificationTimestamp":
getGroupNotificationTimestampCase(request, event);
break;
default: default:
console.error("Unknown action:", request.action); console.error("Unknown action:", request.action);
} }

View File

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