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

[AND-209] Revert public api changes. #25

Merged
merged 1 commit into from
Jan 20, 2025
Merged
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
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[versions]
activityKtx = "1.8.0"
firebaseMessaging = "2.1.0"
firebaseMessagingVersion = "23.3.1"
kotlinxCoroutinesCore = "1.9.0"
startupRuntime = "1.1.1"
Expand Down Expand Up @@ -38,7 +37,6 @@ mockitoKotlin = "4.1.0"
[libraries]
androidx-startup-runtime = { module = "androidx.startup:startup-runtime", version.ref = "startupRuntime" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "activityKtx" }
firebase-messaging = { module = "dev.gitlive:firebase-messaging", version.ref = "firebaseMessaging" }
google-firebase-messaging = { module = "com.google.firebase:firebase-messaging", version.ref = "firebaseMessagingVersion" }
stream-log = { group = "io.getstream", name = "stream-log", version.ref = "streamLog" }
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppCompat" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
public final class io/getstream/android/push/firebase/FirebaseMessagingDelegate {
public static final field INSTANCE Lio/getstream/android/push/firebase/FirebaseMessagingDelegate;
public static final fun handleRemoteMessage (Lio/getstream/android/push/firebase/StreamRemoteMessage;)Z
public static final fun handleRemoteMessage (Lcom/google/firebase/messaging/RemoteMessage;)Z
public static final fun registerFirebaseToken (Ljava/lang/String;Ljava/lang/String;)V
}

public final class io/getstream/android/push/firebase/FirebasePushDeviceGenerator : io/getstream/android/push/PushDeviceGenerator {
public fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;)V
public fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;)V
public fun generatePushDevice (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun <init> (Lcom/google/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Landroid/content/Context;)V
public synthetic fun <init> (Lcom/google/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Landroid/content/Context;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Landroid/content/Context;)V
public fun asyncGeneratePushDevice (Lkotlin/jvm/functions/Function1;)V
public fun isValidForThisDevice ()Z
public fun onPushDeviceGeneratorSelected ()V
}

public final class io/getstream/android/push/firebase/StreamRemoteMessage {
public fun <init> (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIII)V
public final fun component1 ()Ljava/util/Map;
public final fun component10 ()I
public final fun component11 ()I
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/lang/String;
public final fun component6 ()Ljava/lang/String;
public final fun component7 ()Ljava/lang/String;
public final fun component8 ()J
public final fun component9 ()I
public final fun copy (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIII)Lio/getstream/android/push/firebase/StreamRemoteMessage;
public static synthetic fun copy$default (Lio/getstream/android/push/firebase/StreamRemoteMessage;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIIIILjava/lang/Object;)Lio/getstream/android/push/firebase/StreamRemoteMessage;
public fun equals (Ljava/lang/Object;)Z
public final fun getCollapseKey ()Ljava/lang/String;
public final fun getData ()Ljava/util/Map;
public final fun getFrom ()Ljava/lang/String;
public final fun getMessageId ()Ljava/lang/String;
public final fun getMessageType ()Ljava/lang/String;
public final fun getOriginalPriority ()I
public final fun getPriority ()I
public final fun getSenderId ()Ljava/lang/String;
public final fun getSentTime ()J
public final fun getTo ()Ljava/lang/String;
public final fun getTtl ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

Original file line number Diff line number Diff line change
@@ -1,47 +0,0 @@
public final class io/getstream/android/push/firebase/FirebaseMessagingDelegate {
public static final field INSTANCE Lio/getstream/android/push/firebase/FirebaseMessagingDelegate;
public static final fun handleRemoteMessage (Lio/getstream/android/push/firebase/StreamRemoteMessage;)Z
public static final fun registerFirebaseToken (Ljava/lang/String;Ljava/lang/String;)V
}

public final class io/getstream/android/push/firebase/FirebasePushDeviceGenerator : io/getstream/android/push/PushDeviceGenerator {
public fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;)V
public fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Ldev/gitlive/firebase/messaging/FirebaseMessaging;Ljava/lang/String;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;)V
public fun generatePushDevice (Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun isValidForThisDevice ()Z
public fun onPushDeviceGeneratorSelected ()V
}

