Skip to content

Commit

Permalink
Use properly fallback provider name
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Jul 24, 2023
1 parent 99c6292 commit 65b5b20
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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 (Lcom/google/firebase/messaging/RemoteMessage;)Z
public static final fun registerFirebaseToken (Ljava/lang/String;Ljava/lang/String;)V
public static synthetic fun registerFirebaseToken$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
}

public final class io/getstream/android/push/firebase/FirebasePushDeviceGenerator : io/getstream/android/push/PushDeviceGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class ChatFirebaseMessagingService : FirebaseMessagingService() {

override fun onNewToken(token: String) {
try {
FirebaseMessagingDelegate.registerFirebaseToken(token)
FirebaseMessagingDelegate.registerFirebaseToken(token, "")
} catch (exception: IllegalStateException) {
logger.e(exception) { "[onFirebaseNewToken] error while registering Firebase Token" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import io.getstream.android.push.delegate.PushDelegateProvider
*/
public object FirebaseMessagingDelegate {

internal lateinit var fallbackProviderName: String
internal var fallbackProviderName: String? = null

/**
* Handles [remoteMessage] from Firebase.
Expand All @@ -45,18 +45,23 @@ public object FirebaseMessagingDelegate {
* Register new Firebase Token.
*
* @param token provided by Firebase.
* @param providerName Optional name for the provider name.
* @param providerName The provider name.
*/
@JvmStatic
public fun registerFirebaseToken(
token: String,
providerName: String = fallbackProviderName,
providerName: String,
) {
val pushDevice = PushDevice(
token = token,
pushProvider = PushProvider.FIREBASE,
providerName = providerName,
)
PushDelegateProvider.delegates.forEach { it.registerPushDevice(pushDevice) }
(providerName.takeUnless { it.isBlank() } ?: fallbackProviderName)
?.let {
PushDevice(
token = token,
pushProvider = PushProvider.FIREBASE,
providerName = it,
)
}
?.let {
PushDelegateProvider.delegates.forEach { delegate -> delegate.registerPushDevice(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public final class io/getstream/android/push/huawei/HuaweiMessagingDelegate {
public static final field INSTANCE Lio/getstream/android/push/huawei/HuaweiMessagingDelegate;
public static final fun handleRemoteMessage (Lcom/huawei/hms/push/RemoteMessage;)Z
public static final fun registerHuaweiToken (Ljava/lang/String;Ljava/lang/String;)V
public static synthetic fun registerHuaweiToken$default (Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)V
}

public final class io/getstream/android/push/huawei/HuaweiPushDeviceGenerator : io/getstream/android/push/PushDeviceGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class ChatHuaweiMessagingService : HmsMessageService() {

override fun onNewToken(token: String) {
try {
HuaweiMessagingDelegate.registerHuaweiToken(token)
HuaweiMessagingDelegate.registerHuaweiToken(token, "")
} catch (exception: IllegalStateException) {
logger.e(exception) { "[onHuaweiNewToken] error while registering Huawei Token" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import kotlin.jvm.Throws
*/
public object HuaweiMessagingDelegate {

internal lateinit var fallbackProviderName: String
internal var fallbackProviderName: String? = null

/**
* Handles [remoteMessage] from Huawei.
Expand All @@ -47,19 +47,24 @@ public object HuaweiMessagingDelegate {
* Register new Huawei Token.
*
* @param token provided by Huawei.
* @param providerName Optional name for the provider name.
* @param providerName The provider name.
*/
@Throws(IllegalStateException::class)
@JvmStatic
public fun registerHuaweiToken(
token: String,
providerName: String = fallbackProviderName,
providerName: String,
) {
val pushDevice = PushDevice(
token = token,
pushProvider = PushProvider.HUAWEI,
providerName = providerName,
)
PushDelegateProvider.delegates.forEach { it.registerPushDevice(pushDevice) }
(providerName.takeUnless { it.isBlank() } ?: fallbackProviderName)
?.let {
PushDevice(
token = token,
pushProvider = PushProvider.HUAWEI,
providerName = it,
)
}
?.let {
PushDelegateProvider.delegates.forEach { delegate -> delegate.registerPushDevice(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public final class io/getstream/android/push/xiaomi/XiaomiMessagingDelegate {
public static final field INSTANCE Lio/getstream/android/push/xiaomi/XiaomiMessagingDelegate;
public static final fun handleMiPushMessage (Lcom/xiaomi/mipush/sdk/MiPushMessage;)Z
public static final fun registerXiaomiToken (Lcom/xiaomi/mipush/sdk/MiPushCommandMessage;Ljava/lang/String;)V
public static synthetic fun registerXiaomiToken$default (Lcom/xiaomi/mipush/sdk/MiPushCommandMessage;Ljava/lang/String;ILjava/lang/Object;)V
}

public final class io/getstream/android/push/xiaomi/XiaomiPushDeviceGenerator : io/getstream/android/push/PushDeviceGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class ChatXiaomiMessagingReceiver : PushMessageReceiver() {
override fun onReceiveRegisterResult(context: Context, miPushCommandMessage: MiPushCommandMessage) {
logger.d { "[onReceiveXiaomiRegisterResult] miPushCommandMessage: $miPushCommandMessage" }
try {
XiaomiMessagingDelegate.registerXiaomiToken(miPushCommandMessage)
XiaomiMessagingDelegate.registerXiaomiToken(miPushCommandMessage, "")
} catch (exception: IllegalStateException) {
logger.e(exception) { "[onReceiveRegisterResult] error while registering Xiaomi Token" }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import io.getstream.android.push.delegate.PushDelegateProvider
*/
public object XiaomiMessagingDelegate {

internal lateinit var fallbackProviderName: String
internal var fallbackProviderName: String? = null

private val mapAdapter: JsonAdapter<MutableMap<String, String>> by lazy {
Moshi.Builder()
Expand All @@ -56,24 +56,29 @@ public object XiaomiMessagingDelegate {
* Register new Xiaomi Token.
*
* @param miPushCommandMessage provided by Xiaomi.
* @param providerName Optional name for the provider name.
* @param providerName The provider name.
*/
@JvmStatic
public fun registerXiaomiToken(
miPushCommandMessage: MiPushCommandMessage,
providerName: String = fallbackProviderName,
providerName: String,
) {
miPushCommandMessage
.takeIf { it.command == MiPushClient.COMMAND_REGISTER }
?.commandArguments
?.get(0)
?.run {
val pushDevice = PushDevice(
token = this,
pushProvider = PushProvider.XIAOMI,
providerName = providerName,
)
PushDelegateProvider.delegates.forEach { it.registerPushDevice(pushDevice) }
(providerName.takeUnless { it.isBlank() } ?: fallbackProviderName)
?.let {
PushDevice(
token = this,
pushProvider = PushProvider.XIAOMI,
providerName = it,
)
}
?.let {
PushDelegateProvider.delegates.forEach { delegate -> delegate.registerPushDevice(it) }
}
}
}

Expand Down

0 comments on commit 65b5b20

Please sign in to comment.