react-native-acoustic-mobile-push-inbox-beta 3.9.37 → 3.9.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/assets/mce/plugins/rn-plugin-inbox.json +20 -0
- package/android/src/main/java/co/acoustic/mobile/push/plugin/inbox/RNAcousticMobilePushInboxModule.java +361 -552
- package/android/src/main/java/co/acoustic/mobile/push/plugin/inbox/RNPushNotificationInboxCustomAction.java +329 -0
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Copyright © 2019,
|
|
2
|
+
* Copyright © 2019, 2025 Acoustic, L.P. All rights reserved.
|
|
3
3
|
*
|
|
4
4
|
* NOTICE: This file contains material that is confidential and proprietary to
|
|
5
5
|
* Acoustic, L.P. and/or other developers. No license is granted under any intellectual or
|
|
@@ -10,10 +10,6 @@
|
|
|
10
10
|
|
|
11
11
|
package co.acoustic.mobile.push.plugin.inbox;
|
|
12
12
|
|
|
13
|
-
import com.facebook.react.ReactApplication;
|
|
14
|
-
import com.facebook.react.ReactInstanceManager;
|
|
15
|
-
import com.facebook.react.ReactNativeHost;
|
|
16
|
-
import com.facebook.react.ReactRootView;
|
|
17
13
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
18
14
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
19
15
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
@@ -21,21 +17,13 @@ import com.facebook.react.bridge.ReactMethod;
|
|
|
21
17
|
import com.facebook.react.bridge.Callback;
|
|
22
18
|
|
|
23
19
|
import android.app.Activity;
|
|
24
|
-
import android.content.Context;
|
|
25
|
-
import android.content.Intent;
|
|
26
|
-
import android.os.Bundle;
|
|
27
|
-
import android.os.Build;
|
|
28
20
|
import android.view.ViewGroup;
|
|
29
21
|
import android.view.ViewParent;
|
|
30
|
-
import android.view.Window;
|
|
31
|
-
import android.widget.FrameLayout;
|
|
32
22
|
import android.widget.RelativeLayout;
|
|
33
|
-
|
|
34
23
|
import com.facebook.react.bridge.ReadableArray;
|
|
35
24
|
import com.facebook.react.bridge.ReadableMap;
|
|
36
25
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
37
26
|
import com.facebook.react.bridge.ReadableType;
|
|
38
|
-
import com.facebook.react.bridge.WritableArray;
|
|
39
27
|
import com.facebook.react.bridge.WritableMap;
|
|
40
28
|
import com.facebook.react.bridge.WritableNativeArray;
|
|
41
29
|
import com.facebook.react.bridge.WritableNativeMap;
|
|
@@ -49,574 +37,395 @@ import co.acoustic.mobile.push.sdk.api.attribute.StringAttribute;
|
|
|
49
37
|
import co.acoustic.mobile.push.sdk.api.event.Event;
|
|
50
38
|
import co.acoustic.mobile.push.sdk.api.notification.MceNotificationAction;
|
|
51
39
|
import co.acoustic.mobile.push.sdk.api.notification.MceNotificationActionRegistry;
|
|
52
|
-
import co.acoustic.mobile.push.sdk.api.notification.NotificationDetails;
|
|
53
40
|
import co.acoustic.mobile.push.sdk.notification.MceNotificationActionImpl;
|
|
54
|
-
import co.acoustic.mobile.push.sdk.plugin.inbox.InboxMessageReference;
|
|
55
41
|
import co.acoustic.mobile.push.sdk.plugin.inbox.InboxMessagesClient;
|
|
56
42
|
import co.acoustic.mobile.push.sdk.plugin.inbox.RichContent;
|
|
57
43
|
import co.acoustic.mobile.push.sdk.plugin.inbox.RichContentDatabaseHelper;
|
|
58
|
-
import co.acoustic.mobile.push.sdk.notification.ActionImpl;
|
|
59
44
|
import co.acoustic.mobile.push.sdk.util.Logger;
|
|
60
45
|
import co.acoustic.mobile.push.sdk.api.message.MessageSync;
|
|
61
|
-
import co.acoustic.mobile.push.sdk.plugin.inbox.InboxMessageProcessor;
|
|
62
46
|
import co.acoustic.mobile.push.sdk.plugin.inbox.InboxEvents;
|
|
63
|
-
import co.acoustic.mobile.push.sdk.api.message.MessageProcessor;
|
|
64
47
|
|
|
65
48
|
import org.json.JSONArray;
|
|
66
49
|
import org.json.JSONException;
|
|
67
50
|
import org.json.JSONObject;
|
|
68
|
-
|
|
69
|
-
import java.util.ArrayList;
|
|
70
51
|
import java.util.Date;
|
|
71
52
|
import java.util.HashMap;
|
|
72
53
|
import java.util.Iterator;
|
|
73
54
|
import java.util.LinkedList;
|
|
74
55
|
import java.util.List;
|
|
75
|
-
import java.util.Map;
|
|
76
56
|
|
|
77
57
|
import static com.facebook.react.bridge.ReadableType.*;
|
|
78
|
-
import static java.lang.Thread.sleep;
|
|
79
58
|
|
|
80
59
|
public class RNAcousticMobilePushInboxModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
internalHideInbox();
|
|
156
|
-
|
|
157
|
-
showInboxMessage(msg, activity);
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
if (fromNotification) {
|
|
161
|
-
InboxEvents.sendInboxNotificationOpenedEvent(context, new ActionImpl(type, name, payload), attribution, mailingId);
|
|
162
|
-
}
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
Logger.e(TAG, "Could not find downloaded message");
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
@Override
|
|
170
|
-
public void onFailure(MessageSync.SyncReport syncReport, OperationResult result) {
|
|
171
|
-
Logger.e(TAG, "Could not download message");
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
} else {
|
|
175
|
-
activity.runOnUiThread(new Runnable() {
|
|
176
|
-
@Override
|
|
177
|
-
public void run() {
|
|
178
|
-
internalHideInbox();
|
|
179
|
-
showInboxMessage(inboxMessage, activity);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
if (fromNotification) {
|
|
183
|
-
InboxEvents.sendInboxNotificationOpenedEvent(context, new ActionImpl(type, name, payload), attribution, mailingId);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
@Override
|
|
190
|
-
public void init(Context context, JSONObject jsonObject) {
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
@Override
|
|
195
|
-
public void update(Context context, JSONObject jsonObject) {
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
@Override
|
|
200
|
-
public boolean shouldDisplayNotification(Context context, NotificationDetails notificationDetails, Bundle bundle) {
|
|
201
|
-
return true;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
@Override
|
|
205
|
-
public boolean shouldSendDefaultEvent(Context context) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
@ReactMethod
|
|
212
|
-
public void hideInbox() {
|
|
213
|
-
final Activity activity = getCurrentActivity();
|
|
214
|
-
if(activity == null) {
|
|
215
|
-
Logger.e(TAG, "Can't find activity");
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
activity.runOnUiThread(new Runnable() {
|
|
220
|
-
@Override
|
|
221
|
-
public void run() {
|
|
222
|
-
internalHideInbox();
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
// Needs to be run on the main thread.
|
|
229
|
-
private void internalHideInbox() {
|
|
230
|
-
if(this.relativeLayout != null) {
|
|
231
|
-
ViewParent parent = this.relativeLayout.getParent();
|
|
232
|
-
if(parent instanceof ViewGroup) {
|
|
233
|
-
ViewGroup group = (ViewGroup) parent;
|
|
234
|
-
group.removeView(this.relativeLayout);
|
|
235
|
-
} else {
|
|
236
|
-
Logger.e(TAG, "InApp Parent is not a ViewGroup!");
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
this.relativeLayout = null;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
// Needs to be run on the main thread.
|
|
243
|
-
private void showInboxMessage(RichContent inboxMessage, Activity activity) {
|
|
244
|
-
if(inboxActionModule==null) {
|
|
245
|
-
Logger.e(TAG, "inbox action module is not registered");
|
|
246
|
-
return;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
this.relativeLayout = new RelativeLayout(reactContext);
|
|
250
|
-
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT));
|
|
251
|
-
RelativeLayout.LayoutParams viewLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
|
|
252
|
-
|
|
253
|
-
viewLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
|
|
254
|
-
|
|
255
|
-
ReactApplication application = (ReactApplication) activity.getApplication();
|
|
256
|
-
ReactNativeHost reactNativeHost = application.getReactNativeHost();
|
|
257
|
-
ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
|
|
258
|
-
|
|
259
|
-
Bundle messageBundle = new Bundle();
|
|
260
|
-
messageBundle.putLong("sendDate", inboxMessage.getSendDate().getTime());
|
|
261
|
-
messageBundle.putLong("expirationDate", inboxMessage.getExpirationDate().getTime());
|
|
262
|
-
messageBundle.putBoolean("isDeleted", inboxMessage.getIsDeleted());
|
|
263
|
-
messageBundle.putBoolean("isRead", inboxMessage.getIsRead());
|
|
264
|
-
messageBundle.putBoolean("isExpired", inboxMessage.getIsExpired());
|
|
265
|
-
messageBundle.putString("templateName", inboxMessage.getTemplate());
|
|
266
|
-
messageBundle.putString("attribution", inboxMessage.getAttribution());
|
|
267
|
-
messageBundle.putString("mailingId", inboxMessage.getMessageId());
|
|
268
|
-
messageBundle.putString("inboxMessageId", inboxMessage.getMessageId());
|
|
269
|
-
messageBundle.putString("richContentId", inboxMessage.getContentId());
|
|
270
|
-
|
|
271
|
-
try {
|
|
272
|
-
JSONObject content = inboxMessage.getContent();
|
|
273
|
-
if (content != null) {
|
|
274
|
-
messageBundle.putBundle("content", convertJsonObjectToBundle(content));
|
|
275
|
-
}
|
|
276
|
-
} catch (Exception ex) {
|
|
277
|
-
Logger.d(TAG, "Couldn't convert inbox json content", ex);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
Bundle initialProperties = new Bundle();
|
|
281
|
-
initialProperties.putBundle("message", messageBundle);
|
|
282
|
-
|
|
283
|
-
ReactRootView reactRootView = new ReactRootView(reactContext);
|
|
284
|
-
reactRootView.setLayoutParams(viewLayout);
|
|
285
|
-
reactRootView.startReactApplication(reactInstanceManager, inboxActionModule, initialProperties);
|
|
286
|
-
relativeLayout.addView(reactRootView);
|
|
287
|
-
|
|
288
|
-
Window window = activity.getWindow();
|
|
289
|
-
FrameLayout.LayoutParams relativeLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT );
|
|
290
|
-
window.addContentView(relativeLayout, relativeLayoutParams);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
@ReactMethod
|
|
294
|
-
public void inboxMessageCount(Callback callback) {
|
|
295
|
-
RichContentDatabaseHelper.MessageCursor messageCursor = RichContentDatabaseHelper.getRichContentDatabaseHelper(reactContext).getMessages();
|
|
296
|
-
int messages = 0;
|
|
297
|
-
int unread = 0;
|
|
298
|
-
while(messageCursor.moveToNext())
|
|
299
|
-
{
|
|
300
|
-
RichContent message = messageCursor.getRichContent();
|
|
301
|
-
messages++;
|
|
302
|
-
if(!message.getIsRead()) {
|
|
303
|
-
unread++;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
WritableNativeMap map = new WritableNativeMap();
|
|
308
|
-
map.putInt("messages", messages);
|
|
309
|
-
map.putInt("unread", unread);
|
|
310
|
-
callback.invoke(map);
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
@ReactMethod
|
|
314
|
-
public void deleteInboxMessage(String inboxMessageId) {
|
|
315
|
-
InboxMessagesClient.deleteMessageById(reactContext, inboxMessageId);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
@ReactMethod
|
|
319
|
-
public void readInboxMessage(String inboxMessageId) {
|
|
60
|
+
private static final String TYPE = "openInboxMessage";
|
|
61
|
+
private static String TAG = "RNAcousticMobilePushInboxModule";
|
|
62
|
+
|
|
63
|
+
private ReactApplicationContext reactContext;
|
|
64
|
+
private static String inboxActionModule;
|
|
65
|
+
private MceNotificationAction inboxCustomAction;
|
|
66
|
+
|
|
67
|
+
public static RelativeLayout relativeLayout = null;
|
|
68
|
+
|
|
69
|
+
// Send event to javascript
|
|
70
|
+
protected void sendEvent(String eventName, WritableMap params) {
|
|
71
|
+
reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(eventName, params);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public RNAcousticMobilePushInboxModule() {}
|
|
75
|
+
|
|
76
|
+
public RNAcousticMobilePushInboxModule(ReactApplicationContext reactContext) {
|
|
77
|
+
super(reactContext);
|
|
78
|
+
this.reactContext = reactContext;
|
|
79
|
+
reactContext.addLifecycleEventListener(this);
|
|
80
|
+
|
|
81
|
+
registerInboxComponent();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public String getName() {
|
|
86
|
+
return "RNAcousticMobilePushInbox";
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@ReactMethod
|
|
90
|
+
public void registerInboxComponent(String component) {
|
|
91
|
+
inboxActionModule = component;
|
|
92
|
+
registerInboxComponent();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
private void registerInboxComponent() {
|
|
96
|
+
// Create an instance of the custom action handler
|
|
97
|
+
// if (inboxActionModule == null) {
|
|
98
|
+
inboxCustomAction = new RNPushNotificationInboxCustomAction(reactContext, inboxActionModule);
|
|
99
|
+
// }
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A custom action handler for RNPushNotificationInbox, responsible for processing inbox messages and navigating to the inbox screen when a push notification is clicked.
|
|
103
|
+
*/
|
|
104
|
+
MceNotificationActionRegistry.registerNotificationAction(reactContext, TYPE, inboxCustomAction);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
@ReactMethod
|
|
109
|
+
public void inboxMessageCount(Callback callback) {
|
|
110
|
+
RichContentDatabaseHelper.MessageCursor messageCursor = RichContentDatabaseHelper.getRichContentDatabaseHelper(reactContext).getMessages();
|
|
111
|
+
int messages = 0;
|
|
112
|
+
int unread = 0;
|
|
113
|
+
while (messageCursor.moveToNext()) {
|
|
114
|
+
RichContent message = messageCursor.getRichContent();
|
|
115
|
+
messages++;
|
|
116
|
+
if (!message.getIsRead()) {
|
|
117
|
+
unread++;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
WritableNativeMap map = new WritableNativeMap();
|
|
122
|
+
map.putInt("messages", messages);
|
|
123
|
+
map.putInt("unread", unread);
|
|
124
|
+
callback.invoke(map);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@ReactMethod
|
|
128
|
+
public void deleteInboxMessage(String inboxMessageId) {
|
|
129
|
+
InboxMessagesClient.deleteMessageById(reactContext, inboxMessageId);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
@ReactMethod
|
|
133
|
+
public void readInboxMessage(String inboxMessageId) {
|
|
320
134
|
RichContentDatabaseHelper.MessageCursor messageCursor = RichContentDatabaseHelper.getRichContentDatabaseHelper(reactContext).getMessagesByMessageId(inboxMessageId);
|
|
321
|
-
|
|
322
|
-
|
|
135
|
+
messageCursor.moveToFirst();
|
|
136
|
+
RichContent message = messageCursor.getRichContent();
|
|
323
137
|
InboxEvents.sendInboxMessageOpenedEvent(reactContext, message);
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
138
|
+
InboxMessagesClient.setMessageReadById(reactContext, inboxMessageId);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@ReactMethod
|
|
142
|
+
public void syncInboxMessages() {
|
|
143
|
+
MessageSync.syncMessages(reactContext, new OperationCallback<MessageSync.SyncReport>() {
|
|
144
|
+
@Override
|
|
145
|
+
public void onSuccess(MessageSync.SyncReport syncReport, OperationResult result) {
|
|
146
|
+
sendEvent("SyncInbox", null);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Override
|
|
150
|
+
public void onFailure(final MessageSync.SyncReport syncReport, final OperationResult result) {
|
|
151
|
+
sendEvent("SyncInbox", null);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
@ReactMethod
|
|
157
|
+
public void listInboxMessages(boolean direction, Callback callback) {
|
|
158
|
+
WritableNativeArray messages = new WritableNativeArray();
|
|
159
|
+
RichContentDatabaseHelper.MessageCursor messageCursor = RichContentDatabaseHelper.getRichContentDatabaseHelper(reactContext).getMessages();
|
|
160
|
+
while (messageCursor.moveToNext()) {
|
|
161
|
+
RichContent message = messageCursor.getRichContent();
|
|
162
|
+
WritableMap messageMap = new WritableNativeMap();
|
|
163
|
+
messageMap.putString("inboxMessageId", message.getMessageId());
|
|
164
|
+
messageMap.putString("richContentId", message.getContentId());
|
|
165
|
+
messageMap.putString("templateName", message.getTemplate());
|
|
166
|
+
messageMap.putString("attribution", message.getAttribution());
|
|
167
|
+
messageMap.putString("mailingId", message.getMessageId());
|
|
168
|
+
messageMap.putDouble("sendDate", message.getSendDate().getTime());
|
|
169
|
+
messageMap.putDouble("expirationDate", message.getExpirationDate().getTime());
|
|
170
|
+
messageMap.putBoolean("isDeleted", message.getIsDeleted());
|
|
171
|
+
messageMap.putBoolean("isRead", message.getIsRead());
|
|
172
|
+
messageMap.putBoolean("isExpired", message.getIsExpired());
|
|
173
|
+
|
|
174
|
+
try {
|
|
175
|
+
JSONObject content = message.getContent();
|
|
176
|
+
if (content != null) {
|
|
177
|
+
messageMap.putMap("content", convertJsonObject(content));
|
|
178
|
+
}
|
|
179
|
+
} catch (Exception ex) {
|
|
180
|
+
Logger.d(TAG, "Couldn't convert inbox json content", ex);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
messages.pushMap(messageMap);
|
|
184
|
+
}
|
|
185
|
+
callback.invoke(messages);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
HashMap<String, String> convertFromMapToHash(ReadableMap map) {
|
|
189
|
+
HashMap<String, String> hash = new HashMap<String, String>();
|
|
190
|
+
ReadableMapKeySetIterator keys = map.keySetIterator();
|
|
191
|
+
while (keys.hasNextKey()) {
|
|
192
|
+
String key = keys.nextKey();
|
|
193
|
+
ReadableType type = map.getType(key);
|
|
194
|
+
switch (type) {
|
|
195
|
+
case Array:
|
|
196
|
+
try {
|
|
197
|
+
JSONArray json = convertReadableArray(map.getArray(key));
|
|
198
|
+
hash.put(key, json.toString());
|
|
199
|
+
} catch (JSONException e) {
|
|
200
|
+
e.printStackTrace();
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
case Boolean:
|
|
204
|
+
Boolean bool = new Boolean(map.getBoolean(key));
|
|
205
|
+
hash.put(key, bool.toString());
|
|
206
|
+
break;
|
|
207
|
+
case Map:
|
|
208
|
+
try {
|
|
209
|
+
JSONObject json = convertReadableMap(map.getMap(key));
|
|
210
|
+
hash.put(key, json.toString());
|
|
211
|
+
} catch (JSONException e) {
|
|
212
|
+
e.printStackTrace();
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
case Null:
|
|
216
|
+
hash.put(key, "<NULL>");
|
|
217
|
+
break;
|
|
218
|
+
case Number:
|
|
219
|
+
hash.put(key, Double.toString(map.getDouble(key)));
|
|
220
|
+
break;
|
|
221
|
+
case String:
|
|
222
|
+
hash.put(key, map.getString(key));
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return hash;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
@ReactMethod
|
|
230
|
+
public void clickInboxAction(ReadableMap action, String inboxMessageId) {
|
|
231
|
+
RichContentDatabaseHelper.MessageCursor messageCursor = RichContentDatabaseHelper.getRichContentDatabaseHelper(reactContext).getMessagesByMessageId(inboxMessageId);
|
|
232
|
+
messageCursor.moveToFirst();
|
|
233
|
+
RichContent message = messageCursor.getRichContent();
|
|
234
|
+
String richContentId = message.getContentId();
|
|
235
|
+
String attribution = message.getAttribution();
|
|
236
|
+
|
|
237
|
+
// get richContentId and attribution
|
|
238
|
+
// put in event
|
|
239
|
+
String actionType = action.getString("type");
|
|
240
|
+
|
|
241
|
+
MceNotificationAction actionImpl = MceNotificationActionRegistry.getNotificationAction(reactContext, actionType);
|
|
242
|
+
if (actionImpl != null) {
|
|
243
|
+
HashMap<String, String> payload = convertFromMapToHash(action);
|
|
244
|
+
|
|
245
|
+
actionImpl.handleAction(reactContext, actionType, null, null, null, payload, false);
|
|
246
|
+
|
|
247
|
+
List<Attribute> eventAttributes = new LinkedList<Attribute>();
|
|
248
|
+
eventAttributes.add(new StringAttribute("richContentId", richContentId));
|
|
249
|
+
eventAttributes.add(new StringAttribute("inboxMessageId", inboxMessageId));
|
|
250
|
+
eventAttributes.add(new StringAttribute("actionTaken", actionType));
|
|
251
|
+
|
|
252
|
+
String name = actionType;
|
|
253
|
+
MceNotificationActionImpl.ClickEventDetails clickEventDetails = MceNotificationActionImpl.getClickEventDetails(actionType);
|
|
254
|
+
if (clickEventDetails != null) {
|
|
255
|
+
name = clickEventDetails.eventName;
|
|
256
|
+
String value = payload.get("value");
|
|
257
|
+
eventAttributes.add(new StringAttribute(clickEventDetails.valueName, value));
|
|
258
|
+
} else {
|
|
259
|
+
for (String key : payload.keySet()) {
|
|
260
|
+
eventAttributes.add(new StringAttribute(key, payload.get(key)));
|
|
261
|
+
}
|
|
262
|
+
}
|
|
449
263
|
|
|
450
264
|
Event event = new Event("inboxMessage", name, new Date(), eventAttributes, attribution, null);
|
|
451
265
|
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
return bundle;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
@Override
|
|
608
|
-
public void onHostResume() {
|
|
266
|
+
MceSdk.getEventsClient(false).sendEvent(reactContext, event, new OperationCallback<Event>() {
|
|
267
|
+
@Override
|
|
268
|
+
public void onSuccess(Event event, OperationResult result) {
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
@Override
|
|
273
|
+
public void onFailure(Event event, OperationResult result) {
|
|
274
|
+
MceSdk.getQueuedEventsClient().sendEvent(reactContext, event);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@ReactMethod
|
|
281
|
+
public void hideInbox() {
|
|
282
|
+
final Activity activity = reactContext.getCurrentActivity();
|
|
283
|
+
if (activity == null) {
|
|
284
|
+
Logger.e(TAG, "Can't find activity");
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
activity.runOnUiThread(new Runnable() {
|
|
289
|
+
@Override
|
|
290
|
+
public void run() {
|
|
291
|
+
internalHideInbox();
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
// Needs to be run on the main thread.
|
|
298
|
+
private void internalHideInbox() {
|
|
299
|
+
if (this.relativeLayout != null) {
|
|
300
|
+
ViewParent parent = this.relativeLayout.getParent();
|
|
301
|
+
if (parent instanceof ViewGroup) {
|
|
302
|
+
ViewGroup group = (ViewGroup) parent;
|
|
303
|
+
group.removeView(this.relativeLayout);
|
|
304
|
+
} else {
|
|
305
|
+
Logger.e(TAG, "InApp Parent is not a ViewGroup!");
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
this.relativeLayout = null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public static JSONArray convertReadableArray(ReadableArray readableArray) throws JSONException {
|
|
312
|
+
JSONArray jsonArray = new JSONArray();
|
|
313
|
+
for (int i = 0; i < readableArray.size(); i++) {
|
|
314
|
+
ReadableType type = readableArray.getType(i);
|
|
315
|
+
if (type == String) {
|
|
316
|
+
jsonArray.put(readableArray.getString(i));
|
|
317
|
+
} else if (type == Boolean) {
|
|
318
|
+
jsonArray.put(readableArray.getBoolean(i));
|
|
319
|
+
} else if (type == Null) {
|
|
320
|
+
jsonArray.put(JSONObject.NULL);
|
|
321
|
+
} else if (type == Number) {
|
|
322
|
+
jsonArray.put(readableArray.getDouble(i));
|
|
323
|
+
} else if (type == Map) {
|
|
324
|
+
jsonArray.put(convertReadableMap(readableArray.getMap(i)));
|
|
325
|
+
} else if (type == Array) {
|
|
326
|
+
jsonArray.put(convertReadableArray(readableArray.getArray(i)));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return jsonArray;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
public static JSONObject convertReadableMap(ReadableMap readableMap) throws JSONException {
|
|
333
|
+
JSONObject jsonObject = new JSONObject();
|
|
334
|
+
ReadableMapKeySetIterator keys = readableMap.keySetIterator();
|
|
335
|
+
while (keys.hasNextKey()) {
|
|
336
|
+
String key = keys.nextKey();
|
|
337
|
+
ReadableType type = readableMap.getType(key);
|
|
338
|
+
if (type == String) {
|
|
339
|
+
jsonObject.put(key, readableMap.getString(key));
|
|
340
|
+
} else if (type == Boolean) {
|
|
341
|
+
jsonObject.put(key, readableMap.getBoolean(key));
|
|
342
|
+
} else if (type == Null) {
|
|
343
|
+
jsonObject.put(key, JSONObject.NULL);
|
|
344
|
+
} else if (type == Number) {
|
|
345
|
+
jsonObject.put(key, readableMap.getDouble(key));
|
|
346
|
+
} else if (type == Map) {
|
|
347
|
+
jsonObject.put(key, convertReadableMap(readableMap.getMap(key)));
|
|
348
|
+
} else if (type == Array) {
|
|
349
|
+
jsonObject.put(key, convertReadableArray(readableMap.getArray(key)));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return jsonObject;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
public static WritableNativeArray convertJsonArray(JSONArray jsonArray) throws JSONException {
|
|
356
|
+
WritableNativeArray array = new WritableNativeArray();
|
|
357
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
|
358
|
+
Object value = jsonArray.get(i);
|
|
359
|
+
|
|
360
|
+
if (value == null || value == JSONObject.NULL) {
|
|
361
|
+
array.pushNull();
|
|
362
|
+
} else if (value instanceof Boolean) {
|
|
363
|
+
array.pushBoolean((Boolean) value);
|
|
364
|
+
} else if (value instanceof Integer) {
|
|
365
|
+
array.pushInt((Integer) value);
|
|
366
|
+
} else if (value instanceof Long) {
|
|
367
|
+
Long longValue = (Long) value;
|
|
368
|
+
array.pushDouble(longValue.doubleValue());
|
|
369
|
+
} else if (value instanceof Double) {
|
|
370
|
+
array.pushDouble((Double) value);
|
|
371
|
+
} else if (value instanceof String) {
|
|
372
|
+
array.pushString((String) value);
|
|
373
|
+
} else if (value instanceof JSONObject) {
|
|
374
|
+
array.pushMap(convertJsonObject((JSONObject) value));
|
|
375
|
+
} else if (value instanceof JSONArray) {
|
|
376
|
+
array.pushArray(convertJsonArray((JSONArray) value));
|
|
377
|
+
} else {
|
|
378
|
+
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return array;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
public static WritableNativeMap convertJsonObject(JSONObject jsonObject) throws JSONException {
|
|
385
|
+
WritableNativeMap map = new WritableNativeMap();
|
|
386
|
+
Iterator<String> jsonIterator = jsonObject.keys();
|
|
387
|
+
while (jsonIterator.hasNext()) {
|
|
388
|
+
String key = jsonIterator.next();
|
|
389
|
+
Object value = jsonObject.get(key);
|
|
390
|
+
|
|
391
|
+
if (value == null || value == JSONObject.NULL) {
|
|
392
|
+
map.putNull(key);
|
|
393
|
+
} else if (value instanceof Boolean) {
|
|
394
|
+
map.putBoolean(key, (Boolean) value);
|
|
395
|
+
} else if (value instanceof Integer) {
|
|
396
|
+
map.putInt(key, (Integer) value);
|
|
397
|
+
} else if (value instanceof Long) {
|
|
398
|
+
Long longValue = (Long) value;
|
|
399
|
+
map.putDouble(key, longValue.doubleValue());
|
|
400
|
+
} else if (value instanceof Double) {
|
|
401
|
+
map.putDouble(key, (Double) value);
|
|
402
|
+
} else if (value instanceof String) {
|
|
403
|
+
map.putString(key, (String) value);
|
|
404
|
+
} else if (value instanceof JSONObject) {
|
|
405
|
+
map.putMap(key, convertJsonObject((JSONObject) value));
|
|
406
|
+
} else if (value instanceof JSONArray) {
|
|
407
|
+
map.putArray(key, convertJsonArray((JSONArray) value));
|
|
408
|
+
} else {
|
|
409
|
+
throw new IllegalArgumentException("Unsupported type: " + value.getClass());
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return map;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
@Override
|
|
417
|
+
public void onHostResume() {
|
|
609
418
|
registerInboxComponent();
|
|
610
|
-
|
|
419
|
+
}
|
|
611
420
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
421
|
+
@Override
|
|
422
|
+
public void onHostPause() {
|
|
423
|
+
}
|
|
615
424
|
|
|
616
|
-
|
|
617
|
-
|
|
425
|
+
@Override
|
|
426
|
+
public void onHostDestroy() {
|
|
618
427
|
|
|
619
|
-
|
|
428
|
+
}
|
|
620
429
|
|
|
621
430
|
@ReactMethod
|
|
622
431
|
public void addListener(String eventName) {
|