From 205eceee2101a6721eb21407d88f40a5910c02c2 Mon Sep 17 00:00:00 2001 From: Alexandre Jacinto Date: Wed, 13 Dec 2023 10:23:47 +0000 Subject: [PATCH] fix: check if intent comes from FCM (#81) References: https://outsystemsrd.atlassian.net/browse/RMET-3013 --- CHANGELOG.md | 3 +++ package.json | 2 +- plugin.xml | 2 +- .../cloudmessaging/OSFirebaseCloudMessaging.kt | 14 +++++++++++++- .../firebase/cloudmessaging/build.gradle | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bfe7502f..80da22ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 The changes documented here do not include those from the original repository. +## [Version 2.0.1] +- Fix: Only deal with intents from the plugin (https://outsystemsrd.atlassian.net/browse/RMET-3013) + ## [Version 2.0.0] - Feat: update sound hook to unzip sound files, for both iOS and Android (https://outsystemsrd.atlassian.net/browse/RMET-2464). - Feat: update firebase core version (https://outsystemsrd.atlassian.net/browse/RMET-2451). diff --git a/package.json b/package.json index ed50a977..efcf2790 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.outsystems.firebase.cloudmessaging", - "version": "2.0.0", + "version": "2.0.1", "description": "Outsystems plugin for Firebase Cloud Messaging", "keywords": [ "ecosystem:cordova", diff --git a/plugin.xml b/plugin.xml index 9978e50c..685b8bc6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - + OSFirebaseCloudMessaging Outsystems plugin for Firebase Cloud Messaging OutSystems Inc diff --git a/src/android/com/outsystems/firebase/cloudmessaging/OSFirebaseCloudMessaging.kt b/src/android/com/outsystems/firebase/cloudmessaging/OSFirebaseCloudMessaging.kt index f180a0d5..51787054 100755 --- a/src/android/com/outsystems/firebase/cloudmessaging/OSFirebaseCloudMessaging.kt +++ b/src/android/com/outsystems/firebase/cloudmessaging/OSFirebaseCloudMessaging.kt @@ -37,6 +37,8 @@ class OSFirebaseCloudMessaging : CordovaImplementation() { private const val ERROR_FORMAT_PREFIX = "OS-PLUG-FCMS-" private const val NOTIFICATION_PERMISSION_REQUEST_CODE = 123123 private const val NOTIFICATION_PERMISSION_SEND_LOCAL_REQUEST_CODE = 987987 + const val FCM_EXPLICIT_NOTIFICATION = "com.outsystems.fcm.notification" + const val GOOGLE_MESSAGE_ID = "google.message_id" } override fun initialize(cordova: CordovaInterface, webView: CordovaWebView) { @@ -60,8 +62,18 @@ class OSFirebaseCloudMessaging : CordovaImplementation() { private fun handleIntent(intent: Intent) { val extras = intent.extras val extrasSize = extras?.size() ?: 0 + + // Check if intent comes from an FCM notification. If not, we don't want to handle it + // This is necessary so that we don't mistakenly deal with deep links thinking they're FCM notification clicks + val googleMessageId = extras?.getString(GOOGLE_MESSAGE_ID) // for notifications automatically delivered by the FCM SDK + val fcmInternal = extras?.getString(FCM_EXPLICIT_NOTIFICATION) // for notifications that we explicitly deliver in the FCM plugin + + if (googleMessageId.isNullOrEmpty() && fcmInternal.isNullOrEmpty()) { + return + } + if(extrasSize > 0) { - val scheme = extras?.getString(FirebaseMessagingOnActionClickActivity.ACTION_DEEP_LINK_SCHEME) + val scheme = extras.getString(FirebaseMessagingOnActionClickActivity.ACTION_DEEP_LINK_SCHEME) if (scheme.isNullOrEmpty()) { FirebaseMessagingOnClickActivity.notifyClickNotification(intent) } diff --git a/src/android/com/outsystems/firebase/cloudmessaging/build.gradle b/src/android/com/outsystems/firebase/cloudmessaging/build.gradle index eba5e4f1..ce4bf857 100644 --- a/src/android/com/outsystems/firebase/cloudmessaging/build.gradle +++ b/src/android/com/outsystems/firebase/cloudmessaging/build.gradle @@ -23,7 +23,7 @@ apply plugin: 'kotlin-kapt' dependencies { implementation("com.github.outsystems:oscore-android:1.2.0@aar") implementation("com.github.outsystems:oscordova-android:1.2.0@aar") - implementation("com.github.outsystems:osfirebasemessaging-android:1.1.3@aar") + implementation("com.github.outsystems:osfirebasemessaging-android:1.1.5@aar") implementation("com.github.outsystems:oslocalnotifications-android:1.0.0@aar") implementation("com.github.outsystems:osnotificationpermissions-android:0.0.4@aar")