public final class io/getstream/android/push/firebase/StreamRemoteMessage {
public fun <init> (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIII)V
public final fun component1 ()Ljava/util/Map;
public final fun component10 ()I
public final fun component11 ()I
public final fun component2 ()Ljava/lang/String;
public final fun component3 ()Ljava/lang/String;
public final fun component4 ()Ljava/lang/String;
public final fun component5 ()Ljava/lang/String;
public final fun component6 ()Ljava/lang/String;
public final fun component7 ()Ljava/lang/String;
public final fun component8 ()J
public final fun component9 ()I
public final fun copy (Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIII)Lio/getstream/android/push/firebase/StreamRemoteMessage;
public static synthetic fun copy$default (Lio/getstream/android/push/firebase/StreamRemoteMessage;Ljava/util/Map;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;JIIIILjava/lang/Object;)Lio/getstream/android/push/firebase/StreamRemoteMessage;
public fun equals (Ljava/lang/Object;)Z
public final fun getCollapseKey ()Ljava/lang/String;
public final fun getData ()Ljava/util/Map;
public final fun getFrom ()Ljava/lang/String;
public final fun getMessageId ()Ljava/lang/String;
public final fun getMessageType ()Ljava/lang/String;
public final fun getOriginalPriority ()I
public final fun getPriority ()I
public final fun getSenderId ()Ljava/lang/String;
public final fun getSentTime ()J
public final fun getTo ()Ljava/lang/String;
public final fun getTtl ()I
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

2 changes: 0 additions & 2 deletions stream-android-push-firebase/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ kotlin {
dependencies {
api(project(":stream-android-push"))
implementation(project(":stream-android-push-delegate"))

api(libs.firebase.messaging)
implementation(libs.kotlinx.coroutines)
implementation(libs.stream.log)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2022 Stream.io Inc. All rights reserved.
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
Expand All @@ -25,7 +25,7 @@ internal class ChatFirebaseMessagingService : FirebaseMessagingService() {
override fun onMessageReceived(remoteMessage: RemoteMessage) {
logger.d { "[onFirebaseMessageReceived] remoteMessage: $remoteMessage" }
try {
FirebaseMessagingDelegate.handleRemoteMessage(remoteMessage.toStreamRemoteMessage())
FirebaseMessagingDelegate.handleRemoteMessage(remoteMessage)
.also {
when (it) {
true -> logger.d { "[onFirebaseMessageReceived] message handled successfully" }
Expand All @@ -47,19 +47,3 @@ internal class ChatFirebaseMessagingService : FirebaseMessagingService() {
}
}
}

private fun RemoteMessage.toStreamRemoteMessage(): StreamRemoteMessage {
return StreamRemoteMessage(
data = data,
senderId = senderId,
from = from,
to = to,
messageType = messageType,
messageId = messageId,
collapseKey = collapseKey,
sentTime = sentTime,
ttl = ttl,
priority = priority,
originalPriority = originalPriority
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2022 Stream.io Inc. All rights reserved.
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
Expand All @@ -15,41 +15,41 @@
*/
package io.getstream.android.push.firebase

import com.google.firebase.messaging.RemoteMessage
import io.getstream.android.push.PushDevice
import io.getstream.android.push.PushProvider
import io.getstream.android.push.delegate.PushDelegateProvider
import io.getstream.log.StreamLog
import kotlin.jvm.JvmStatic

/**
* Helper class for delegating Firebase push messages to the Stream Chat SDK.
*/
public object FirebaseMessagingDelegate {

internal var fallbackProviderName: String? = null
private val logger = StreamLog.getLogger("Push:Firebase")

/**
* Handles [streamRemoteMessage] from Firebase.
* If the [streamRemoteMessage] wasn't sent from the Stream Server and doesn't contain the needed data,
* Handles [remoteMessage] from Firebase.
* If the [remoteMessage] wasn't sent from the Stream Server and doesn't contain the needed data,
* return false to notify you that this remoteMessage needs to be handled by you.
*
* @param streamRemoteMessage The message to be handled.
* @return True if the [streamRemoteMessage] was sent from the Stream Server and has been handled.
* @param remoteMessage The message to be handled.
* @return True if the [remoteMessage] was sent from the Stream Server and has been handled.
*/
@JvmStatic
public fun handleRemoteMessage(streamRemoteMessage: StreamRemoteMessage): Boolean {
logger.d { "[handleRemoteMessage] handling remote message: $streamRemoteMessage" }
public fun handleRemoteMessage(remoteMessage: RemoteMessage): Boolean {
logger.d { "[handleRemoteMessage] handling remote message: $remoteMessage" }
return PushDelegateProvider.delegates.any { pushDelegate ->
pushDelegate.handlePushMessage(
metadata = streamRemoteMessage.extractMetadata(),
payload = streamRemoteMessage.data
metadata = remoteMessage.extractMetadata(),
payload = remoteMessage.data
).also { handled ->
if (handled) logger.d { "[handleRemoteMessage] message handled successfully by $pushDelegate" }
}
}.also { handled ->
if (!handled) logger.d { "[handleRemoteMessage] message was not handled by any Push Delete" }
}
.also { handled ->
if (!handled) logger.d { "[handleRemoteMessage] message was not handled by any Push Delegate" }
}
}

/**
Expand All @@ -76,7 +76,7 @@ public object FirebaseMessagingDelegate {
}
}

private fun StreamRemoteMessage.extractMetadata(): Map<String, Any> {
private fun RemoteMessage.extractMetadata(): Map<String, Any> {
return hashMapOf<String, Any>().apply {
senderId?.also { put("firebase.sender_id", it) }
from?.also { put("firebase.from", it) }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2014-2025 Stream.io Inc. All rights reserved.
*
* Licensed under the Stream License;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://github.com/GetStream/stream-android-push/blob/main/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.getstream.android.push.firebase

import android.content.Context
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailabilityLight
import com.google.firebase.messaging.FirebaseMessaging
import io.getstream.android.push.PushDevice
import io.getstream.android.push.PushDeviceGenerator
import io.getstream.android.push.PushProvider
import io.getstream.log.StreamLog

/**
* Generator responsible for providing information needed to register Firebase push notifications provider
*
* @param firebaseMessaging The [FirebaseMessaging] instance used for retrieving the token.
* @param providerName The push provider name.
* @param context The context used to check if Firebase is available on this device.
*/
public class FirebasePushDeviceGenerator @JvmOverloads constructor(
private val firebaseMessaging: FirebaseMessaging = FirebaseMessaging.getInstance(),
private val providerName: String,
private val context: Context
) : PushDeviceGenerator {

private val logger = StreamLog.getLogger("Push:Firebase")

override fun isValidForThisDevice(): Boolean {
val isValidForThisDevice =
GoogleApiAvailabilityLight.getInstance().isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS
logger.i { "Is Firebase available on on this device -> $isValidForThisDevice" }
return isValidForThisDevice
}

override fun onPushDeviceGeneratorSelected() {
FirebaseMessagingDelegate.fallbackProviderName = providerName
}

override fun asyncGeneratePushDevice(onPushDeviceGenerated: (pushDevice: PushDevice) -> Unit) {
logger.i { "Getting Firebase token" }
firebaseMessaging.token.addOnCompleteListener {
if (it.isSuccessful) {
logger.i { "Firebase returned token successfully" }
onPushDeviceGenerated(
PushDevice(
token = it.result,
pushProvider = PushProvider.FIREBASE,
providerName = providerName
)
)
} else {
logger.i { "Error: Firebase didn't returned token" }
}
}
}
}

This file was deleted.

This file was deleted.

Loading
Loading