diff --git a/android/build.gradle b/android/build.gradle index 0f460c2..b82e191 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -31,7 +31,7 @@ android { } dependencies { - def mmVersion = '13.2.3' + def mmVersion = '13.4.0' //flutter and mm dependencies clash implementation ("org.jetbrains.kotlin:kotlin-stdlib-jdk8") { version { diff --git a/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/chat/ChatPlatformView.java b/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/chat/ChatPlatformView.java index 85fa3fa..a04948e 100644 --- a/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/chat/ChatPlatformView.java +++ b/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/chat/ChatPlatformView.java @@ -20,6 +20,7 @@ import org.infobip.mobile.messaging.chat.view.InAppChatFragment; import org.infobip.plugins.mobilemessaging.flutter.common.ErrorCodes; import org.infobip.plugins.mobilemessaging.flutter.common.StreamHandler; +import org.infobip.mobile.messaging.chat.core.MultithreadStrategy; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -156,11 +157,11 @@ private void setLanguage(MethodCall call, final MethodChannel.Result result) { private void sendContextualData(MethodCall call, final MethodChannel.Result result) { if (fragment != null && fragment.isAdded()) { String data = call.argument("data"); - Boolean allMultiThreadStrategy = call.argument("allMultiThreadStrategy"); - if (data == null || data.isEmpty() || allMultiThreadStrategy == null) { + String chatMultiThreadStrategy = call.argument("chatMultiThreadStrategy"); + if (data == null || data.isEmpty() || chatMultiThreadStrategy == null) { result.error(ErrorCodes.CHAT_VIEW_ERROR.getErrorCode(), "Cannot send contextual data. Data or allMultiThreadStrategy is missing.", null); } else { - fragment.sendContextualData(data, allMultiThreadStrategy); + fragment.sendContextualData(data, MultithreadStrategy.valueOf(chatMultiThreadStrategy)); result.success(RESULT_SUCCESS); } } else { diff --git a/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/infobip_mobilemessaging/InfobipMobilemessagingPlugin.java b/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/infobip_mobilemessaging/InfobipMobilemessagingPlugin.java index 1316e47..e9d4cc8 100644 --- a/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/infobip_mobilemessaging/InfobipMobilemessagingPlugin.java +++ b/android/src/main/java/org/infobip/plugins/mobilemessaging/flutter/infobip_mobilemessaging/InfobipMobilemessagingPlugin.java @@ -64,6 +64,7 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import org.infobip.mobile.messaging.chat.core.MultithreadStrategy; import java.util.ArrayList; import java.util.Arrays; @@ -891,12 +892,12 @@ private void setLanguage(MethodCall call, final MethodChannel.Result result) { private void sendContextualData(MethodCall call, final MethodChannel.Result result) { String data = call.argument("data"); - Boolean allMultiThreadStrategy = call.argument("allMultiThreadStrategy"); - if (data == null || data.isEmpty() || allMultiThreadStrategy == null) { + String chatMultiThreadStrategy = call.argument("chatMultiThreadStrategy"); + if (data == null || data.isEmpty() || chatMultiThreadStrategy == null) { result.error(ErrorCodes.CONTEXTUAL_METADATA_ERROR.getErrorCode(), "Cannot resolve data or allMultiThreadStrategy from arguments", null); return; } - InAppChat.getInstance(activity.getApplication()).sendContextualData(data, allMultiThreadStrategy); + InAppChat.getInstance(activity.getApplication()).sendContextualData(data, MultithreadStrategy.valueOf(chatMultiThreadStrategy)); } private void setJwt(MethodCall call) { diff --git a/example/lib/screens/homepage.dart b/example/lib/screens/homepage.dart index fd60503..ce22040 100644 --- a/example/lib/screens/homepage.dart +++ b/example/lib/screens/homepage.dart @@ -383,7 +383,7 @@ class _HomePageState extends State { ListTile( title: const Text('Send Contextual Data and Show chat screen'), onTap: () { - InfobipMobilemessaging.sendContextualData("{ demoKey: 'InAppChat Metadata Value' }", false); + InfobipMobilemessaging.sendContextualDataWithStrategy("{ demoKey: 'InAppChat Metadata Value' }", ChatMultithreadStrategies.active); InfobipMobilemessaging.showChat(); }, ), diff --git a/ios/Classes/SwiftInfobipMobilemessagingPlugin.swift b/ios/Classes/SwiftInfobipMobilemessagingPlugin.swift index 939e247..337fe6d 100644 --- a/ios/Classes/SwiftInfobipMobilemessagingPlugin.swift +++ b/ios/Classes/SwiftInfobipMobilemessagingPlugin.swift @@ -552,15 +552,26 @@ public class SwiftInfobipMobilemessagingPlugin: NSObject, FlutterPlugin { func sendContextualData(call: FlutterMethodCall, result: @escaping FlutterResult) { guard let args = call.arguments as? [String: Any], let data = args["data"] as? String, - let multiThreadStrategy = args["allMultiThreadStrategy"] as? Bool else { + let multiThreadStrategy = args["chatMultiThreadStrategy"] as? String else { return result( FlutterError( code: "CONTEXTUAL_METADATA_ERROR", - message: "Cannot resolve data or allMultiThreadStrategy from arguments", + message: "Cannot resolve data or chatMultiThreadStrategy from arguments", + details: nil )) + } + + var strategy: MMChatMultiThreadStrategy + switch multiThreadStrategy { + case "ALL": strategy = .ALL + case "ACTIVE": strategy = .ACTIVE + case "ALL_PLUS_NEW": strategy = .ALL_PLUS_NEW + default: + return result(FlutterError( code: "CONTEXTUAL_METADATA_ERROR", + message: "Cannot resolve data or chatMultiThreadStrategy from arguments", details: nil )) } if let chatVc = SwiftInfobipMobilemessagingPlugin.chatVC { - chatVc.sendContextualData(data, multiThreadStrategy: multiThreadStrategy ? .ALL : .ACTIVE) { error in + chatVc.sendContextualData(data, multiThreadStrategy: strategy) { error in if let error = error { result(FlutterError( code: error.mm_code ?? "0", message: error.mm_message, @@ -570,7 +581,7 @@ public class SwiftInfobipMobilemessagingPlugin: NSObject, FlutterPlugin { } } } else if let inAppChat = MobileMessaging.inAppChat { - inAppChat.sendContextualData(data, multiThreadStrategy: multiThreadStrategy ? .ALL : .ACTIVE) + inAppChat.sendContextualData(data, multiThreadStrategy: strategy) return result(Constants.resultSuccess) } else { MMLogDebug("[InAppChat] Cannot send context data, inAppChat service does not exist and ChatViewController is not present.") diff --git a/lib/infobip_mobilemessaging.dart b/lib/infobip_mobilemessaging.dart index 6920c2d..678b9f4 100644 --- a/lib/infobip_mobilemessaging.dart +++ b/lib/infobip_mobilemessaging.dart @@ -18,6 +18,21 @@ import 'models/library_event.dart'; import 'models/message_storage/default_message_storage.dart'; import 'models/message_storage/message_storage.dart'; +enum ChatMultithreadStrategies { + all, allPlusNew, active; + + String get stringValue { + switch (this) { + case ChatMultithreadStrategies.all: + return 'ALL'; + case ChatMultithreadStrategies.allPlusNew: + return 'ALL_PLUS_NEW'; + case ChatMultithreadStrategies.active: + return 'ACTIVE'; + } + } +} + class InfobipMobilemessaging { static const MethodChannel _channel = MethodChannel('infobip_mobilemessaging'); @@ -227,10 +242,23 @@ class InfobipMobilemessaging { } /// Sends contextual data of the Livechat Widget. + @deprecated static void sendContextualData( - String data, bool allMultiThreadStrategy) async { - await _channel.invokeMethod('sendContextualData', - {'data': data, 'allMultiThreadStrategy': allMultiThreadStrategy}); + String data, bool allMultiThreadStrategy + ) async { + InfobipMobilemessaging.sendContextualDataWithStrategy( + data, + allMultiThreadStrategy ? ChatMultithreadStrategies.all : ChatMultithreadStrategies.active + ); + } + + /// Sends contextual data of the Livechat Widget. + static void sendContextualDataWithStrategy( + String data, [ChatMultithreadStrategies chatMultithreadStrategy = ChatMultithreadStrategies.active] + ) async { + await _channel.invokeMethod('sendContextualData', + {'data': data, 'chatMultiThreadStrategy': chatMultithreadStrategy.stringValue } + ); } /// Sets JWT for Livechat.