From 300e1fb2c546f3d3c446bd9de8e82495721c2ca7 Mon Sep 17 00:00:00 2001 From: qcrao Date: Thu, 25 Jul 2024 15:36:50 +0800 Subject: [PATCH] refactor sendEventAsync, add action parameters --- bulkArchiveConversations.js | 2 ++ bulkDeleteConversations.js | 2 +- utils.js | 8 ++++---- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bulkArchiveConversations.js b/bulkArchiveConversations.js index 292e58f..0b2cea4 100644 --- a/bulkArchiveConversations.js +++ b/bulkArchiveConversations.js @@ -11,6 +11,8 @@ async function bulkArchiveConversations() { console.log("Selected Conversations:", selectedConversations); + sendEventAsync("archive", selectedConversations.length); + for (const element of selectedConversations) { await archiveConversation(element); } diff --git a/bulkDeleteConversations.js b/bulkDeleteConversations.js index c2bc5a4..95507dd 100644 --- a/bulkDeleteConversations.js +++ b/bulkDeleteConversations.js @@ -14,7 +14,7 @@ async function bulkDeleteConversations() { console.log("Selected Conversations:", selectedConversations.length); - sendEventAsync(selectedConversations.length); + sendEventAsync("delete", selectedConversations.length); for (let i = 0; i < selectedConversations.length; i++) { await deleteConversation(selectedConversations[i]); diff --git a/utils.js b/utils.js index 88131e1..b4ef3bd 100644 --- a/utils.js +++ b/utils.js @@ -13,7 +13,7 @@ function getUserInfo() { }); } -async function sendEventAsync(count) { +async function sendEventAsync(action, count) { try { const userInfo = await getUserInfo(); const timestamp = new Date().toISOString().replace("T", " ").substr(0, 19); @@ -21,7 +21,7 @@ async function sendEventAsync(count) { const data = { user_id: userInfo.id || "unknown", timestamp: timestamp, - action: "delete", + action: action, count: count, }; @@ -40,8 +40,8 @@ async function sendEventAsync(count) { throw new Error(`HTTP error! status: ${response.status}`); } - console.log("Event sent successfully"); + console.log(`Event '${action}' sent successfully`); } catch (error) { - console.error("Error sending event:", error); + console.error(`Error sending '${action}' event:`, error); } }