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

💡 Suggestion: Avoid third-party model dependency #38

Open
gustavo-pedreros opened this issue Jan 18, 2024 · 0 comments
Open

💡 Suggestion: Avoid third-party model dependency #38

gustavo-pedreros opened this issue Jan 18, 2024 · 0 comments

Comments

@gustavo-pedreros
Copy link

gustavo-pedreros commented Jan 18, 2024

🗒️ Context

I think an SDK must reduce the dependencies with another dependencies. It is a good idea to avoid usage of RemoteMessage in braze functions inside BrazeFirebaseMessagingService. I mean is better to just pass what you are going to use.

😭 My problem

In my case, I'm using this library as a component that belong to my background message layer. My problem is the way that you use a firebase model force me to include firebase in my Braze component.

🧰 Example of potencial improvements:

Function: isBrazePushNotification

fun isBrazePushNotification(remoteMessage: RemoteMessage): Boolean {
    val remoteMessageData = remoteMessage.data
    return "true" == remoteMessageData[Constants.BRAZE_PUSH_BRAZE_KEY]
}

💡 Suggestion:

fun isBrazePushNotification(data: Map<String, String>): Boolean {
    return "true" == data[Constants.BRAZE_PUSH_BRAZE_KEY]
}

Function: handleBrazeRemoteMessage

fun handleBrazeRemoteMessage(context: Context, remoteMessage: RemoteMessage): Boolean {
    if (!isBrazePushNotification(remoteMessage)) {
        brazelog(I) { "Remote message did not originate from Braze. Not consuming remote message: $remoteMessage" }
        return false
    }
    val remoteMessageData = remoteMessage.data
    brazelog(I) { "Got remote message from FCM: $remoteMessageData" }
    val pushIntent = Intent(BrazePushReceiver.FIREBASE_MESSAGING_SERVICE_ROUTING_ACTION)
    val bundle = Bundle()
    for ((key, value) in remoteMessageData) {
        brazelog(V) { "Adding bundle item from FCM remote data with key: $key and value: $value" }
        bundle.putString(key, value)
    }
    pushIntent.putExtras(bundle)
    BrazePushReceiver.handleReceivedIntent(context, pushIntent)
    return true
}

💡 Suggestion:

fun handleBrazeRemoteMessage(context: Context, data: Map<String, String>): Boolean {
    if (!isBrazePushNotification(data)) {
        brazelog(I) { "Remote message did not originate from Braze. Not consuming remote message: $remoteMessage" }
        return false
    }
    brazelog(I) { "Got remote message from FCM: $data" }
    val pushIntent = Intent(BrazePushReceiver.FIREBASE_MESSAGING_SERVICE_ROUTING_ACTION)
    val bundle = Bundle()
    for ((key, value) in data) {
        brazelog(V) { "Adding bundle item from FCM remote data with key: $key and value: $value" }
        bundle.putString(key, value)
    }
    pushIntent.putExtras(bundle)
    BrazePushReceiver.handleReceivedIntent(context, pushIntent)
    return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant