22
33import android .app .Activity ;
44import android .app .Application ;
5+ import android .content .Intent ;
56import android .util .Log ;
67import android .widget .Toast ;
78
3738import io .intercom .android .sdk .helpcenter .sections .HelpCenterCollectionContent ;
3839import io .intercom .android .sdk .identity .Registration ;
3940import io .intercom .android .sdk .push .IntercomPushClient ;
41+ import android .app .TaskStackBuilder ;
4042
4143@ ReactModule (name = IntercomModule .NAME )
4244public class IntercomModule extends ReactContextBaseJavaModule {
@@ -65,11 +67,25 @@ public static boolean isIntercomPush(RemoteMessage remoteMessage) {
6567 }
6668 }
6769
68- public static void handleRemotePushMessage (@ NonNull Application application , RemoteMessage
69- remoteMessage ) {
70+ public static void handleRemotePushWithCustomStack (@ NonNull Application application , RemoteMessage remoteMessage ,
71+ TaskStackBuilder customStack ) {
7072 try {
71- Map message = remoteMessage .getData ();
72- intercomPushClient .handlePush (application , message );
73+ Map <String , String > message = remoteMessage .getData ();
74+ intercomPushClient .handlePushWithCustomStack (application , message , customStack );
75+ } catch (Exception err ) {
76+ Log .e (NAME , "handlePushWithCustomStack error:" );
77+ Log .e (NAME , err .toString ());
78+ }
79+ }
80+
81+ public static void handleRemotePushMessage (@ NonNull Application application , RemoteMessage remoteMessage ) {
82+ try {
83+ TaskStackBuilder customStack = TaskStackBuilder .create (application );
84+ Intent launchIntent = application .getPackageManager ().getLaunchIntentForPackage (application .getPackageName ());
85+ if (launchIntent != null ) {
86+ customStack .addNextIntent (launchIntent );
87+ }
88+ handleRemotePushWithCustomStack (application , remoteMessage , customStack );
7389 } catch (Exception err ) {
7490 Log .e (NAME , "handleRemotePushMessage error:" );
7591 Log .e (NAME , err .toString ());
@@ -107,8 +123,7 @@ public void sendTokenToIntercom(@NonNull String token, Promise promise) {
107123 Log .e (NAME , "no current activity" );
108124 }
109125
110- } catch (
111- Exception err ) {
126+ } catch (Exception err ) {
112127 Log .e (NAME , "sendTokenToIntercom error:" );
113128 Log .e (NAME , err .toString ());
114129 promise .reject (IntercomErrorCodes .SEND_TOKEN_TO_INTERCOM , err .toString ());
@@ -117,24 +132,25 @@ public void sendTokenToIntercom(@NonNull String token, Promise promise) {
117132
118133 @ ReactMethod
119134 public void loginUnidentifiedUser (Promise promise ) {
120- Intercom .client ().loginUnidentifiedUser (new IntercomStatusCallback () {
121- @ Override
122- public void onSuccess () {
123- promise .resolve (true );
124- }
135+ Intercom .client ().loginUnidentifiedUser (new IntercomStatusCallback () {
136+ @ Override
137+ public void onSuccess () {
138+ promise .resolve (true );
139+ }
125140
126- @ Override
127- public void onFailure (@ NonNull IntercomError intercomError ) {
128- Log .e ("ERROR" , intercomError .getErrorMessage ());
129- promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
130- }
131- });
141+ @ Override
142+ public void onFailure (@ NonNull IntercomError intercomError ) {
143+ Log .e ("ERROR" , intercomError .getErrorMessage ());
144+ promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
145+ }
146+ });
132147 }
133148
134149 @ ReactMethod
135150 public void loginUserWithUserAttributes (ReadableMap params , Promise promise ) {
136151 Boolean hasEmail = params .hasKey ("email" ) && IntercomHelpers .getValueAsStringForKey (params , "email" ).length () > 0 ;
137- Boolean hasUserId = params .hasKey ("userId" ) && IntercomHelpers .getValueAsStringForKey (params , "userId" ).length () > 0 ;
152+ Boolean hasUserId = params .hasKey ("userId" )
153+ && IntercomHelpers .getValueAsStringForKey (params , "userId" ).length () > 0 ;
138154 Registration registration = null ;
139155 if (hasEmail && hasUserId ) {
140156 String email = IntercomHelpers .getValueAsStringForKey (params , "email" );
@@ -181,19 +197,19 @@ public void setUserHash(String userHash, Promise promise) {
181197
182198 @ ReactMethod
183199 public void updateUser (ReadableMap params , Promise promise ) {
184- UserAttributes userAttributes = IntercomHelpers .buildUserAttributes (params );
185- Intercom .client ().updateUser (userAttributes , new IntercomStatusCallback () {
186- @ Override
187- public void onSuccess () {
188- promise .resolve (true );
189- }
200+ UserAttributes userAttributes = IntercomHelpers .buildUserAttributes (params );
201+ Intercom .client ().updateUser (userAttributes , new IntercomStatusCallback () {
202+ @ Override
203+ public void onSuccess () {
204+ promise .resolve (true );
205+ }
190206
191- @ Override
192- public void onFailure (@ NonNull IntercomError intercomError ) {
193- Log .e ("ERROR" , intercomError .getErrorMessage ());
194- promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
195- }
196- });
207+ @ Override
208+ public void onFailure (@ NonNull IntercomError intercomError ) {
209+ Log .e ("ERROR" , intercomError .getErrorMessage ());
210+ promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
211+ }
212+ });
197213 }
198214
199215 @ ReactMethod
@@ -358,7 +374,6 @@ public void presentContent(ReadableMap params, Promise promise) {
358374 }
359375 }
360376
361-
362377 @ ReactMethod
363378 public void fetchHelpCenterCollections (Promise promise ) {
364379 try {
@@ -400,7 +415,8 @@ public void fetchHelpCenterCollection(String collectionId, Promise promise) {
400415 CollectionContentRequestCallback collectionContentCallback = new CollectionContentRequestCallback () {
401416 @ Override
402417 public void onComplete (@ NotNull HelpCenterCollectionContent helpCenterCollectionContent ) {
403- promise .resolve (IntercomHelpCenterHelpers .parseHelpCenterCollectionsContentToReadableMap (helpCenterCollectionContent ));
418+ promise .resolve (
419+ IntercomHelpCenterHelpers .parseHelpCenterCollectionsContentToReadableMap (helpCenterCollectionContent ));
404420 }
405421
406422 @ Override
@@ -435,7 +451,8 @@ public void searchHelpCenter(String searchTerm, Promise promise) {
435451 SearchRequestCallback collectionContentCallback = new SearchRequestCallback () {
436452 @ Override
437453 public void onComplete (@ NotNull List <HelpCenterArticleSearchResult > helpCenterArticleSearchResult ) {
438- promise .resolve (IntercomHelpCenterHelpers .parseHelpCenterArticleSearchToReadableArray (helpCenterArticleSearchResult ));
454+ promise .resolve (
455+ IntercomHelpCenterHelpers .parseHelpCenterArticleSearchToReadableArray (helpCenterArticleSearchResult ));
439456 }
440457
441458 @ Override
0 commit comments