|
7 | 7 | import androidx.annotation.NonNull; |
8 | 8 | import androidx.annotation.Nullable; |
9 | 9 |
|
| 10 | +import com.facebook.react.bridge.Arguments; |
10 | 11 | import com.facebook.react.bridge.Promise; |
11 | 12 | import com.facebook.react.bridge.ReactApplicationContext; |
12 | 13 | import com.facebook.react.bridge.ReactContextBaseJavaModule; |
13 | 14 | import com.facebook.react.bridge.ReactMethod; |
14 | 15 | import com.facebook.react.bridge.ReadableArray; |
15 | 16 | import com.facebook.react.bridge.ReadableMap; |
16 | 17 | import com.facebook.react.module.annotations.ReactModule; |
| 18 | +import com.facebook.react.bridge.WritableMap; |
| 19 | +import com.facebook.react.bridge.WritableArray; |
17 | 20 | import com.google.firebase.messaging.RemoteMessage; |
18 | 21 |
|
| 22 | +import org.jetbrains.annotations.NotNull; |
| 23 | + |
19 | 24 | import java.util.List; |
20 | 25 | import java.util.Map; |
21 | 26 |
|
22 | 27 | import io.intercom.android.sdk.Intercom; |
23 | 28 | import io.intercom.android.sdk.UserAttributes; |
24 | 29 | import io.intercom.android.sdk.api.ReactNativeHeaderInterceptor; |
| 30 | +import io.intercom.android.sdk.helpcenter.api.CollectionRequestCallback; |
| 31 | +import io.intercom.android.sdk.helpcenter.collections.HelpCenterCollection; |
25 | 32 | import io.intercom.android.sdk.identity.Registration; |
26 | 33 | import io.intercom.android.sdk.push.IntercomPushClient; |
27 | 34 |
|
@@ -289,6 +296,47 @@ public void displayHelpCenterCollections(ReadableArray collectionsId, Promise pr |
289 | 296 | } |
290 | 297 | } |
291 | 298 |
|
| 299 | + @ReactMethod |
| 300 | + public void fetchHelpCenterCollections(Promise promise) { |
| 301 | + try { |
| 302 | + |
| 303 | + CollectionRequestCallback collectionRequestCallback = new CollectionRequestCallback() { |
| 304 | + @Override |
| 305 | + public void onComplete(@NotNull List<HelpCenterCollection> list) { |
| 306 | + HelpCenterCollection[] returnArray = new HelpCenterCollection[list.size()]; |
| 307 | + |
| 308 | + returnArray = list.toArray(returnArray); |
| 309 | + WritableArray promiseArray = Arguments.createArray(); |
| 310 | + for (HelpCenterCollection helpCenterCollection : returnArray) { |
| 311 | + WritableMap item = Arguments.createMap(); |
| 312 | + item.putString("id", helpCenterCollection.getId()); |
| 313 | + item.putString("title", helpCenterCollection.getTitle()); |
| 314 | + item.putString("summary", helpCenterCollection.getSummary()); |
| 315 | + promiseArray.pushMap(item); |
| 316 | + } |
| 317 | + promise.resolve(promiseArray); |
| 318 | + } |
| 319 | + |
| 320 | + @Override |
| 321 | + public void onError(int i) { |
| 322 | + promise.reject(String.valueOf(i), "fetchHelpCenterCollections error"); |
| 323 | + } |
| 324 | + |
| 325 | + @Override |
| 326 | + public void onFailure() { |
| 327 | + promise.reject("901", "fetchHelpCenterCollections faliure"); |
| 328 | + } |
| 329 | + }; |
| 330 | + |
| 331 | + Intercom.client().fetchHelpCenterCollections(collectionRequestCallback); |
| 332 | + |
| 333 | + } catch (Exception err) { |
| 334 | + Log.e(NAME, "fetchHelpCenterCollections error:"); |
| 335 | + Log.e(NAME, err.toString()); |
| 336 | + promise.reject(IntercomErrorCodes.DISPLAY_HELP_CENTER_COLLECTIONS, err.toString()); |
| 337 | + } |
| 338 | + } |
| 339 | + |
292 | 340 | @ReactMethod |
293 | 341 | public void displayCarousel(String carouselId, Promise promise) { |
294 | 342 | try { |
|
0 commit comments