refactor sendEventAsync, add action parameters

This commit is contained in:
qcrao
2024-07-25 15:36:50 +08:00
parent 123524c629
commit 300e1fb2c5
3 changed files with 7 additions and 5 deletions

View File

@@ -11,6 +11,8 @@ async function bulkArchiveConversations() {
console.log("Selected Conversations:", selectedConversations); console.log("Selected Conversations:", selectedConversations);
sendEventAsync("archive", selectedConversations.length);
for (const element of selectedConversations) { for (const element of selectedConversations) {
await archiveConversation(element); await archiveConversation(element);
} }

View File

@@ -14,7 +14,7 @@ async function bulkDeleteConversations() {
console.log("Selected Conversations:", selectedConversations.length); console.log("Selected Conversations:", selectedConversations.length);
sendEventAsync(selectedConversations.length); sendEventAsync("delete", selectedConversations.length);
for (let i = 0; i < selectedConversations.length; i++) { for (let i = 0; i < selectedConversations.length; i++) {
await deleteConversation(selectedConversations[i]); await deleteConversation(selectedConversations[i]);

View File

@@ -13,7 +13,7 @@ function getUserInfo() {
}); });
} }
async function sendEventAsync(count) { async function sendEventAsync(action, count) {
try { try {
const userInfo = await getUserInfo(); const userInfo = await getUserInfo();
const timestamp = new Date().toISOString().replace("T", " ").substr(0, 19); const timestamp = new Date().toISOString().replace("T", " ").substr(0, 19);
@@ -21,7 +21,7 @@ async function sendEventAsync(count) {
const data = { const data = {
user_id: userInfo.id || "unknown", user_id: userInfo.id || "unknown",
timestamp: timestamp, timestamp: timestamp,
action: "delete", action: action,
count: count, count: count,
}; };
@@ -40,8 +40,8 @@ async function sendEventAsync(count) {
throw new Error(`HTTP error! status: ${response.status}`); throw new Error(`HTTP error! status: ${response.status}`);
} }
console.log("Event sent successfully"); console.log(`Event '${action}' sent successfully`);
} catch (error) { } catch (error) {
console.error("Error sending event:", error); console.error(`Error sending '${action}' event:`, error);
} }
} }