Skip to content

Commit

Permalink
Pull request #88: Msvitlovskyi MCA-4330 new send context data strategy
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-flutter from msvitlovskyi-MCA-4330-new-send-context-data-strategy to main

Squashed commit of the following:

commit 0c5a23417e098f04558c9fb3b52833d4906f5108
Merge: 212e649 0e9f315
Author: Matus Tokar <[email protected]>
Date:   Fri Dec 20 13:40:40 2024 +0100

    Merge remote-tracking branch 'refs/remotes/origin/main' into msvitlovskyi-MCA-4330-new-send-context-data-strategy
    
    # Conflicts:
    #	ios/infobip_mobilemessaging.podspec

commit 212e6496b9f76c3a950862aa3fbe50ffce38fac8
Author: Matus Tokar <[email protected]>
Date:   Thu Dec 19 16:02:09 2024 +0100

    android part of new contextual strategy

commit 10f607b32a5af8eb0aa93e07fce65082bb69af9d
Author: Matus Tokar <[email protected]>
Date:   Wed Dec 18 16:58:15 2024 +0100

    renaming

commit cb3078c19725ef9174d07f1c101e95bbac8a6f48
Author: Matus Tokar <[email protected]>
Date:   Mon Dec 16 13:46:52 2024 +0100

    remove app code

commit cd1b07037fdc37b44127d9d02b41a42dea8bcdc3
Author: Matus Tokar <[email protected]>
Date:   Mon Dec 16 13:44:34 2024 +0100

    android part of new contextual strategy

commit 8f1cf6beafe7153f4619d036bc9cb7c013bde001
Author: Maksym Svitlovskyi <[email protected]>
Date:   Fri Dec 6 15:40:31 2024 +0100

    Make active default value

commit 7184f5508eb59b7c88cb96f7889b23ab27ae3b10
Author: Maksym Svitlovskyi <[email protected]>
Date:   Fri Dec 6 15:23:36 2024 +0100

    Update example app

commit e20ccf3a26aa9b4d159e595c8c935c0ba0ca8dec
Author: Maksym Svitlovskyi <[email protected]>
Date:   Fri Dec 6 15:08:00 2024 +0100

    Deprecate old method, add new method with enum with multithread strategies

commit 86aaffa5bae2854722d7126f0401bcdd0a27db7d
Author: Maksym Svitlovskyi <[email protected]>
Date:   Fri Dec 6 14:58:57 2024 +0100

    increase MM native sdk version
  • Loading branch information
Svitlovskyi authored and Matuš Tokar committed Dec 20, 2024
1 parent 0e9f315 commit 3caba1e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 15 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion example/lib/screens/homepage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ class _HomePageState extends State<HomePage> {
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();
},
),
Expand Down
19 changes: 15 additions & 4 deletions ios/Classes/SwiftInfobipMobilemessagingPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.")
Expand Down
34 changes: 31 additions & 3 deletions lib/infobip_mobilemessaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 3caba1e

Please sign in to comment.