Skip to content

Commit

Permalink
fix: ensure messages are only shown once (#281)
Browse files Browse the repository at this point in the history
Co-authored-by: Bernard Gatt <[email protected]>
  • Loading branch information
stephen-pope-customer-io and BernardGatt authored Jan 18, 2024
1 parent f1bfc22 commit f73e13f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import retrofit2.converter.gson.GsonConverterFactory
class Queue : GistListener {

private var localMessageStore: MutableList<Message> = mutableListOf()
private var shownMessageQueueIds = mutableSetOf<String>()

init {
GistSdk.addListener(this)
Expand Down Expand Up @@ -149,6 +150,11 @@ class Queue : GistListener {
}

private fun processMessage(message: Message) {
if (message.queueId != null && shownMessageQueueIds.contains(message.queueId)) {
Log.i(GIST_TAG, "Duplicate message ${message.queueId} skipped")
return
}

val gistProperties = GistMessageProperties.getGistProperties(message)
gistProperties.routeRule?.let { routeRule ->
try {
Expand Down Expand Up @@ -188,6 +194,7 @@ class Queue : GistListener {
GIST_TAG,
"Logging view for user message: ${message.messageId}, with queue id: ${message.queueId}"
)
shownMessageQueueIds.add(message.queueId)
removeMessageFromLocalStore(message)
gistQueueService.logUserMessageView(message.queueId)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ object GistSdk : Application.ActivityLifecycleCallbacks {
Log.e(GIST_TAG, "Failed to show message: ${e.message}", e)
}
}

return if (messageShown) message.instanceId else null
}

Expand Down

0 comments on commit f73e13f

Please sign in to comment.