From 4fa25463de997c859a368d6e19eb5ff1f598eb81 Mon Sep 17 00:00:00 2001 From: mapierce Date: Fri, 1 Nov 2024 17:28:42 +0000 Subject: [PATCH] Now exposing new APIs --- android/build.gradle | 2 +- .../intercom/reactnative/IntercomHelpers.java | 14 +++++++++ .../intercom/reactnative/IntercomModule.java | 11 +++++++ example/ios/Podfile.lock | 10 +++---- example/src/App.tsx | 28 ++++++++++++++++++ intercom-react-native.podspec | 2 +- ios/IntercomAttributesBuilder.h | 1 + ios/IntercomAttributesBuilder.m | 29 +++++++++++++++++++ ios/IntercomModule.m | 10 +++++++ package.json | 2 +- src/index.tsx | 14 +++++++++ 11 files changed, 115 insertions(+), 8 deletions(-) diff --git a/android/build.gradle b/android/build.gradle index 60ff9630..515e7410 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -69,5 +69,5 @@ dependencies { //noinspection GradleDynamicVersion implementation "com.facebook.react:react-native:+" // From node_modules implementation "com.google.firebase:firebase-messaging:${safeExtGet('firebaseMessagingVersion', '20.2.+')}" - implementation 'io.intercom.android:intercom-sdk:15.10.+' + implementation 'io.intercom.android:intercom-sdk:15.11.+' } diff --git a/android/src/main/java/com/intercom/reactnative/IntercomHelpers.java b/android/src/main/java/com/intercom/reactnative/IntercomHelpers.java index 3e50c408..584754df 100644 --- a/android/src/main/java/com/intercom/reactnative/IntercomHelpers.java +++ b/android/src/main/java/com/intercom/reactnative/IntercomHelpers.java @@ -6,6 +6,8 @@ import com.facebook.react.bridge.ReadableMap; import com.facebook.react.bridge.ReadableMapKeySetIterator; import com.facebook.react.bridge.ReadableType; +import com.facebook.react.bridge.Arguments; +import com.facebook.react.bridge.WritableMap; import java.util.ArrayList; import java.util.Date; @@ -16,6 +18,7 @@ import io.intercom.android.sdk.Company; import io.intercom.android.sdk.Intercom; import io.intercom.android.sdk.UserAttributes; +import io.intercom.android.sdk.identity.Registration; public class IntercomHelpers { @@ -241,4 +244,15 @@ public static String getValueAsStringForKey(ReadableMap map, String key) { } return value; } + + public static WritableMap deconstructRegistration(Registration registration) { + WritableMap registrationMap = Arguments.createMap(); + if (registration.getEmail() != null) { + registrationMap.putString("email", registration.getEmail()); + } + if (registration.getUserId() != null) { + registrationMap.putString("userId", registration.getUserId()); + } + return registrationMap; + } } diff --git a/android/src/main/java/com/intercom/reactnative/IntercomModule.java b/android/src/main/java/com/intercom/reactnative/IntercomModule.java index bd463e23..2b94bab5 100644 --- a/android/src/main/java/com/intercom/reactnative/IntercomModule.java +++ b/android/src/main/java/com/intercom/reactnative/IntercomModule.java @@ -196,6 +196,17 @@ public void onFailure(@NonNull IntercomError intercomError) { }); } + @ReactMethod + public void isUserLoggedIn(Promise promise) { + promise.resolve(Intercom.client().isUserLoggedIn()); + } + + @ReactMethod + public void fetchLoggedInUserAttributes(Promise promise) { + Registration registration = Intercom.client().fetchLoggedInUserAttributes(); + promise.resolve(IntercomHelpers.deconstructRegistration(registration)); + } + @ReactMethod public void logout(Promise promise) { try { diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index f13c658d..35b72e15 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -11,9 +11,9 @@ PODS: - ReactCommon/turbomodule/core (= 0.73.8) - fmt (6.2.1) - glog (0.3.5) - - Intercom (18.1.0) + - Intercom (18.2.0) - intercom-react-native (8.0.0): - - Intercom (~> 18.1.0) + - Intercom (~> 18.2.0) - React-Core - RCT-Folly (2022.05.16.00): - boost @@ -1197,8 +1197,8 @@ SPEC CHECKSUMS: FBReactNativeSpec: bbe8b686178e5ce03d1d8a356789f211f91f31b8 fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9 glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b - Intercom: b3a7282d46c7a670d805b70430cb929d9473ddb1 - intercom-react-native: f4e484301273c2a2ff7c1839eb3c9c2da1c0aa26 + Intercom: e6febbddf5cfa4a15629c1d075b01a9825a23ad9 + intercom-react-native: 8653075ec108951d9c9dedb5b8518e6806508b13 RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0 RCTRequired: 0c7f03a41ee32dec802c74c341e317a4165973d5 RCTTypeSafety: 57698bb7fcde424922e201dab377f496a08a63e3 @@ -1247,4 +1247,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: 15fb131f3e1a2b2d9a606515df1414680c8e67b5 -COCOAPODS: 1.12.1 +COCOAPODS: 1.15.2 diff --git a/example/src/App.tsx b/example/src/App.tsx index 54932b60..b6fa5a1d 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -77,6 +77,18 @@ export default function App() { Alert.alert(field, `Provided ${field} is not of correct format`); }; + const showLoggedInStatusAlert = () => { + Intercom.isUserLoggedIn().then((res) => { + Alert.alert(`Logged in status: ${res ? 'Yes' : 'No'}`); + }); + } + + const showLoggedInUserAttributes = () => { + Intercom.fetchLoggedInUserAttributes().then((res) => { + Alert.alert('User Attributes', JSON.stringify(res)); + }); + } + const validateEmail = (email: string | undefined) => { return String(email) .toLowerCase() @@ -295,6 +307,22 @@ export default function App() { }); }} /> +