Skip to content

Commit

Permalink
Pull request #16: in-app editor params added
Browse files Browse the repository at this point in the history
Merge in MML/infobip-mobile-messaging-react-native-plugin from okoroleva-MM-4120_inAppEditorChanges to master

Squashed commit of the following:

commit 5a9d6137c13773131a84fa8e8ac507e871a85c60
Author: Olga Koroleva <[email protected]>
Date:   Tue Sep 15 16:51:42 2020 +0300

    added material lib dependency

commit f8025bd390e64673e45b3c156461cdb986ca67bc
Author: Olga Koroleva <[email protected]>
Date:   Tue Sep 15 16:17:04 2020 +0300

    changes after PR

commit dba99b950e8d73794a47234a241314c2e74bd69b
Author: Olga Koroleva <[email protected]>
Date:   Tue Sep 15 13:33:16 2020 +0300

    added params for Android message

commit 2fd0a9ad5f62211ae9e44f86ecbfb7c0382a0ee2
Author: Olga Koroleva <[email protected]>
Date:   Mon Sep 14 17:07:22 2020 +0300

    in-app editor params added
  • Loading branch information
riskpp committed Sep 15, 2020
1 parent 61cea28 commit e4f0db5
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 40 deletions.
3 changes: 2 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ repositories {
}

