Skip to content

Commit 9672270

Browse files
Matuš TokarMatuš Tokar
Matuš Tokar
authored and
Matuš Tokar
committed
Pull request #474: mtokar-MCA-4193_contextual_data_new_strategy
Merge in MML/infobip-mobile-messaging-android from mtokar-MCA-4193_contextual_data_new_strategy to master Squashed commit of the following: commit 96c3470c87f177006daff8c9a640c397286fc89a Author: Matus Tokar <mtokar@infobip.com> Date: Wed Dec 18 12:32:34 2024 +0100 review fixes commit 108a6ff51e9e024cab318a1e79c602e6923fc0ac Author: Matus Tokar <mtokar@infobip.com> Date: Sun Dec 15 17:40:10 2024 +0100 new context data strategy
1 parent dc58316 commit 9672270

File tree

8 files changed

+120
-30
lines changed

8 files changed

+120
-30
lines changed

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChat.java

+37-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import androidx.fragment.app.FragmentManager;
88

99
import org.infobip.mobile.messaging.MobileMessaging;
10+
import org.infobip.mobile.messaging.chat.core.MultithreadStrategy;
1011
import org.infobip.mobile.messaging.chat.view.InAppChatEventsListener;
1112
import org.infobip.mobile.messaging.chat.view.styles.InAppChatTheme;
1213

