pushwoosh-react-native-plugin 1.2.5 → 2.2.17

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.
Files changed (66) hide show
  1. package/.github/ISSUE_TEMPLATE/bug_report.yml +135 -0
  2. package/.github/ISSUE_TEMPLATE/feature_request.yml +31 -0
  3. package/.github/ISSUE_TEMPLATE/question.yml +28 -0
  4. package/InlineInApp.js +71 -0
  5. package/README.md +35 -85
  6. package/docs/README.md +230 -11
  7. package/index.d.ts +91 -0
  8. package/index.js +536 -154
  9. package/package.json +12 -1
  10. package/pushwoosh-react-native-plugin.podspec +20 -0
  11. package/react-native.config.js +9 -0
  12. package/scripts/add_inbox_ios_resources.js +42 -0
  13. package/src/android/build.gradle +40 -10
  14. package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  15. package/src/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  16. package/src/android/gradlew +160 -0
  17. package/src/android/gradlew.bat +90 -0
  18. package/src/android/src/main/AndroidManifest.xml +19 -54
  19. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/ConversionUtil.java +214 -148
  20. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/CustomFirebaseMessagingService.java +29 -0
  21. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/EventDispatcher.java +10 -2
  22. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InboxUiStyleManager.java +162 -0
  23. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/InlineInAppManager.java +48 -0
  24. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshNotificationServiceExtension.java +44 -0
  25. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPackage.java +4 -2
  26. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PushwooshPlugin.java +608 -297
  27. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/RCTInlineInAppView.java +75 -0
  28. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/internal/ReactNativePluginProvider.java +15 -0
  29. package/src/ios/PWAppDelegate.h +20 -0
  30. package/src/ios/PWGDPRManager.h +46 -0
  31. package/src/ios/PWIInboxStyle.h +122 -0
  32. package/src/ios/PWIInboxUI.h +39 -0
  33. package/src/ios/PWInAppManager.h +176 -0
  34. package/src/ios/PWInbox.h +147 -0
  35. package/src/ios/PWInlineInAppView.h +26 -0
  36. package/src/ios/PWLog.h +23 -0
  37. package/src/ios/PWMessaging.h +20 -0
  38. package/src/ios/PWNotificationExtensionManager.h +46 -0
  39. package/src/ios/PWRichMediaManager.h +123 -0
  40. package/src/ios/PWRichMediaStyle.h +122 -0
  41. package/src/ios/PushNotificationManager.h +234 -111
  42. package/src/ios/Pushwoosh.h +623 -0
  43. package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
  44. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
  45. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
  46. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
  47. package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
  48. package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
  49. package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
  50. package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
  51. package/src/ios/PushwooshInboxUI.h +19 -0
  52. package/src/ios/PushwooshPlugin/PWEventDispatcher.h +1 -1
  53. package/src/ios/PushwooshPlugin/PWInlineInAppManager.h +17 -0
  54. package/src/ios/PushwooshPlugin/PWInlineInAppManager.m +54 -0
  55. package/src/ios/PushwooshPlugin/Pushwoosh.h +19 -2
  56. package/src/ios/PushwooshPlugin/Pushwoosh.m +552 -75
  57. package/src/ios/PushwooshPlugin.xcodeproj/project.pbxproj +27 -6
  58. package/src/ios/libPushwoosh.a +0 -0
  59. package/src/ios/libPushwooshInboxUI.a +0 -0
  60. package/.npmignore +0 -3
  61. package/src/android/.npmignore +0 -1
  62. package/src/android/pushwooshplugin.iml +0 -145
  63. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/NotificationReceiver.java +0 -42
  64. package/src/android/src/main/java/com/pushwoosh/reactnativeplugin/PostEventActivity.java +0 -45
  65. package/src/ios/Pushwoosh.a +0 -0
  66. package/src/ios/PushwooshPlugin.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
@@ -1,318 +1,629 @@
1
1
  package com.pushwoosh.reactnativeplugin;
2
2
 
3
3
  import android.app.Activity;
4
- import android.content.BroadcastReceiver;
4
+ import android.os.Bundle;
5
5
  import android.content.Context;
6
6
  import android.content.Intent;
7
- import android.content.IntentFilter;
8
- import android.content.pm.ApplicationInfo;
9
- import android.content.pm.PackageManager;
7
+ import android.graphics.Color;
8
+ import android.text.TextUtils;
9
+
10
+ import androidx.annotation.NonNull;
11
+ import androidx.annotation.Nullable;
10
12
 
11
13
  import com.facebook.react.bridge.Callback;
12
14
  import com.facebook.react.bridge.LifecycleEventListener;
13
- import com.facebook.react.bridge.NativeModule;
14
15
  import com.facebook.react.bridge.ReactApplicationContext;
15
- import com.facebook.react.bridge.ReactContext;
16
16
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
17
17
  import com.facebook.react.bridge.ReactMethod;
