mirror of
https://github.com/bitwarden/android.git
synced 2024-10-31 07:05:35 +03:00
Add support for the FCMv1 format in push notifications (#1456)
This commit is contained in:
parent
dc633f0c0a
commit
6fd4be20e3
4 changed files with 679 additions and 44 deletions
|
@ -65,10 +65,17 @@ interface PushManager {
|
|||
val syncSendUpsertFlow: Flow<SyncSendUpsertData>
|
||||
|
||||
/**
|
||||
* Handles the necessary steps to take when a push notification with payload [data] is received.
|
||||
* Handles the necessary steps to take when a push notification with a legacy FCM [data]
|
||||
* payload is received.
|
||||
*/
|
||||
fun onMessageReceived(data: String)
|
||||
|
||||
/**
|
||||
* Handles the necessary steps to take when a push notification with FCM v1 payload is
|
||||
* received.
|
||||
*/
|
||||
fun onMessageReceived(data: Map<String, String>)
|
||||
|
||||
/**
|
||||
* Registers a [token] for the current user with Bitwarden's server if needed.
|
||||
*/
|
||||
|
|
|
@ -106,14 +106,34 @@ class PushManagerImpl @Inject constructor(
|
|||
.launchIn(unconfinedScope)
|
||||
}
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod", "ReturnCount")
|
||||
override fun onMessageReceived(data: String) {
|
||||
val notification = try {
|
||||
json.decodeFromString<BitwardenNotification>(data)
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
return
|
||||
}
|
||||
onMessageReceived(notification)
|
||||
}
|
||||
|
||||
@Suppress("ReturnCount")
|
||||
override fun onMessageReceived(data: Map<String, String>) {
|
||||
val type = data["type"] ?: return
|
||||
val payload = data["payload"] ?: return
|
||||
val notificationType = try {
|
||||
json.decodeFromString<NotificationType>(string = type)
|
||||
} catch (exception: IllegalArgumentException) {
|
||||
return
|
||||
}
|
||||
val notification = BitwardenNotification(
|
||||
contextId = data["contextId"],
|
||||
notificationType = notificationType,
|
||||
payload = payload,
|
||||
)
|
||||
onMessageReceived(notification)
|
||||
}
|
||||
|
||||
@Suppress("LongMethod", "CyclomaticComplexMethod", "ReturnCount")
|
||||
private fun onMessageReceived(notification: BitwardenNotification) {
|
||||
if (authDiskSource.uniqueAppId == notification.contextId) return
|
||||
|
||||
val userId = activeUserId ?: return
|
||||
|
|
|
@ -17,8 +17,10 @@ class BitwardenFirebaseMessagingService : FirebaseMessagingService() {
|
|||
lateinit var pushManager: PushManager
|
||||
|
||||
override fun onMessageReceived(message: RemoteMessage) {
|
||||
val data = message.data["data"] ?: return
|
||||
pushManager.onMessageReceived(data)
|
||||
message
|
||||
.data["data"]
|
||||
?.let { pushManager.onMessageReceived(it) }
|
||||
?: pushManager.onMessageReceived(message.data)
|
||||
}
|
||||
|
||||
override fun onNewToken(token: String) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue