From e818c4ff013e823bef0f767a52af26d7ee972681 Mon Sep 17 00:00:00 2001 From: Karn Date: Thu, 17 Oct 2024 18:13:14 +0530 Subject: [PATCH] hide broadcast if user dismisses it --- src/managers/message-broadcast-manager.js | 13 +++++++++++++ src/managers/message-manager.js | 10 +++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/managers/message-broadcast-manager.js b/src/managers/message-broadcast-manager.js index b0e3379..284a9b8 100644 --- a/src/managers/message-broadcast-manager.js +++ b/src/managers/message-broadcast-manager.js @@ -54,6 +54,19 @@ export async function markBroadcastAsSeen(broadcastId) { } } +export async function markBroadcastAsDismissed(broadcastId) { + log(`Marking broadcast ${broadcastId} as dismissed.`); + const messageBroadcastLocalStoreName = await getMessageBroadcastLocalStoreName(); + if (!messageBroadcastLocalStoreName) return; + + const broadcast = await fetchMessageBroadcast(messageBroadcastLocalStoreName, broadcastId); + if (!broadcast) return; + + const broadcastShouldShowLocalStoreName = getBroadcastShouldShowLocalStoreName(messageBroadcastLocalStoreName, broadcastId); + setKeyToLocalStore(broadcastShouldShowLocalStoreName, false); + log(`Marked broadcast ${broadcastId} as dismissed and will not show again.`); +} + async function fetchMessageBroadcast(messageBroadcastLocalStoreName, broadcastId) { const broadcasts = getKeyFromLocalStore(messageBroadcastLocalStoreName); return broadcasts.find(message => message.queueId === broadcastId); diff --git a/src/managers/message-manager.js b/src/managers/message-manager.js index a28358f..e8ed14b 100644 --- a/src/managers/message-manager.js +++ b/src/managers/message-manager.js @@ -230,6 +230,7 @@ async function handleGistEvents(e) { case "close": await hideMessage(currentMessage); await removePersistentMessage(currentMessage); + await logBroadcastDismissedLocally(currentMessage); await checkMessageQueue(); break; case "showMessage": @@ -302,4 +303,11 @@ async function logUserMessageViewLocally(message) { } else { await markUserQueueMessageAsSeen(message.queueId); } -} \ No newline at end of file +} + +async function logBroadcastDismissedLocally(message) { + if (isMessageBroadcast(message)) { + log(`Logging broadcast dismissed locally for: ${message.queueId}`); + await markBroadcastAsDismissed(message.queueId); + } +}