@@ -78,14 +79,16 @@ public synchronized static InAppChat getInstance(Context context) {
7879

7980
/**
8081
* Adds in-app chat Fragment to the Activity or shows it if it was already added and hidden.
82+
*
8183
* @param fragmentManager manager to make interactions with Fragment
82-
* @param containerId identifier of the container in-app chat Fragment is to be placed in
84+
* @param containerId identifier of the container in-app chat Fragment is to be placed in
8385
*/
8486
public abstract void showInAppChatFragment(FragmentManager fragmentManager, int containerId);
8587

8688
/**
8789
* Hides in-app chat Fragment, so that all views, especially in-app chat webView,
8890
* stays in memory and chat connection is active while fragment is hidden.
91+
*
8992
* @param fragmentManager manager to make interactions with Fragment
9093
* @see InAppChat#hideInAppChatFragment(FragmentManager, Boolean)
9194
*/
@@ -95,13 +98,12 @@ public synchronized static InAppChat getInstance(Context context) {
9598
* Hides in-app chat Fragment, so that all views, especially in-app chat webView, stays in memory.
9699
* You can control whether chat connection stays active while fragment is hidden.
97100
*
101+
* @param fragmentManager manager to make interactions with Fragment
102+
* @param disconnectChatWhenHidden if true disconnects chat connection when fragment is hidden, otherwise chat connection stays active
98103
* @apiNote By chat connection you can control push notifications.
99104
* Push notifications are active only when chat connection is not active.
100105
* Disconnect chat if you want to receive push notifications while fragment is hidden.
101106
* Chat connection is re-established when {@link InAppChat#showInAppChatFragment(FragmentManager, int)} is called.
102-
*
103-
* @param fragmentManager manager to make interactions with Fragment
104-
* @param disconnectChatWhenHidden if true disconnects chat connection when fragment is hidden, otherwise chat connection stays active
105107
* @see InAppChat#hideInAppChatFragment(FragmentManager)
106108
*/
107109
public abstract void hideInAppChatFragment(FragmentManager fragmentManager, Boolean disconnectChatWhenHidden);
@@ -140,16 +142,29 @@ public synchronized static InAppChat getInstance(Context context) {
140142
*
141143
* @param data contextual data in the form of JSON string
142144
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
145+
* @deprecated Use {@link InAppChat#sendContextualData(String, MultithreadStrategy, MobileMessaging.ResultListener)} instead
143146
*/
147+
@Deprecated
144148
public abstract void sendContextualData(@Nullable String data, @Nullable Boolean allMultiThreadStrategy);
145149

146150
/**
147-
* Set contextual data of the Livechat Widget with false (ACTIVE) value for multithread strategy.
151+
* Set contextual data of the Livechat Widget.
148152
* If the function is called when the chat is loaded,
149153
* data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
150154
* Every function invocation will overwrite the previous contextual data.
151155
*
152-
* @param data contextual data in the form of JSON string
156+
* @param data contextual data in the form of JSON string
157+
* @param flag multithread strategy [MultithreadStrategy]
158+
*/
159+
public abstract void sendContextualData(@Nullable String data, @Nullable MultithreadStrategy flag);
160+
161+
/**
162+
* Set contextual data of the Livechat Widget with false (MultithreadStrategy.ACTIVE) value for multithread strategy.
163+
* If the function is called when the chat is loaded,
164+
* data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
165+
* Every function invocation will overwrite the previous contextual data.
166+
*
167+
* @param data contextual data in the form of JSON string
153168
*/
154169
public abstract void sendContextualData(@Nullable String data);
155170

@@ -163,9 +178,24 @@ public synchronized static InAppChat getInstance(Context context) {
163178
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
164179
* @param resultListener listener to report the result on
165180
* @see MobileMessaging.ResultListener
181+
* @deprecated Use {@link InAppChat#sendContextualData(String, MultithreadStrategy, MobileMessaging.ResultListener)} instead
166182
*/
183+
@Deprecated
167184
public abstract void sendContextualData(@Nullable String data, @Nullable Boolean allMultiThreadStrategy, @Nullable MobileMessaging.ResultListener<Void> resultListener);
168185

186+
/**
187+
* Set contextual data of the Livechat Widget.
188+
* If the function is called when the chat is loaded,
189+
* data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
190+
* Every function invocation will overwrite the previous contextual data.
191+
*
192+
* @param data contextual data in the form of JSON string
193+
* @param flag multithread strategy [MultithreadStrategy]
194+
* @param resultListener listener to report the result on
195+
* @see MobileMessaging.ResultListener
196+
*/
197+
public abstract void sendContextualData(@Nullable String data, @Nullable MultithreadStrategy flag, @Nullable MobileMessaging.ResultListener<Void> resultListener);
198+
169199
/**
170200
* Set {@link JwtProvider} to give in-app chat ability to authenticate.
171201
*
@@ -185,6 +215,7 @@ public synchronized static InAppChat getInstance(Context context) {
185215

186216
/**
187217
* Navigates to THREAD_LIST view in multithread widget if in-app chat is shown as Fragment.
218+
*
188219
* @see org.infobip.mobile.messaging.chat.core.InAppChatWidgetView
189220
*/
190221
public abstract void showThreadsList();

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/InAppChatImpl.java

+31-12
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
import android.view.View;
1111
import android.view.ViewGroup;
1212

13+
import androidx.annotation.NonNull;
14+
import androidx.annotation.Nullable;
15+
import androidx.appcompat.app.AppCompatActivity;
16+
import androidx.core.app.TaskStackBuilder;
17+
import androidx.fragment.app.Fragment;
18+
import androidx.fragment.app.FragmentManager;
19+
import androidx.fragment.app.FragmentTransaction;
20+
1321
import org.infobip.mobile.messaging.Event;
1422
import org.infobip.mobile.messaging.Message;
1523
import org.infobip.mobile.messaging.MessageHandlerModule;
@@ -21,6 +29,7 @@
2129
import org.infobip.mobile.messaging.app.ActivityLifecycleMonitor;
2230
import org.infobip.mobile.messaging.chat.core.InAppChatBroadcasterImpl;
2331
import org.infobip.mobile.messaging.chat.core.InAppChatScreenImpl;
32+
import org.infobip.mobile.messaging.chat.core.MultithreadStrategy;
2433
import org.infobip.mobile.messaging.chat.core.SessionStorage;
2534
import org.infobip.mobile.messaging.chat.mobileapi.InAppChatSynchronizer;
2635
import org.infobip.mobile.messaging.chat.mobileapi.LivechatRegistrationChecker;
@@ -45,14 +54,6 @@
4554
import java.util.Locale;
4655
import java.util.concurrent.Executors;
4756

48-
import androidx.annotation.NonNull;
49-
import androidx.annotation.Nullable;
50-
import androidx.appcompat.app.AppCompatActivity;
51-
import androidx.core.app.TaskStackBuilder;
52-
import androidx.fragment.app.Fragment;
53-
import androidx.fragment.app.FragmentManager;
54-
import androidx.fragment.app.FragmentTransaction;
55-
5657

5758
public class InAppChatImpl extends InAppChat implements MessageHandlerModule {
5859

@@ -379,7 +380,7 @@ public void setLanguage(String language, MobileMessaging.ResultListener<String>
379380

380381
@Override
381382
public void sendContextualData(@Nullable String data) {
382-
sendContextualData(data, false, new MobileMessaging.ResultListener<Void>() {
383+
sendContextualData(data, MultithreadStrategy.ACTIVE, new MobileMessaging.ResultListener<Void>() {
383384
@Override
384385
public void onResult(Result<Void, MobileMessagingError> result) {
385386
if (!result.isSuccess()) {
@@ -401,21 +402,39 @@ public void onResult(Result<Void, MobileMessagingError> result) {
401402
});
402403
}
403404

405+
@Override
406+
public void sendContextualData(@Nullable String data, @Nullable MultithreadStrategy flag) {
407+
sendContextualData(data, flag, new MobileMessaging.ResultListener<Void>() {
408+
@Override
409+
public void onResult(Result<Void, MobileMessagingError> result) {
410+
if (!result.isSuccess()) {
411+
MobileMessagingLogger.e(TAG,"Send contextual data error: " + result.getError().getMessage());
412+
}
413+
}
414+
});
415+
}
416+
404417
@Override
405418
public void sendContextualData(@Nullable String data, @Nullable Boolean allMultiThreadStrategy, @Nullable MobileMessaging.ResultListener<Void> resultListener) {
419+
MultithreadStrategy flag = Boolean.TRUE.equals(allMultiThreadStrategy) ? MultithreadStrategy.ALL : MultithreadStrategy.ACTIVE;
420+
sendContextualData(data, flag, resultListener);
421+
}
422+
423+
@Override
424+
public void sendContextualData(@Nullable String data, @Nullable MultithreadStrategy flag, @Nullable MobileMessaging.ResultListener<Void> resultListener) {
406425
Result<Void, MobileMessagingError> result = null;
407426
try {
408427
if (data == null || data.isEmpty()) {
409428
sessionStorage().setContextualData(null);
410429
result = new Result<>(MobileMessagingError.createFrom(new IllegalArgumentException("Could not send contextual data. Data is null or empty.")));
411-
} else if (allMultiThreadStrategy == null) {
430+
} else if (flag == null) {
412431
sessionStorage().setContextualData(null);
413432
result = new Result<>(MobileMessagingError.createFrom(new IllegalArgumentException("Could not send contextual data. Strategy flag is null.")));
414433
} else if (inAppChatWVFragment != null) {
415-
inAppChatWVFragment.sendContextualData(data, allMultiThreadStrategy);
434+
inAppChatWVFragment.sendContextualData(data, flag);
416435
result = new Result<>(null);
417436
} else {
418-
sessionStorage().setContextualData(new ContextualData(data, allMultiThreadStrategy));
437+
sessionStorage().setContextualData(new ContextualData(data, flag));
419438
MobileMessagingLogger.d(TAG,"Contextual data is stored, will be sent once chat is loaded.");
420439
result = new Result<>(null);
421440
}

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/InAppChatClient.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ public interface InAppChatClient {
3939
void setLanguage(Locale locale);
4040

4141
/**
42-
* Send contextual metadata of conversation and a InAppChatMultiThreadFlag flag
42+
* Send contextual metadata of conversation and a MultithreadStrategy flag
4343
*
4444
* @param data contextual data in the form of JSON string
4545
* @param multiThreadFlag multithread strategy flag
4646
* @param resultListener result listener
4747
*/
48-
void sendContextualData(String data, InAppChatMultiThreadFlag multiThreadFlag, MobileMessaging.ResultListener<String> resultListener);
48+
void sendContextualData(String data, MultithreadStrategy multiThreadFlag, MobileMessaging.ResultListener<String> resultListener);
4949

5050
/**
5151
* Change destination from thread to list in multiThread widget. For non multiThread widget it does nothing.

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/core/InAppChatClientImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void setLanguage(Locale locale) {
7575
}
7676

7777
@Override
78-
public void sendContextualData(String data, InAppChatMultiThreadFlag multiThreadFlag, MobileMessaging.ResultListener<String> resultListener) {
78+
public void sendContextualData(String data, MultithreadStrategy multiThreadFlag, MobileMessaging.ResultListener<String> resultListener) {
7979
if (data == null || data.isEmpty()){
8080
resultListener.onResult(new Result<>(MobileMessagingError.createFrom(new IllegalArgumentException("Could not send contextual data. Data is null or empty."))));
8181
return;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.infobip.mobile.messaging.chat.core;
22

3-
public enum InAppChatMultiThreadFlag {
3+
public enum MultithreadStrategy {
44
ACTIVE,
5-
ALL
5+
ALL,
6+
ALL_PLUS_NEW
67
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.infobip.mobile.messaging.chat.models
22

3+
import org.infobip.mobile.messaging.chat.core.MultithreadStrategy
4+
35
internal data class ContextualData(
46
val data: String,
5-
val allMultiThreadStrategy: Boolean
7+
val allMultiThreadStrategy: MultithreadStrategy
68
)

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/InAppChatFragment.kt

+23-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import org.infobip.mobile.messaging.chat.R
3636
import org.infobip.mobile.messaging.chat.attachments.InAppChatAttachmentHelper
3737
import org.infobip.mobile.messaging.chat.attachments.InAppChatMobileAttachment
3838
import org.infobip.mobile.messaging.chat.core.InAppChatWidgetView
39+
import org.infobip.mobile.messaging.chat.core.MultithreadStrategy
3940
import org.infobip.mobile.messaging.chat.core.SessionStorage
4041
import org.infobip.mobile.messaging.chat.databinding.IbFragmentChatBinding
4142
import org.infobip.mobile.messaging.chat.models.ContextualData
@@ -354,15 +355,34 @@ class InAppChatFragment : Fragment(), InAppChatFragmentActivityResultDelegate.Re
354355
* Every function invocation will overwrite the previous contextual data.
355356
*
356357
*
357-
* @param data contextual data in the form of JSON string
358+
* @param data contextual data in the form of JSON string
358359
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
359360
* @see [InAppChatFragment.EventsListener.onChatLoaded] to detect if chat is loaded
360361
*/
362+
@Deprecated("Use sendContextualData(data: String, flag: MultithreadStrategy) instead")
361363
fun sendContextualData(data: String, allMultiThreadStrategy: Boolean) {
364+
val flag = if (allMultiThreadStrategy) MultithreadStrategy.ALL else MultithreadStrategy.ACTIVE
365+
sendContextualData(data, flag)
366+
}
367+
368+
/**
369+
* Set contextual data of the Livechat Widget.
370+
*
371+
* If the function is called when [InAppChatFragment] is attached and the chat is loaded,
372+
* data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
373+
*
374+
* Every function invocation will overwrite the previous contextual data.
375+
*
376+
*
377+
* @param data contextual data in the form of JSON string
378+
* @param flag multithread strategy [MultithreadStrategy]
379+
* @see [InAppChatFragment.EventsListener.onChatLoaded] to detect if chat is loaded
380+
*/
381+
fun sendContextualData(data: String, flag: MultithreadStrategy) {
362382
withBinding(
363-
action = { it.ibLcChat.sendContextualData(data, allMultiThreadStrategy) },
383+
action = { it.ibLcChat.sendContextualData(data, flag) },
364384
fallback = {
365-
SessionStorage.contextualData = ContextualData(data, allMultiThreadStrategy)
385+
SessionStorage.contextualData = ContextualData(data, flag)
366386
MobileMessagingLogger.d(TAG, "Contextual data is stored, will be sent once chat is loaded.")
367387
}
368388
)

infobip-mobile-messaging-android-chat-sdk/src/main/java/org/infobip/mobile/messaging/chat/view/InAppChatView.kt

+20-3
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,30 @@ class InAppChatView @JvmOverloads constructor(
247247
*
248248
* Every function invocation will overwrite the previous contextual data.
249249
*
250-
* @param data contextual data in the form of JSON string
250+
* @param data contextual data in the form of JSON string
251251
* @param allMultiThreadStrategy multithread strategy flag, true -> ALL, false -> ACTIVE
252252
* @see [InAppChatView.EventsListener.onChatLoaded] to detect if chat is loaded
253253
*/
254+
@Deprecated("Use sendContextualData(data: String, flag: MultithreadStrategy) instead")
254255
fun sendContextualData(data: String, allMultiThreadStrategy: Boolean) {
256+
val flag = if (allMultiThreadStrategy) MultithreadStrategy.ALL else MultithreadStrategy.ACTIVE
257+
sendContextualData(data, flag)
258+
}
259+
260+
/**
261+
* Set contextual data of the Livechat Widget.
262+
*
263+
* If the function is called when the chat is loaded,
264+
* data will be sent immediately, otherwise they will be sent to the chat once it is loaded.
265+
*
266+
* Every function invocation will overwrite the previous contextual data.
267+
*
268+
* @param data contextual data in the form of JSON string
269+
* @param flag multithread strategy [MultithreadStrategy]
270+
* @see [InAppChatView.EventsListener.onChatLoaded] to detect if chat is loaded
271+
*/
272+
fun sendContextualData(data: String, flag: MultithreadStrategy) {
255273
if (isChatLoaded) {
256-
val flag = if (allMultiThreadStrategy) InAppChatMultiThreadFlag.ALL else InAppChatMultiThreadFlag.ACTIVE
257274
val listener = object : ResultListener<String>() {
258275
override fun onResult(result: Result<String, MobileMessagingError>) {
259276
SessionStorage.contextualData = null
@@ -264,7 +281,7 @@ class InAppChatView @JvmOverloads constructor(
264281
}
265282
inAppChatClient.sendContextualData(data, flag, listener)
266283
} else {
267-
SessionStorage.contextualData = ContextualData(data, allMultiThreadStrategy)
284+
SessionStorage.contextualData = ContextualData(data, flag)
268285
MobileMessagingLogger.d(TAG, "Contextual data is stored, will be sent once chat is loaded.")
269286
}
270287
}

0 commit comments

Comments
 (0)