Skip to content

Commit

Permalink
[in-app-broadcast] hide anonymous message if user dismisses it (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
karngyan authored Oct 18, 2024
2 parents 7831bb7 + 80f8c77 commit 3429e9d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/managers/message-broadcast-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,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);
Expand Down
10 changes: 9 additions & 1 deletion src/managers/message-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ async function handleGistEvents(e) {
case "close":
await hideMessage(currentMessage);
await removePersistentMessage(currentMessage);
await logBroadcastDismissedLocally(currentMessage);
await checkMessageQueue();
break;
case "showMessage":
Expand Down Expand Up @@ -302,4 +303,11 @@ async function logUserMessageViewLocally(message) {
} else {
await markUserQueueMessageAsSeen(message.queueId);
}
}
}

async function logBroadcastDismissedLocally(message) {
if (isMessageBroadcast(message)) {
log(`Logging broadcast dismissed locally for: ${message.queueId}`);
await markBroadcastAsDismissed(message.queueId);
}
}

0 comments on commit 3429e9d

Please sign in to comment.