dependencies {
def mmVersion = '3.0.3'
def mmVersion = '3.3.0'

implementation 'com.facebook.react:react-native:+'
implementation "androidx.annotation:annotation:1.1.0"
implementation 'com.google.android.material:material:1.0.0'

implementation "org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-resources:$mmVersion@aar"
implementation "org.infobip.mobile.messaging.api:infobip-mobile-messaging-android-chat-sdk:$mmVersion@aar"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;

import org.infobip.mobile.messaging.chat.InAppChat;

Expand All @@ -25,7 +26,7 @@ public String getName() {
}

@ReactMethod
public void showChat() {
public void showChat(ReadableMap args) {
InAppChat.getInstance(reactContext).inAppChatView().show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ public static JSONObject toJSON(Message message) {
.putOpt("seen", message.getSeenTimestamp() != 0)
.putOpt("seenDate", message.getSeenTimestamp())
.putOpt("geo", hasGeo(message))
.putOpt("chat", message.isChatMessage());
.putOpt("chat", message.isChatMessage())
.putOpt("browserUrl", message.getBrowserUrl())
.putOpt("webViewUrl", message.getWebViewUrl())
.putOpt("deeplink", message.getDeeplink())
.putOpt("inAppOpenTitle", message.getInAppOpenTitle())
.putOpt("inAppDismissTitle", message.getInAppDismissTitle());
} catch (JSONException e) {
Log.w(Utils.TAG, "Cannot convert message to JSON: " + e.getMessage());
Log.d(Utils.TAG, Log.getStackTraceString(e));
Expand Down Expand Up @@ -118,6 +123,16 @@ private static Message fromJSON(JSONObject json) {
message.setFrom(json.optString("from", null));
message.setReceivedTimestamp(json.optLong("receivedTimestamp", 0));
message.setCustomPayload(json.optJSONObject("customPayload"));
message.setContentUrl(json.optString("contentUrl", null));
message.setSeenTimestamp(json.optLong("seenDate", 0));
message.setBrowserUrl(json.optString("browserUrl", null));
message.setWebViewUrl(json.optString("webViewUrl", null));
message.setDeeplink(json.optString("deeplink", null));
message.setInAppOpenTitle(json.optString("inAppOpenTitle", null));
message.setInAppDismissTitle(json.optString("inAppDismissTitle", null));
if (json.optBoolean("chat", false)) {
message.setMessageType(Message.MESSAGE_TYPE_CHAT);
}
return message;
}

Expand Down Expand Up @@ -173,4 +188,4 @@ public static List<Message> resolveMessages(JSONArray args) throws JSONException
}
return messages;
}
}
}
18 changes: 14 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,20 @@ class MobileMessaging {
* Shows In-app chat screen.
* iOS - it's screen with top bar and `x` button on the right corner.
* Android - it's screen with top bar and back navigation button.
* @name showChat
* @param {Object} presentingOptions. You can configure how chat will be presented.
* Now only one option for iOS is supported: `shouldBePresentedModally`, false by default.
* If it's true - in-app chat View Controller for iOS will be presented modally.
* example:
* {
* ios: {
* shouldBePresentedModally: true
* }
* }
*/
showChat() {
RNMMChat.showChat();
}
showChat(presentingOptions= {}) {
RNMMChat.showChat(presentingOptions);
};

/**
* You can define custom appearance for iOS chat view by providing a chat settings.
Expand All @@ -497,7 +507,7 @@ class MobileMessaging {
} else {
console.log("method setupiOSChatSettings isn't supported for Android, use settings.xml to provide appearance settings.");
}
}
};
}

export class ChatView extends React.Component {
Expand Down
6 changes: 3 additions & 3 deletions infobip-mobile-messaging-react-native-plugin.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Pod::Spec.new do |s|
s.requires_arc = true

s.dependency "React"
s.dependency "MobileMessaging/Core", "8.0.6"
s.dependency "MobileMessaging/Geofencing", "8.0.6"
s.dependency "MobileMessaging/InAppChat", "8.0.6"
s.dependency "MobileMessaging/Core", "8.2.4"
s.dependency "MobileMessaging/Geofencing", "8.2.4"
s.dependency "MobileMessaging/InAppChat", "8.2.4"

end
2 changes: 1 addition & 1 deletion ios/Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "infobip/mobile-messaging-sdk-ios" "8.0.6"
github "infobip/mobile-messaging-sdk-ios" "8.2.4"
2 changes: 1 addition & 1 deletion ios/Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "infobip/mobile-messaging-sdk-ios" "8.0.6"
github "infobip/mobile-messaging-sdk-ios" "8.2.4"
23 changes: 18 additions & 5 deletions ios/MobileMessagingPlugin/RNMMChat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,24 @@ import MobileMessaging

@objc(RNMMChat)
class RNMMChat: NSObject {
@objc(showChat)
func showChat() {
let vc = ChatViewController.makeRootNavigationViewController()
vc.modalPresentationStyle = .fullScreen
RCTKeyWindow()?.rootViewController?.present(vc, animated: true, completion: nil)

@objc(showChat:)
func showChat(presentingOptions: NSDictionary) {
var presentVCModally = false
if let presentingOptions = presentingOptions as? [String: Any],
let iosOptions = presentingOptions["ios"] as? [String: Any],
let shouldBePresentedModally = iosOptions["shouldBePresentedModally"] as? Bool {
presentVCModally = shouldBePresentedModally
}
let vc = presentVCModally ? ChatViewController.makeRootNavigationViewController(): ChatViewController.makeRootNavigationViewControllerWithCustomTransition()
if presentVCModally {
vc.modalPresentationStyle = .fullScreen
}
if let rootVc = RCTKeyWindow()?.rootViewController {
rootVc.present(vc, animated: true, completion: nil)
} else {
MMLogDebug("[InAppChat] could not define root vc to present in-app-chat")
}
}

@objc(setupChatSettings:)
Expand Down
2 changes: 1 addition & 1 deletion ios/MobileMessagingPlugin/RNMMChatBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ @interface RNMMChat (RCTExternModule) <RCTBridgeModule>

@implementation RNMMChat (RCTExternModule)
RCT_EXPORT_MODULE_NO_LOAD(RNMMChat, RNMMChat)
RCT_EXTERN_METHOD(showChat)
RCT_EXTERN_METHOD(showChat:)
RCT_EXTERN_METHOD(setupChatSettings:)

- (dispatch_queue_t)methodQueue {
Expand Down
47 changes: 26 additions & 21 deletions ios/MobileMessagingPlugin/RNMobileMessagingUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ extension MTMessage {
result["seenDate"] = seenDate?.timeIntervalSince1970
result["geo"] = isGeoMessage
result["chat"] = isChatMessage
result["browserUrl"] = browserUrl?.absoluteString
result["deeplink"] = deeplink?.absoluteString
result["webViewUrl"] = webViewUrl?.absoluteString
result["inAppOpenTitle"] = inAppOpenTitle
result["inAppDismissTitle"] = inAppDismissTitle
return result
}

var isGeoMessage: Bool {
let geoAreasDicts = (originalPayload["internalData"] as? [String: Any])?["geo"] as? [[String: Any]]
return geoAreasDicts != nil
Expand All @@ -39,48 +44,48 @@ extension BaseMessage {
{
return nil
}

return BaseMessage(messageId: messageId, direction: MessageDirection.MT, originalPayload: originalPayload, deliveryMethod: .undefined)
}

func dictionary() -> [String: Any] {
var result = [String: Any]()
result["messageId"] = messageId
result["customPayload"] = originalPayload["customPayload"]
result["originalPayload"] = originalPayload

if let aps = originalPayload["aps"] as? StringKeyPayload {
result["body"] = aps["body"]
result["sound"] = aps["sound"]
}

if let internalData = originalPayload["internalData"] as? StringKeyPayload,
let _ = internalData["silent"] as? StringKeyPayload {
result["silent"] = true
} else if let silent = originalPayload["silent"] as? Bool {
result["silent"] = silent
}

return result
}
}

extension MMRegion {
func dictionary() -> [String: Any] {
var areaCenter = [String: Any]()
areaCenter["lat"] = center.latitude
areaCenter["lon"] = center.longitude

var area = [String: Any]()
area["id"] = identifier
area["center"] = areaCenter
area["radius"] = radius
area["title"] = title

var result = [String: Any]()
result["area"] = area
return result
}
func dictionary() -> [String: Any] {
var areaCenter = [String: Any]()
areaCenter["lat"] = center.latitude
areaCenter["lon"] = center.longitude
var area = [String: Any]()
area["id"] = identifier
area["center"] = areaCenter
area["radius"] = radius
area["title"] = title
var result = [String: Any]()
result["area"] = area
return result
}
}

extension Optional {
Expand Down

0 comments on commit e4f0db5

Please sign in to comment.