Skip to content

Commit

Permalink
Pull request #36: Feature/MCA-2042 send contextual metadata
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-huawei from feature/MCA-2042_send_contextual_metadata to release_3.0.0

Squashed commit of the following:

commit cbe2bff80a4070c34f97d0e7c3049f4c18accf02
Author: Matuš Tokar <[email protected]>
Date:   Tue Sep 13 15:54:17 2022 +0200

    manual merge

commit 312c18479931ea601a4f7e64f83acaed73c9def2
Merge: 50e25ff 7bed55f
Author: Matuš Tokar <[email protected]>
Date:   Tue Sep 13 15:34:44 2022 +0200

    Merge branch 'release_3.0.0' into feature/send_contextual_metadata

commit 50e25ff
Author: Olga Koroleva <[email protected]>
Date:   Tue Jun 28 10:52:27 2022 +0300

    Revert "note about geo"

    This reverts commit ba8373f.

commit ba8373f
Author: Olga Koroleva <[email protected]>
Date:   Tue Jun 28 10:45:31 2022 +0300

    note about geo
  • Loading branch information
Matuš Tokar authored and Matuš Tokar committed Sep 16, 2022
1 parent 7bed55f commit 63d312e
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
const SHOW = 'show';
const SEND = 'send';
const SET_LANGUAGE = 'set_language';
const SEND_CONTEXTUAL_DATA = 'send_contextual_data'

window.handleMessageSend = function(message) {
liveChat(SEND, message);
Expand All @@ -53,6 +54,13 @@
liveChat(SET_LANGUAGE, language);
}

function sendContextualData(data, strategy) {
liveChat(SEND_CONTEXTUAL_DATA, {
metadata: data,
multiThreadStrategy: strategy
});
}

// Override widget config
liveChat(CONFIG, {
widgetId: getQueryParameter('widgetId'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,19 @@ public synchronized static InAppChat getInstance(Context context) {
* @param language in locale format e.g.: en-US
*/
public abstract void setLanguage(String language);

/**
* Set contextual data of the widget
*
* @param data contextual data in the form of JSON string
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
*/
public abstract void sendContextualData(String data, Boolean allMultiThreadStrategy);

/**
* Set contextual data of the widget with false (ACTIVE) value for multithread strategy
*
* @param data contextual data in the form of JSON string
*/
public abstract void sendContextualData(String data);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.infobip.mobile.messaging.app.ActivityLifecycleMonitor;
import org.infobip.mobile.messaging.chat.core.InAppChatBroadcasterImpl;
import org.infobip.mobile.messaging.chat.core.InAppChatViewImpl;
import org.infobip.mobile.messaging.chat.core.MMChatMultiThreadFlag;
import org.infobip.mobile.messaging.chat.mobileapi.InAppChatSynchronizer;
import org.infobip.mobile.messaging.chat.properties.MobileMessagingChatProperty;
import org.infobip.mobile.messaging.chat.properties.PropertyHelper;
Expand Down Expand Up @@ -150,6 +151,22 @@ public static void setIsWebViewCacheCleaned(Boolean webViewCacheCleaned) {
isWebViewCacheCleaned = webViewCacheCleaned;
}

@Override
public void sendContextualData(String data, Boolean allMultiThreadStrategy) {
if (inAppChatWVFragment != null) {
MMChatMultiThreadFlag strategy = MMChatMultiThreadFlag.ACTIVE;
if (allMultiThreadStrategy) {
strategy = MMChatMultiThreadFlag.ALL;
}
inAppChatWVFragment.sendContextualMetaData(data, strategy);
}
}

@Override
public void sendContextualData(String data) {
sendContextualData(data, false);
}

// region private methods

synchronized private AndroidBroadcaster coreBroadcaster() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ public interface InAppChatClient {
*/
void setLanguage(String language);


/**
* Send contextual metadata of conversation and a MMChatMultiThreadFlag flag
*
* @param data
* @param multitThreadFlag
*/
void sendContextualData(String data, MMChatMultiThreadFlag multiThreadFlag);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static org.infobip.mobile.messaging.chat.utils.CommonUtils.isOSOlderThanKitkat;
import static org.infobip.mobile.messaging.util.StringUtils.isNotBlank;

import android.webkit.ValueCallback;

import org.infobip.mobile.messaging.chat.attachments.InAppChatMobileAttachment;
import org.infobip.mobile.messaging.chat.view.InAppChatWebView;
import org.infobip.mobile.messaging.logging.MobileMessagingLogger;
Expand All @@ -15,6 +17,7 @@
public class InAppChatClientImpl implements InAppChatClient {

private final InAppChatWebView webView;
private static final String TAG = InAppChatClient.class.getSimpleName();

public InAppChatClientImpl(InAppChatWebView webView) {
this.webView = webView;
Expand Down Expand Up @@ -59,6 +62,21 @@ public void setLanguage(String language) {
}
}

@Override
public void sendContextualData(String data, MMChatMultiThreadFlag multiThreadFlag) {
if (webView != null && !data.isEmpty()) {
String script = "sendContextualData(" + data + ", '" + multiThreadFlag + "')";
webView.evaluateJavascriptMethod(script, new ValueCallback<String>() {
@Override
public void onReceiveValue(String value) {
if (value != null) {
MobileMessagingLogger.d(TAG, value);
}
}
});
}
}

private boolean canSendMessage(String message) {
return webView != null && isNotBlank(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ public interface InAppChatWebViewManager {
void setControlsVisibility(boolean isVisible);
void openAttachmentPreview(String url, String type, String caption);
void setLanguage(String language);
void sendContextualMetaData(String data, MMChatMultiThreadFlag multiThreadFlag);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public enum InAppChatWidgetMethods {
handleMessageSend,
handleMessageWithAttachmentSend,
handleMessageDraftSend,
setLanguage
setLanguage,
sendContextualData
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.infobip.mobile.messaging.chat.core;

public enum MMChatMultiThreadFlag {
ACTIVE,
ALL
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
import org.infobip.mobile.messaging.chat.core.InAppChatClientImpl;
import org.infobip.mobile.messaging.chat.core.InAppChatEvent;
import org.infobip.mobile.messaging.chat.core.InAppChatWebViewManager;
import org.infobip.mobile.messaging.chat.core.MMChatMultiThreadFlag;
import org.infobip.mobile.messaging.chat.properties.MobileMessagingChatProperty;
import org.infobip.mobile.messaging.chat.properties.PropertyHelper;
import org.infobip.mobile.messaging.chat.utils.CommonUtils;
Expand Down Expand Up @@ -604,6 +605,11 @@ public void setLanguage(String language) {
inAppChatClient.setLanguage(language);
}

@Override
public void sendContextualMetaData(String data, MMChatMultiThreadFlag multiThreadFlag) {
inAppChatClient.sendContextualData(data, multiThreadFlag);
}

/*
Errors handling
*/
Expand Down

0 comments on commit 63d312e

Please sign in to comment.