19
19
import com .facebook .react .bridge .WritableArray ;
20
20
import com .facebook .react .bridge .WritableMap ;
21
21
22
- import java .security .InvalidKeyException ;
23
- import java .security .NoSuchAlgorithmException ;
24
- import java .util .Formatter ;
25
22
import java .util .List ;
26
23
import java .util .Map ;
27
24
28
- import javax .crypto .Mac ;
29
- import javax .crypto .spec .SecretKeySpec ;
30
-
31
25
public class RNBatchPushModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
32
26
33
27
private final ReactApplicationContext reactContext ;
34
28
private String batchAPIKey ;
35
- private String batchInboxSecret ;
36
29
37
30
public RNBatchPushModule (ReactApplicationContext reactContext ) {
38
31
super (reactContext );
@@ -44,12 +37,6 @@ public RNBatchPushModule(ReactApplicationContext reactContext) {
44
37
String packageName = reactContext .getApplicationContext ().getPackageName ();
45
38
this .batchAPIKey = resources .getString (resources .getIdentifier ("BATCH_API_KEY" , "string" , packageName ));
46
39
47
- // Inbox is optional
48
- int batchInboxSecretIdentifier = resources .getIdentifier ("BATCH_INBOX_SECRET" , "string" , packageName );
49
- if (batchInboxSecretIdentifier > 0 ) {
50
- this .batchInboxSecret = resources .getString (batchInboxSecretIdentifier );
51
- }
52
-
53
40
Batch .Push .setGCMSenderId (resources .getString (resources .getIdentifier ("GCM_SENDER_ID" , "string" , packageName )));
54
41
Batch .setConfig (new Config (this .batchAPIKey ));
55
42
@@ -88,14 +75,9 @@ public void logoutUser() {
88
75
}
89
76
90
77
@ ReactMethod
91
- public void fetchNewNotifications (String userID , final Promise promise ) {
78
+ public void fetchNewNotifications (String userID , String authKey , final Promise promise ) {
92
79
try {
93
- SecretKeySpec signinKey = new SecretKeySpec (this .batchInboxSecret .getBytes (), "HmacSHA256" );
94
- Mac mac = Mac .getInstance ("HmacSHA256" );
95
- mac .init (signinKey );
96
- String hash = toHexString (mac .doFinal ((this .batchAPIKey + userID ).getBytes ()));
97
-
98
- BatchInboxFetcher inboxFetcher = Batch .Inbox .getFetcher (userID , hash );
80
+ BatchInboxFetcher inboxFetcher = Batch .Inbox .getFetcher (userID , authKey );
99
81
inboxFetcher .fetchNewNotifications (new BatchInboxFetcher .OnNewNotificationsFetchedListener () {
100
82
public void onFetchSuccess (@ NonNull List <BatchInboxNotificationContent > notifications , boolean foundNewNotifications , boolean endReached ) {
101
83
WritableArray jsNotifications = Arguments .createArray ();
@@ -120,25 +102,11 @@ public void onFetchFailure(@NonNull String error) {
120
102
promise .reject ("BATCH_ERROR" , "Error fetching new notifications: " + error );
121
103
}
122
104
});
123
- } catch (NoSuchAlgorithmException exception ) {
124
- Log .e ("RNBatchPush" , "HmacSHA256 is not available" );
125
- } catch (InvalidKeyException exception ) {
126
- Log .e ("RNBatchPush" , "Key is invalid" );
127
105
} catch (Exception exception ) {
128
106
Log .e ("RNBatchPush" , "Unknown exception: " + exception .getMessage ());
129
107
}
130
108
}
131
109
132
- private static String toHexString (byte [] bytes ) {
133
- Formatter formatter = new Formatter ();
134
-
135
- for (byte b : bytes ) {
136
- formatter .format ("%02x" , b );
137
- }
138
-
139
- return formatter .toString ();
140
- }
141
-
142
110
@ Override
143
111
public void onHostResume ()
144
112
{
0 commit comments