From 0fb5826588c33758d34705286a81ec584d3ac8e7 Mon Sep 17 00:00:00 2001 From: Marek Stransky Date: Fri, 14 Jun 2024 11:20:23 +0200 Subject: [PATCH 1/3] Add inbox notification to parser --- docs/Using-Push-Service.md | 3 ++ .../android/mtokensdk/push/PushParser.kt | 46 ++++++++++++++----- library/src/test/java/PushTests.kt | 8 +++- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/docs/Using-Push-Service.md b/docs/Using-Push-Service.md index 8d56060..a1f3960 100644 --- a/docs/Using-Push-Service.md +++ b/docs/Using-Push-Service.md @@ -129,6 +129,9 @@ The `PushMessage` is an abstract class that is implemented by following classes - `name` of the operation - `result` of the operation (for example that the operation was canceled by the user). - `originalData` - data on which was the push message constructed +- `PushMessageInboxReceived` - a new inbox message was triggered with the id + - `id` of the message + - `originalData` - data on which was the push message constructed Example push notification processing: diff --git a/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt b/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt index c0c5576..5e6e409 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt @@ -26,7 +26,7 @@ class PushParser { /** * When you receive a push notification, you can test it here if it's a "WMT" notification. * - * Return type can be [PushMessageOperationCreated] or [PushMessageOperationFinished] + * Return type can be [PushMessageOperationCreated], [PushMessageOperationFinished] or [PushMessageInboxReceived] * * @param notificationData: data of received notification. * @return parsed known [PushMessage] or null @@ -34,21 +34,32 @@ class PushParser { @JvmStatic @JvmName("parseNotification") fun parseNotification(notificationData: Map): PushMessage? { + return when (notificationData["messageType"]) { + "mtoken.operationInit" -> parseOperationCreated(notificationData) + "mtoken.operationFinished" -> parseOperationFinished(notificationData) + "mtoken.inboxMessage.new" -> parseInboxMessageReceived(notificationData) + else -> null + } + } + // Helper methods + private fun parseOperationCreated(notificationData: Map): PushMessage? { val id = notificationData["operationId"] ?: return null val name = notificationData["operationName"] ?: return null + return PushMessageOperationCreated(id, name, notificationData) + } - return when (notificationData["messageType"]) { - "mtoken.operationInit" -> { - PushMessageOperationCreated(id, name, notificationData) - } - "mtoken.operationFinished" -> { - notificationData["mtokenOperationResult"]?.let { return PushMessageOperationFinished(id, name, PushMessageOperationFinished.parseResult(it), notificationData) } - } - else -> { - null - } - } + private fun parseOperationFinished(notificationData: Map): PushMessage? { + val id = notificationData["operationId"] ?: return null + val name = notificationData["operationName"] ?: return null + val result = notificationData["mtokenOperationResult"] ?: return null + val operationResult = PushMessageOperationFinished.parseResult(result) + return PushMessageOperationFinished(id, name, operationResult, notificationData) + } + + private fun parseInboxMessageReceived(notificationData: Map): PushMessage? { + val inboxId = notificationData["inboxId"] ?: return null + return PushMessageInboxReceived(inboxId, notificationData) } } } @@ -129,3 +140,14 @@ class PushMessageOperationFinished( } } } + +/** + * Created when a new inbox message was triggered. + */ +class PushMessageInboxReceived( + /** Id of the inbox message. */ + val id: String, + + /** Original data on which was the push message constructed. */ + originalData: Map +): PushMessage(originalData) diff --git a/library/src/test/java/PushTests.kt b/library/src/test/java/PushTests.kt index ac612ef..7504d95 100644 --- a/library/src/test/java/PushTests.kt +++ b/library/src/test/java/PushTests.kt @@ -102,11 +102,17 @@ class PushTests { Assert.assertNull(makePush("mtoken.operationFinished", "1", null, "authentication.success")) } - private fun makePush(type: String?, id: String?, name: String?, opResult: String?): PushMessage? { + @Test + fun `test inbox new message`() { + Assert.assertNotNull(makePush("mtoken.inboxMessage.new", null, null, null, "666")) + } + + private fun makePush(type: String?, id: String?, name: String?, opResult: String?, inboxId: String? = null): PushMessage? { val map = mutableMapOf() type?.let { map["messageType"] = it } id?.let { map["operationId"] = it } name?.let { map["operationName"] = it } + inboxId?.let { map["inboxId"] = it } opResult?.let { map["mtokenOperationResult"] = it } return PushParser.parseNotification(map) } From 5b76e830ceb48cfc925a7a2916fed81eda1635f1 Mon Sep 17 00:00:00 2001 From: Marek Stransky Date: Fri, 14 Jun 2024 11:41:41 +0200 Subject: [PATCH 2/3] Add explicitly if messageType is not present it will return null --- .../main/java/com/wultra/android/mtokensdk/push/PushParser.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt b/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt index 5e6e409..1a444ad 100644 --- a/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt +++ b/library/src/main/java/com/wultra/android/mtokensdk/push/PushParser.kt @@ -34,7 +34,9 @@ class PushParser { @JvmStatic @JvmName("parseNotification") fun parseNotification(notificationData: Map): PushMessage? { - return when (notificationData["messageType"]) { + val messageType = notificationData["messageType"] ?: return null + + return when (messageType) { "mtoken.operationInit" -> parseOperationCreated(notificationData) "mtoken.operationFinished" -> parseOperationFinished(notificationData) "mtoken.inboxMessage.new" -> parseInboxMessageReceived(notificationData) From 05ebe1772c5f8b9f7eda291d7f35233a7cc9e9af Mon Sep 17 00:00:00 2001 From: Marek Stransky Date: Thu, 20 Jun 2024 12:39:45 +0200 Subject: [PATCH 3/3] Add TBA 1.12.0. version to changelog --- docs/Changelog.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/Changelog.md b/docs/Changelog.md index cd4d2cc..4a6192f 100644 --- a/docs/Changelog.md +++ b/docs/Changelog.md @@ -1,5 +1,9 @@ # Changelog +## 1.12.0 (TBA) +- Extended PushParser to support parsing of inbox notifications [(#150)](https://github.com/wultra/mtoken-sdk-android/pull/150) +- Added statusReason to UserOperation [(#148)](https://github.com/wultra/mtoken-sdk-android/pull/148) + ## 1.11.0 (May, 2024) - Changed name of the log class to the `WMTLogger`