Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce a de-dupe mechanism for push notifications #177

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.klaviyo.pushFcm.KlaviyoRemoteMessage.imageUrl
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.isKlaviyoNotification
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.notificationCount
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.notificationPriority
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.notificationTag
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.sound
import com.klaviyo.pushFcm.KlaviyoRemoteMessage.title
import java.net.URL
Expand Down Expand Up @@ -62,6 +63,7 @@ class KlaviyoNotification(private val message: RemoteMessage) {
internal const val COLOR_KEY = "color"
internal const val NOTIFICATION_COUNT_KEY = "notification_count"
internal const val NOTIFICATION_PRIORITY = "notification_priority"
internal const val NOTIFICATION_TAG = "notification_tag"
private const val DOWNLOAD_TIMEOUT_MS = 5_000

/**
Expand Down Expand Up @@ -104,7 +106,7 @@ class KlaviyoNotification(private val message: RemoteMessage) {

NotificationManagerCompat
.from(context)
.notify(generateId(), notification.build())
.notify(message.notificationTag, generateId(), notification.build())

return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ object KlaviyoRemoteMessage {
get() = this.data[KlaviyoNotification.NOTIFICATION_PRIORITY]?.toInt()
?: NotificationCompat.PRIORITY_DEFAULT

/**
* Parse out notification tag, used as a de-duping mechanism
*/
val RemoteMessage.notificationTag: String? get() = this.data[KlaviyoNotification.NOTIFICATION_TAG]

/**
* Determine if the message originated from Klaviyo from the tracking params
*/
Expand Down
Loading