Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ repositories {

dependencies {
implementation 'com.facebook.react:react-native:+'
api 'io.kommunicate.sdk:kommunicateui:2.14.1'
api 'io.kommunicate.sdk:kommunicateui:2.14.2'
}
21 changes: 13 additions & 8 deletions android/src/main/java/io/kommunicate/app/KmEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void register(ReactApplicationContext reactContext) {
}

public void unregister() {
EventManager.getInstance().unregisterPluginEventListener();
EventManager.getInstance().unregisterPluginEventListener();
}

private void sendEvent(String eventName, String value) {
Expand All @@ -41,7 +41,7 @@ public void onPluginLaunch() {

@Override
public void onPluginDismiss() {
sendEvent("onPluginDismiss", "dismiss");
sendEvent("onPluginDismiss", "dismiss");
}

@Override
Expand Down Expand Up @@ -108,12 +108,12 @@ public void onAttachmentClick(String attachmentType) {

@Override
public void onFaqClick(String FaqUrl) {
sendEvent("onFaqClick", FaqUrl);
sendEvent("onFaqClick", FaqUrl);
}

@Override
public void onLocationClick() {
sendEvent("onLocationClick", "clicked");
sendEvent("onLocationClick", "clicked");
}

@Override
Expand All @@ -123,17 +123,22 @@ public void onNotificationClick(Message message){

@Override
public void onVoiceButtonClick(String action){
sendEvent("onVoiceButtonClick", action);
sendEvent("onVoiceButtonClick", action);
}

@Override
public void onRatingEmoticonsClick(Integer ratingValue){
public void onRatingEmoticonsClick(Integer ratingValue) {
sendEvent("onRatingEmoticonsClick", String.valueOf(ratingValue));
}

@Override
public void onRateConversationClick(){
sendEvent("onRateConversationClick", "clicked");
public void onRateConversationClick() {
sendEvent("onRateConversationClick", "clicked");
}

@Override
public void onCurrentOpenedConversation(Integer conversationId) {
sendEvent("onCurrentConversationOpened", String.valueOf(conversationId));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class RNKommunicateChatModule extends ReactContextBaseJavaModule {
private static final String MESSAGE_METADATA = "messageMetadata";
private static final String TEAM_ID = "teamId";
private static final String CONVERSATION_INFO = "conversationInfo";
private static final String APP_ID = "appId";
private static final String LANGUAGES = "languages";
private static final String KM_USER = "kmUser";
private KmEventListener kmEventListener;
Expand Down Expand Up @@ -216,6 +217,93 @@ public void onFailure(RegistrationResponse registrationResponse, Exception excep
});
}

@ReactMethod
public void launchConversationWithUser(final ReadableMap jsonObject, final Callback callback) {
final Activity currentActivity = getCurrentActivity();
if (currentActivity == null) {
callback.invoke(ERROR, "Activity doesn't exist");
return;
}

try {
KMUser user = null;
Map<String, String> conversationInfo = null;
Map<String, Object> dataMap = jsonObject.toHashMap();
Map<String, String> messageMetadata = null;
String applicationId = null;
boolean shouldMaintainSession = true;

if (jsonObject.hasKey(KM_USER)) {
user = (KMUser) GsonUtils.getObjectFromJson(jsonObject.getString(KM_USER), KMUser.class);
dataMap.remove(KM_USER);
}

if (jsonObject.hasKey("shouldMaintainSession")) {
shouldMaintainSession = jsonObject.getBoolean("shouldMaintainSession");
dataMap.remove("shouldMaintainSession");
}

if (user != null && user.getApplicationId() != null) {
applicationId = user.getApplicationId();
} else if (jsonObject.hasKey(APP_ID)) {
applicationId = (String) jsonObject.getString(APP_ID);
} else {
callback.invoke(ERROR, "The object doesn't contain appId.");
return;
}

if (jsonObject.hasKey(CONVERSATION_INFO)) {
conversationInfo = (Map<String, String>) GsonUtils.getObjectFromJson(jsonObject.getString(CONVERSATION_INFO), Map.class);
dataMap.remove(CONVERSATION_INFO);
}

if (jsonObject.hasKey(MESSAGE_METADATA)) {
messageMetadata = (Map<String, String>) GsonUtils.getObjectFromJson(jsonObject.getString(MESSAGE_METADATA), Map.class);
dataMap.remove(MESSAGE_METADATA);
}

KmConversationBuilder conversationBuilder = (KmConversationBuilder) GsonUtils.getObjectFromJson(GsonUtils.getJsonFromObject(dataMap, HashMap.class), KmConversationBuilder.class);
conversationBuilder.setContext(currentActivity);

if (!jsonObject.hasKey("isSingleConversation")) {
conversationBuilder.setSingleConversation(true);
}
if (!jsonObject.hasKey("skipConversationList")) {
conversationBuilder.setSkipConversationList(true);
}
if (user != null) {
conversationBuilder.setKmUser(user);
}
if (conversationInfo != null) {
conversationBuilder.setConversationInfo(conversationInfo);
}
if (messageMetadata != null) {
conversationBuilder.setMessageMetadata(messageMetadata);
}
// Launch Kommunicate conversation
Kommunicate.launchConversationWithUser(
currentActivity,
applicationId,
user,
conversationBuilder,
shouldMaintainSession,
new KmCallback() {
@Override
public void onSuccess(Object message) {
callback.invoke(SUCCESS, message != null ? ChannelService.getInstance(currentActivity).getChannelByChannelKey((Integer) message).getClientGroupId() : "Success");
}

@Override
public void onFailure(Object error) {
callback.invoke(ERROR, error != null ? error.toString() : "Unknown error occurred");
}
}
);
} catch (Exception e) {
callback.invoke(ERROR, e.toString());
}
}

@ReactMethod
public void updateUserDetails(final ReadableMap config, final Callback callback) {
final Activity currentActivity = getCurrentActivity();
Expand Down
Loading