18
+ import com.facebook.react.bridge.ReadableArray;
18
19
  import com.facebook.react.bridge.ReadableMap;
19
- import com.pushwoosh.BasePushMessageReceiver;
20
- import com.pushwoosh.BaseRegistrationReceiver;
21
- import com.pushwoosh.PushManager;
22
- import com.pushwoosh.SendPushTagsCallBack;
23
- import com.pushwoosh.inapp.InAppFacade;
24
- import com.pushwoosh.internal.utils.JsonUtils;
20
+ import com.facebook.react.bridge.WritableNativeArray;
21
+ import com.pushwoosh.GDPRManager;
22
+ import com.pushwoosh.Pushwoosh;
23
+ import com.pushwoosh.RegisterForPushNotificationsResultData;
24
+ import com.pushwoosh.badge.PushwooshBadge;
25
+ import com.pushwoosh.exception.GetTagsException;
26
+ import com.pushwoosh.exception.PushwooshException;
27
+ import com.pushwoosh.exception.SetUserIdException;
28
+ import com.pushwoosh.exception.RegisterForPushNotificationsException;
29
+ import com.pushwoosh.exception.UnregisterForPushNotificationException;
30
+ import com.pushwoosh.function.Result;
31
+ import com.pushwoosh.inapp.PushwooshInApp;
32
+ import com.pushwoosh.inbox.PushwooshInbox;
33
+ import com.pushwoosh.inbox.data.InboxMessage;
34
+ import com.pushwoosh.inbox.exception.InboxMessagesException;
35
+ import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
36
+ import com.pushwoosh.internal.network.NetworkModule;
37
+ import com.pushwoosh.internal.platform.AndroidPlatformModule;
25
38
  import com.pushwoosh.internal.utils.PWLog;
39
+ import com.pushwoosh.notification.PushwooshNotificationSettings;
40
+ import com.pushwoosh.notification.SoundType;
41
+ import com.pushwoosh.notification.VibrateType;
42
+ import com.pushwoosh.tags.TagsBundle;
43
+ import com.pushwoosh.notification.LocalNotification;
44
+ import com.pushwoosh.notification.LocalNotificationReceiver;
45
+
46
+ import org.json.JSONObject;
26
47
 
27
48
  import java.util.ArrayList;
28
- import java.util.List;
29
- import java.util.Map;
30
- import java.util.Objects;
49
+ import java.util.Collection;
31
50
 
32
51
  public class PushwooshPlugin extends ReactContextBaseJavaModule implements LifecycleEventListener {
33
52
 
34
- static final String TAG = "ReactNativePlugin";
35
-
36
- private PushManager mPushManager;
37
-
38
- private static EventDispatcher mEventDispatcher = new EventDispatcher();
39
-
40
- private boolean mBroadcastPush = true;
41
-
42
- private static String mStartPushData;
43
- private static Object mStartPushLock = new Object();
44
- private static boolean mPushCallbackRegistered = false;
45
-
46
- BroadcastReceiver mRegistationReceiver = new BaseRegistrationReceiver() {
47
- @Override
48
- protected void onRegisterActionReceive(Context context, Intent intent) {
49
- if (intent == null) {
50
- return;
51
- }
52
-
53
- else if (intent.hasExtra(PushManager.REGISTER_EVENT)) {
54
- String pushToken = intent.getExtras().getString(PushManager.REGISTER_EVENT);
55
- mEventDispatcher.dispatchEvent(PushManager.REGISTER_EVENT, pushToken);
56
- }
57
- else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) {
58
- String pushToken = intent.getExtras().getString(PushManager.UNREGISTER_EVENT);
59
- mEventDispatcher.dispatchEvent(PushManager.UNREGISTER_EVENT, pushToken);
60
- }
61
- else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) {
62
- String errorMessage = intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT);
63
- mEventDispatcher.dispatchEvent(PushManager.REGISTER_ERROR_EVENT, errorMessage);
64
- }
65
- else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) {
66
- String errorMessage = intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT);
67
- mEventDispatcher.dispatchEvent(PushManager.UNREGISTER_ERROR_EVENT, errorMessage);
68
- }
69
- }
70
- };
71
-
72
- BroadcastReceiver mPushMessageReceiver = new BasePushMessageReceiver() {
73
- @Override
74
- protected void onMessageReceive(Intent intent) {
75
- if (intent == null) {
76
- return;
77
- }
78
-
79
- String pushData = intent.getStringExtra(JSON_DATA_KEY);
80
- openPush(pushData);
81
- }
82
- };
83
-
84
- public PushwooshPlugin(ReactApplicationContext reactContext) {
85
- super(reactContext);
86
-
87
- try {
88
- String packageName = reactContext.getPackageName();
89
- ApplicationInfo ai = reactContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
90
-
91
- if (ai.metaData != null) {
92
- mBroadcastPush = ai.metaData.getBoolean("PW_BROADCAST_PUSH", true);
93
- }
94
- }
95
- catch (Exception e) {
53
+ static final String TAG = "ReactNativePlugin";
54
+ private static final String PUSH_OPEN_EVENT = "PwPushOpened";
55
+ private static final String PUSH_OPEN_JS_EVENT = "pushOpened";
56
+
57
+ private static final String PUSH_RECEIVED_EVENT = Pushwoosh.PUSH_RECEIVE_EVENT;
58
+ private static final String PUSH_RECEIVED_JS_EVENT = "pushReceived";
59
+
60
+ private static EventDispatcher mEventDispatcher = new EventDispatcher();
61
+
62
+ private static String sReceivedPushData;
63
+ private static boolean sReceivedPushCallbackRegistered = false;
64
+
65
+ private static String sStartPushData;
66
+ private static boolean sPushCallbackRegistered = false;
67
+
68
+ private static boolean sInitialized = false;
69
+ private static final Object sStartPushLock = new Object();
70
+
71
+ private static PushwooshPlugin INSTANCE = null;
72
+
73
+ private InboxUiStyleManager inboxUiInboxUiStyleManager;
74
+
75
+ public PushwooshPlugin(ReactApplicationContext reactContext) {
76
+ super(reactContext);
77
+
78
+ INSTANCE = this;
79
+
80
+ reactContext.addLifecycleEventListener(this);
81
+
82
+ Context applicationContext = AndroidPlatformModule.getApplicationContext();
83
+ inboxUiInboxUiStyleManager = new InboxUiStyleManager(applicationContext);
84
+ }
85
+
86
+ ///
87
+ /// Module API
88
+ ///
89
+
90
+ @Override
91
+ public String getName() {
92
+ return "Pushwoosh";
93
+ }
94
+
95
+
96
+ @ReactMethod
97
+ public void init(ReadableMap config, Callback success, Callback error) {
98
+ String appId = config.getString("pw_appid");
99
+ String projectId = config.getString("project_number");
100
+
101
+ if (appId == null || projectId == null) {
102
+ if (error != null) {
103
+ error.invoke("Pushwoosh Application id and GCM project number not specified");
104
+ }
105
+ return;
106
+ }
107
+
108
+ if (config.hasKey("reverse_proxy_url")) {
109
+ String proxyUrl = config.getString("reverse_proxy_url");
110
+ if (!TextUtils.isEmpty(proxyUrl) && NetworkModule.getRequestManager() != null) {
111
+ NetworkModule.getRequestManager().setReverseProxyUrl(proxyUrl);
112
+ }
113
+ }
114
+
115
+ Pushwoosh.getInstance().setAppId(appId);
116
+
117
+ if (!TextUtils.isEmpty(projectId)) {
118
+ Pushwoosh.getInstance().setSenderId(projectId);
119
+ }
120
+
121
+ synchronized (sStartPushLock) {
122
+ if (sReceivedPushData != null) {
123
+ sendEvent(PUSH_RECEIVED_JS_EVENT, ConversionUtil.stringToJSONObject(sReceivedPushData));
124
+ }
125
+
126
+ if (sStartPushData != null) {
127
+ sendEvent(PUSH_OPEN_JS_EVENT, ConversionUtil.stringToJSONObject(sStartPushData));
128
+ }
129
+ }
130
+
131
+ sInitialized = true;
132
+
133
+ if (success != null) {
134
+ success.invoke();
135
+ }
136
+ }
137
+
138
+ @ReactMethod
139
+ public void register(final Callback success, final Callback error) {
140
+ Pushwoosh.getInstance().registerForPushNotifications(new RegisterForPushNotificationCallback(success, error));
141
+ }
142
+
143
+ @ReactMethod
144
+ public void unregister(final Callback success, final Callback error) {
145
+ Pushwoosh.getInstance().unregisterForPushNotifications(new com.pushwoosh.function.Callback<String, UnregisterForPushNotificationException>() {
146
+ @Override
147
+ public void process(Result<String, UnregisterForPushNotificationException> result) {
148
+ if (result.isSuccess()) {
149
+ if (success != null) {
150
+ success.invoke(result.getData());
151
+ }
152
+ } else if (result.getException() != null) {
153
+ if (error != null) {
154
+ error.invoke(result.getException().getLocalizedMessage());
155
+ }
156
+ }
157
+ }
158
+ });
159
+ }
160
+
161
+ @ReactMethod
162
+ public void onPushOpen(Callback callback) {
163
+ synchronized (sStartPushLock) {
164
+ if (!sPushCallbackRegistered && sStartPushData != null) {
165
+ callback.invoke(ConversionUtil.toWritableMap(ConversionUtil.stringToJSONObject(sStartPushData)));
166
+ sPushCallbackRegistered = true;
167
+ return;
168
+ }
169
+
170
+ sPushCallbackRegistered = true;
171
+ mEventDispatcher.subscribe(PUSH_OPEN_EVENT, callback);
172
+ }
173
+ }
174
+
175
+ @ReactMethod
176
+ public void onPushReceived(Callback callback) {
177
+ synchronized (sStartPushLock) {
178
+ if (!sReceivedPushCallbackRegistered && sReceivedPushData != null) {
179
+ callback.invoke(ConversionUtil.toWritableMap(ConversionUtil.stringToJSONObject(sReceivedPushData)));
180
+ sReceivedPushCallbackRegistered = true;
181
+ return;
182
+ }
183
+
184
+ sReceivedPushCallbackRegistered = true;
185
+ mEventDispatcher.subscribe(PUSH_RECEIVED_EVENT, callback);
186
+ }
187
+ }
188
+
189
+ @ReactMethod
190
+ public void setTags(ReadableMap tags, final Callback success, final Callback error) {
191
+ Pushwoosh.getInstance().sendTags(ConversionUtil.convertToTagsBundle(tags), new com.pushwoosh.function.Callback<Void, PushwooshException>() {
192
+ @Override
193
+ public void process(Result<Void, PushwooshException> result) {
194
+ if (result.isSuccess()) {
195
+ if (success != null) {
196
+ success.invoke();
197
+ }
198
+ } else {
199
+ if (error != null) {
200
+ error.invoke(result.getException().getMessage());
201
+ }
202
+ }
203
+ }
204
+ });
205
+ }
206
+
207
+ @ReactMethod
208
+ public void getTags(final Callback success, final Callback error) {
209
+ Pushwoosh.getInstance().getTags(new com.pushwoosh.function.Callback<TagsBundle, GetTagsException>() {
210
+ @Override
211
+ public void process(Result<TagsBundle, GetTagsException> result) {
212
+ if (result.isSuccess()) {
213
+ if (success != null && result.getData() != null) {
214
+ success.invoke(ConversionUtil.toWritableMap(result.getData().toJson()));
215
+ }
216
+ } else {
217
+ if (error != null && result.getException() != null) {
218
+ error.invoke(result.getException().getMessage());
219
+ }
220
+ }
221
+ }
222
+ });
223
+ }
224
+
225
+ @ReactMethod
226
+ public void getPushToken(Callback callback) {
227
+ callback.invoke(Pushwoosh.getInstance().getPushToken());
228
+ }
229
+
230
+ @ReactMethod
231
+ public void getHwid(Callback callback) {
232
+ callback.invoke(Pushwoosh.getInstance().getHwid());
233
+ }
234
+
235
+ @ReactMethod
236
+ public void setUserId(String userId) {
237
+ PushwooshInApp.getInstance().setUserId(userId);
238
+ }
239
+
240
+ @ReactMethod
241
+ public void setUserId(String userId, final Callback success, final Callback error) {
242
+ Pushwoosh.getInstance().setUserId(userId, new com.pushwoosh.function.Callback<Boolean, SetUserIdException>() {
243
+ @Override
244
+ public void process(Result<Boolean, SetUserIdException> result) {
245
+ if (result.isSuccess()) {
246
+ if (success != null) {
247
+ success.invoke();
248
+ }
249
+ } else {
250
+ if (error != null) {
251
+ error.invoke(result.getException().getMessage());
252
+ }
253
+ }
254
+ }
255
+ });
256
+ }
257
+
258
+ @ReactMethod
259
+ public void postEvent(String event, ReadableMap attributes) {
260
+ PushwooshInApp.getInstance().postEvent(event, ConversionUtil.convertToTagsBundle(attributes));
261
+ }
262
+
263
+ @ReactMethod
264
+ public void createLocalNotification(ReadableMap data){
265
+
266
+ JSONObject params = ConversionUtil.toJsonObject(data);
267
+
268
+ String message = params.optString("msg");
269
+ if (message == null){
270
+ return;
271
+ }
272
+ int seconds = params.optInt("seconds");
273
+ Bundle extras = new Bundle();
274
+ String userData = params.optString("userData");
275
+ if (userData!=null){
276
+ extras.putString("u", userData);
277
+ }
278
+
279
+ LocalNotification.Builder builder = new LocalNotification.Builder();
280
+ if (extras != null){
281
+ builder.setExtras(extras);
282
+ }
283
+ LocalNotification notification = builder
284
+ .setMessage(message)
285
+ .setDelay(seconds)
286
+ .build();
287
+
288
+ Pushwoosh.getInstance().scheduleLocalNotification(notification);
289
+ }
290
+
291
+ @ReactMethod
292
+ public void clearLocalNotification(){
293
+ LocalNotificationReceiver.cancelAll();
294
+ }
295
+
296
+ @ReactMethod
297
+ public void clearNotificationCenter() {
298
+ if (AndroidPlatformModule.getManagerProvider() != null) {
299
+ if (AndroidPlatformModule.getManagerProvider().getNotificationManager() != null) {
300
+ AndroidPlatformModule.getManagerProvider().getNotificationManager().cancelAll();
301
+ }
302
+ }
303
+ }
304
+
305
+ @ReactMethod
306
+ public void setApplicationIconBadgeNumber(int badgeNumber) {
307
+ PushwooshBadge.setBadgeNumber(badgeNumber);
308
+ }
309
+
310
+ @ReactMethod
311
+ public void getApplicationIconBadgeNumber(Callback callback) {
312
+ callback.invoke(PushwooshBadge.getBadgeNumber());
313
+ }
314
+
315
+ @ReactMethod
316
+ public void addToApplicationIconBadgeNumber(int badgeNumber) {
317
+ PushwooshBadge.addBadgeNumber(badgeNumber);
318
+ }
319
+
320
+ @ReactMethod
321
+ public void setMultiNotificationMode(boolean on) {
322
+ PushwooshNotificationSettings.setMultiNotificationMode(on);
323
+ }
324
+
325
+ @ReactMethod
326
+ public void setLightScreenOnNotification(boolean on) {
327
+ PushwooshNotificationSettings.setLightScreenOnNotification(on);
328
+ }
329
+
330
+ @ReactMethod
331
+ public void setEnableLED(boolean on) {
332
+ PushwooshNotificationSettings.setEnableLED(on);
333
+ }
334
+
335
+ @ReactMethod
336
+ public void setColorLED(int color) {
337
+ PushwooshNotificationSettings.setColorLED(color);
338
+ }
339
+
340
+ @ReactMethod
341
+ public void setSoundType(int type) {
342
+ PushwooshNotificationSettings.setSoundNotificationType(SoundType.fromInt(type));
343
+ }
344
+
345
+ @ReactMethod
346
+ public void setVibrateType(int type) {
347
+ PushwooshNotificationSettings.setVibrateNotificationType(VibrateType.fromInt(type));
348
+ }
349
+
350
+
351
+ @ReactMethod
352
+ public void presentInboxUI(final ReadableMap mapStyle) {
353
+ if (mapStyle != null) {
354
+ inboxUiInboxUiStyleManager.setStyle(mapStyle);
355
+ }
356
+
357
+ Activity currentActivity = getCurrentActivity();
358
+ Intent intent = new Intent(currentActivity, InboxActivity.class);
359
+ if (currentActivity != null) {
360
+ currentActivity.startActivity(intent);
361
+ }else {
362
+ PWLog.error(TAG, "current activity is null");
363
+ }
364
+ }
365
+
366
+ @ReactMethod
367
+ public void messagesWithNoActionPerformedCount(final Callback callback) {
368
+ PushwooshInbox.messagesWithNoActionPerformedCount(new com.pushwoosh.function.Callback<Integer, InboxMessagesException>() {
369
+ @Override
370
+ public void process(@NonNull Result<Integer, InboxMessagesException> result) {
371
+ if (result.isSuccess() && callback != null) {
372
+ callback.invoke(result.getData());
373
+ }
374
+ }
375
+ });
376
+ }
377
+
378
+ @ReactMethod
379
+ public void unreadMessagesCount(final Callback callback) {
380
+ PushwooshInbox.unreadMessagesCount(new com.pushwoosh.function.Callback<Integer, InboxMessagesException>() {
381
+ @Override
382
+ public void process(@NonNull Result<Integer, InboxMessagesException> result) {
383
+ if (result.isSuccess() && callback != null) {
384
+ callback.invoke(result.getData());
385
+ }
386
+ }
387
+ });
388
+ }
389
+
390
+ @ReactMethod
391
+ public void messagesCount(final Callback callback) {
392
+ PushwooshInbox.messagesCount(new com.pushwoosh.function.Callback<Integer, InboxMessagesException>() {
393
+ @Override
394
+ public void process(@NonNull Result<Integer, InboxMessagesException> result) {
395
+ if (result.isSuccess() && callback != null) {
396
+ callback.invoke(result.getData());
397
+ }
398
+ }
399
+ });
400
+ }
401
+
402
+ @ReactMethod
403
+ public void loadMessages(@NonNull final Callback success, @Nullable final Callback error) {
404
+ PushwooshInbox.loadMessages(new com.pushwoosh.function.Callback<Collection<InboxMessage>, InboxMessagesException>() {
405
+ @Override
406
+ public void process(@NonNull Result<Collection<InboxMessage>, InboxMessagesException> result) {
407
+ try {
408
+ if (result.isSuccess() && result.getData() != null) {
409
+ ArrayList<InboxMessage> messagesList = new ArrayList<>(result.getData());
410
+ WritableNativeArray writableArray = new WritableNativeArray();
411
+ for (InboxMessage message : messagesList) {
412
+ writableArray.pushMap(ConversionUtil.inboxMessageToWritableMap(message));
413
+ }
414
+ success.invoke(writableArray);
415
+ } else if (error != null) {
416
+ error.invoke(TAG + "Failed to fetch inbox messages from server");
417
+ }
418
+ } catch (Exception e) {
419
+ if (error != null) {
420
+ error.invoke(e.getLocalizedMessage());
421
+ }
422
+ }
423
+ }
424
+ });
425
+ }
426
+
427
+ @ReactMethod
428
+ public void readMessage(String id) {
429
+ PushwooshInbox.readMessage(id);
430
+ }
431
+
432
+ @ReactMethod
433
+ public void readMessages(ReadableArray codes) {
434
+ PushwooshInbox.readMessages(ConversionUtil.messageCodesArrayToArrayList(codes));
435
+ }
436
+
437
+ @ReactMethod
438
+ public void deleteMessage(String id) {
439
+ PushwooshInbox.deleteMessage(id);
440
+ }
441
+
442
+ @ReactMethod
443
+ public void deleteMessages(ReadableArray codes) {
444
+ PushwooshInbox.deleteMessages(ConversionUtil.messageCodesArrayToArrayList(codes));
445
+ }
446
+
447
+ @ReactMethod
448
+ public void performAction(String id) {
449
+ PushwooshInbox.performAction(id);
450
+ }
451
+
452
+ @ReactMethod
453
+ public void showGDPRConsentUI(){
454
+ GDPRManager.getInstance().showGDPRConsentUI();
455
+ }
456
+
457
+ @ReactMethod
458
+ public void showGDPRDeletionUI(){
459
+ GDPRManager.getInstance().showGDPRDeletionUI();
460
+ }
461
+
462
+ @ReactMethod
463
+ public void isDeviceDataRemoved(final Callback success){
464
+ success.invoke(GDPRManager.getInstance().isDeviceDataRemoved());
465
+ }
466
+
467
+ @ReactMethod
468
+ public void isCommunicationEnabled(final Callback success){
469
+ success.invoke(GDPRManager.getInstance().isCommunicationEnabled());
470
+ }
471
+
472
+ @ReactMethod
473
+ public void isAvailableGDPR(final Callback success){
474
+ success.invoke(GDPRManager.getInstance().isAvailable());
475
+ }
476
+
477
+ @ReactMethod
478
+ public void setCommunicationEnabled(boolean enable, final Callback success, final Callback error) {
479
+ GDPRManager.getInstance().setCommunicationEnabled(enable, new com.pushwoosh.function.Callback<Void, PushwooshException>() {
480
+ @Override
481
+ public void process(Result<Void, PushwooshException> result) {
482
+ if (result.isSuccess()) {
483
+ if (success != null) {
484
+ success.invoke(result.getData());
485
+ }
486
+ } else if (result.getException() != null) {
487
+ if (error != null) {
488
+ error.invoke(result.getException().getLocalizedMessage());
489
+ }
490
+ }
491
+ }
492
+ });
493
+ }
494
+
495
+ @ReactMethod
496
+ public void removeAllDeviceData(final Callback success, final Callback error) {
497
+ GDPRManager.getInstance().removeAllDeviceData(new com.pushwoosh.function.Callback<Void, PushwooshException>() {
498
+ @Override
499
+ public void process(Result<Void, PushwooshException> result) {
500
+ if (result.isSuccess()) {
501
+ if (success != null) {
502
+ success.invoke(result.getData());
503
+ }
504
+ } else if (result.getException() != null) {
505
+ if (error != null) {
506
+ error.invoke(result.getException().getLocalizedMessage());
507
+ }
508
+ }
509
+ }
510
+ });
511
+ }
512
+
513
+ @ReactMethod
514
+ public void setLanguage(String language){
515
+ Pushwoosh.getInstance().setLanguage(language);
516
+ }
517
+
518
+ @ReactMethod
519
+ public void setNotificationIconBackgroundColor(String color) {
520
+ int intColor;
521
+ try {
522
+ intColor = Color.parseColor(color);
523
+ PushwooshNotificationSettings.setNotificationIconBackgroundColor(intColor);
524
+ } catch (IllegalArgumentException e) {
96
525
  PWLog.exception(e);
97
526
  }
98
-
99
- PWLog.debug(TAG, "broadcastPush = " + mBroadcastPush);
100
-
101
- registerPushReceiver();
102
-
103
- reactContext.addLifecycleEventListener(this);
104
- }
105
-
106
- public static void openPush(String pushData) {
107
- PWLog.info(TAG, "Push open: " + pushData);
108
-
109
- try {
110
- synchronized (mStartPushLock) {
111
- mStartPushData = pushData;
112
- if (mPushCallbackRegistered) {
113
- mEventDispatcher.dispatchEvent(PushManager.PUSH_RECEIVE_EVENT, ConversionUtil.toWritableMap(ConversionUtil.stringToMap(pushData)));
114
- }
115
- }
116
- }
117
- catch (Exception e) {
118
- // React Native is highly unstable
119
- PWLog.exception(e);
120
- }
121
- }
122
-
123
- ///
124
- /// Module API
125
- ///
126
-
127
- @Override
128
- public String getName() {
129
- return "Pushwoosh";
130
- }
131
-
132
- @ReactMethod
133
- public void init(ReadableMap config, Callback success, Callback error) {
134
- String appId = config.getString("pw_appid");
135
- String projectId = config.getString("project_number");
136
-
137
- if (appId == null || projectId == null) {
138
- if (error != null) {
139
- error.invoke("Pushwoosh Application id and GCM project number not specified");
140
- }
141
- return;
142
- }
143
-
144
- Context context = getReactApplicationContext();
145
-
146
- context.registerReceiver(mRegistationReceiver, new IntentFilter(context.getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));
147
-
148
- PushManager.initializePushManager(context, appId, projectId);
149
-
150
- mPushManager = PushManager.getInstance(context);
151
-
152
- try {
153
- mPushManager.onStartup(context);
154
- }
155
- catch (Exception e) {
156
- PWLog.exception(e);
157
- if (error != null) {
158
- error.invoke(e.getMessage());
159
- }
160
- return;
161
- }
162
-
163
- if (success != null) {
164
- success.invoke();
165
- }
166
- }
167
-
168
- @ReactMethod
169
- public void register(Callback success, Callback error) {
170
- mEventDispatcher.subscribe(PushManager.REGISTER_EVENT, success);
171
- mEventDispatcher.subscribe(PushManager.REGISTER_ERROR_EVENT, error);
172
- mPushManager.registerForPushNotifications();
173
- }
174
-
175
- @ReactMethod
176
- public void unregister(Callback success, Callback error) {
177
- mEventDispatcher.subscribe(PushManager.UNREGISTER_EVENT, success);
178
- mEventDispatcher.subscribe(PushManager.UNREGISTER_ERROR_EVENT, error);
179
- mPushManager.unregisterForPushNotifications();
180
- }
181
-
182
- @ReactMethod
183
- public void onPushOpen(Callback callback) {
184
- synchronized (mStartPushLock) {
185
- if (!mPushCallbackRegistered && mStartPushData != null) {
186
- callback.invoke(ConversionUtil.toWritableMap(ConversionUtil.stringToMap(mStartPushData)));
187
- mPushCallbackRegistered = true;
188
- return;
189
- }
190
-
191
- mPushCallbackRegistered = true;
192
- mEventDispatcher.subscribe(PushManager.PUSH_RECEIVE_EVENT, callback);
193
- }
194
- }
195
-
196
- @ReactMethod
197
- public void setTags(ReadableMap tags, final Callback success, final Callback error) {
198
- mPushManager.sendTags(getReactApplicationContext(), ConversionUtil.toMap(tags), new SendPushTagsCallBack() {
199
- @Override
200
- public void taskStarted() {
201
-
202
- }
203
-
204
- @Override
205
- public void onSentTagsSuccess(Map<String, String> result) {
206
- if (success != null) {
207
- success.invoke();
208
- }
209
- }
210
-
211
- @Override
212
- public void onSentTagsError(Exception e) {
213
- if (error != null) {
214
- error.invoke(e.getMessage());
215
- }
216
- }
217
- });
218
- }
219
-
220
- @ReactMethod
221
- public void getTags(final Callback success, final Callback error) {
222
- mPushManager.getTagsAsync(getReactApplicationContext(), new PushManager.GetTagsListener() {
223
- @Override
224
- public void onTagsReceived(Map<String, Object> tags) {
225
- if (success != null) {
226
- success.invoke(ConversionUtil.toWritableMap(tags));
227
- }
228
- }
229
-
230
- @Override
231
- public void onError(Exception e) {
232
- if (error != null) {
233
- error.invoke(e.getMessage());
234
- }
235
- }
236
- });
237
- }
238
-
239
- @ReactMethod
240
- public void getPushToken(Callback callback) {
241
- callback.invoke(mPushManager.getPushToken(getReactApplicationContext()));
242
- }
243
-
244
- @ReactMethod
245
- public void getHwid(Callback callback) {
246
- callback.invoke(mPushManager.getPushwooshHWID(getReactApplicationContext()));
247
- }
248
-
249
- @ReactMethod
250
- public void setUserId(String userId) {
251
- mPushManager.setUserId(getReactApplicationContext(), userId);
252
- }
253
-
254
- @ReactMethod
255
- public void postEvent(String event, ReadableMap attributes) {
256
- Intent intent = PostEventActivity.createIntent(getReactApplicationContext(), event, ConversionUtil.toMap(attributes));
257
- getReactApplicationContext().startActivity(intent);
258
- }
259
-
260
- ///
261
- /// LifecycleEventListener callbacks
262
- ///
263
-
264
- @Override
265
- public void onHostResume() {
266
- PWLog.noise(TAG, "Host resumed");
267
-
268
- registerPushReceiver();
269
- }
270
-
271
- @Override
272
- public void onHostPause() {
273
- PWLog.noise(TAG, "Host paused");
274
-
275
- unregisterPushReceiver();
276
- }
277
-
278
- @Override
279
- public void onHostDestroy() {
280
- PWLog.noise(TAG, "Host destroyed");
281
-
282
- mPushCallbackRegistered = false;
283
- mStartPushData = null;
284
- }
285
-
286
- ///
287
- /// Private methods
288
- ///
289
-
290
- private void registerPushReceiver() {
291
- if (!mBroadcastPush) {
292
- return;
293
- }
294
-
295
- try {
296
- Context context = getReactApplicationContext();
297
- IntentFilter intentFilter = new IntentFilter(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
298
- context.registerReceiver(mPushMessageReceiver, intentFilter);
299
- }
300
- catch (Exception e) {
301
-
302
- }
303
- }
304
-
305
- private void unregisterPushReceiver() {
306
- if (!mBroadcastPush) {
307
- return;
308
- }
309
-
310
- try {
311
- Context context = getReactApplicationContext();
312
- context.unregisterReceiver(mPushMessageReceiver);
313
- }
314
- catch (Exception e) {
315
-
316
- }
317
- }
527
+ }
528
+
529
+ @ReactMethod
530
+ public void enableHuaweiPushNotifications() {
531
+ Pushwoosh.getInstance().enableHuaweiPushNotifications();
532
+ }
533
+
534
+ ///
535
+ /// LifecycleEventListener callbacks
536
+ ///
537
+
538
+ @Override
539
+ public void onHostResume() {
540
+ PWLog.noise(TAG, "Host resumed");
541
+ }
542
+
543
+ @Override
544
+ public void onHostPause() {
545
+ PWLog.noise(TAG, "Host paused");
546
+ }
547
+
548
+ @Override
549
+ public void onHostDestroy() {
550
+ PWLog.noise(TAG, "Host destroyed");
551
+
552
+ sPushCallbackRegistered = false;
553
+ sStartPushData = null;
554
+
555
+ sReceivedPushCallbackRegistered = false;
556
+ sReceivedPushData = null;
557
+ }
558
+
559
+ ///
560
+ /// Private methods
561
+ ///
562
+
563
+ static void openPush(String pushData) {
564
+ PWLog.info(TAG, "Push open: " + pushData);
565
+
566
+ try {
567
+ synchronized (sStartPushLock) {
568
+ sStartPushData = pushData;
569
+ if (sPushCallbackRegistered) {
570
+ mEventDispatcher.dispatchEvent(PUSH_OPEN_EVENT, ConversionUtil.toWritableMap(ConversionUtil.stringToJSONObject(pushData)));
571
+ }
572
+ if (sInitialized && INSTANCE != null) {
573
+ INSTANCE.sendEvent(PUSH_OPEN_JS_EVENT, ConversionUtil.stringToJSONObject(pushData));
574
+ }
575
+ }
576
+ } catch (Exception e) {
577
+ // React Native is highly unstable
578
+ PWLog.exception(e);
579
+ }
580
+ }
581
+
582
+ private void sendEvent(String event, JSONObject params) {
583
+ mEventDispatcher.sendJSEvent(getReactApplicationContext(), event, ConversionUtil.toWritableMap(params));
584
+ }
585
+
586
+ static void messageReceived(String pushData) {
587
+ PWLog.info(TAG, "Push received: " + pushData);
588
+
589
+ try {
590
+ synchronized (sStartPushLock) {
591
+ sReceivedPushData = pushData;
592
+ if (sReceivedPushCallbackRegistered) {
593
+ mEventDispatcher.dispatchEvent(PUSH_RECEIVED_EVENT, ConversionUtil.toWritableMap(ConversionUtil.stringToJSONObject(pushData)));
594
+ }
595
+ if (sInitialized && INSTANCE != null) {
596
+ INSTANCE.sendEvent(PUSH_RECEIVED_JS_EVENT, ConversionUtil.stringToJSONObject(pushData));
597
+ }
598
+ }
599
+ } catch (Exception e) {
600
+ // React Native is highly unstable
601
+ PWLog.exception(e);
602
+ }
603
+ }
604
+
605
+ private class RegisterForPushNotificationCallback implements com.pushwoosh.function.Callback<RegisterForPushNotificationsResultData, RegisterForPushNotificationsException> {
606
+ private Callback success;
607
+ private Callback error;
608
+
609
+ public RegisterForPushNotificationCallback(Callback success, Callback error) {
610
+ this.success = success;
611
+ this.error = error;
612
+ }
613
+
614
+ @Override
615
+ public void process(Result<RegisterForPushNotificationsResultData, RegisterForPushNotificationsException> result) {
616
+ if (result.isSuccess()) {
617
+ if (success != null && result.getData() != null) {
618
+ success.invoke(result.getData().getToken());
619
+ success = null;
620
+ }
621
+ } else if (result.getException() != null) {
622
+ if (error != null) {
623
+ error.invoke(result.getException().getLocalizedMessage());
624
+ error = null;
625
+ }
626
+ }
627
+ }
628
+ }
318
629
  }