pushwoosh-react-native-plugin 2.0.0 → 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 +265 -24
  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 +7 -6
  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 +606 -393
  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 +18 -3
  56. package/src/ios/PushwooshPlugin/Pushwoosh.m +532 -98
  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 -150
  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,416 +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;
26
40
  import com.pushwoosh.notification.SoundType;
27
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;
28
47
 
29
48
  import java.util.ArrayList;
30
- import java.util.List;
31
- import java.util.Map;
32
- import java.util.Objects;
49
+ import java.util.Collection;
33
50
 
34
51
  public class PushwooshPlugin extends ReactContextBaseJavaModule implements LifecycleEventListener {
35
52
 
36
- static final String TAG = "ReactNativePlugin";
37
-
38
- static final String PUSH_OPEN_JS_EVENT = "pushOpened";
39
-
40
- private PushManager mPushManager;
41
-
42
- private static EventDispatcher mEventDispatcher = new EventDispatcher();
43
-
44
- private boolean mBroadcastPush = true;
45
-
46
- private static String mStartPushData;
47
- private static Object mStartPushLock = new Object();
48
- private static boolean mPushCallbackRegistered = false;
49
- private static boolean mInitialized = false;
50
-
51
- private static PushwooshPlugin INSTANCE = null;
52
-
53
- BroadcastReceiver mRegistationReceiver = new BaseRegistrationReceiver() {
54
- @Override
55
- protected void onRegisterActionReceive(Context context, Intent intent) {
56
- if (intent == null) {
57
- return;
58
- }
59
-
60
- else if (intent.hasExtra(PushManager.REGISTER_EVENT)) {
61
- String pushToken = intent.getExtras().getString(PushManager.REGISTER_EVENT);
62
- mEventDispatcher.dispatchEvent(PushManager.REGISTER_EVENT, pushToken);
63
- }
64
- else if (intent.hasExtra(PushManager.UNREGISTER_EVENT)) {
65
- String pushToken = intent.getExtras().getString(PushManager.UNREGISTER_EVENT);
66
- mEventDispatcher.dispatchEvent(PushManager.UNREGISTER_EVENT, pushToken);
67
- }
68
- else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT)) {
69
- String errorMessage = intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT);
70
- mEventDispatcher.dispatchEvent(PushManager.REGISTER_ERROR_EVENT, errorMessage);
71
- }
72
- else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT)) {
73
- String errorMessage = intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT);
74
- mEventDispatcher.dispatchEvent(PushManager.UNREGISTER_ERROR_EVENT, errorMessage);
75
- }
76
- }
77
- };
78
-
79
- BroadcastReceiver mPushMessageReceiver = new BasePushMessageReceiver() {
80
- @Override
81
- protected void onMessageReceive(Intent intent) {
82
- if (intent == null) {
83
- return;
84
- }
85
-
86
- String pushData = intent.getStringExtra(JSON_DATA_KEY);
87
- openPush(pushData);
88
- }
89
- };
90
-
91
- public PushwooshPlugin(ReactApplicationContext reactContext) {
92
- super(reactContext);
93
-
94
- INSTANCE = this;
95
-
96
- try {
97
- String packageName = reactContext.getPackageName();
98
- ApplicationInfo ai = reactContext.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
99
-
100
- if (ai.metaData != null) {
101
- mBroadcastPush = ai.metaData.getBoolean("PW_BROADCAST_PUSH", true);
102
- }
103
- }
104
- catch (Exception e) {
105
- PWLog.exception(e);
106
- }
107
-
108
- PWLog.debug(TAG, "broadcastPush = " + mBroadcastPush);
109
-
110
- registerPushReceiver();
111
-
112
- reactContext.addLifecycleEventListener(this);
113
- }
114
-
115
- public static void openPush(String pushData) {
116
- PWLog.info(TAG, "Push open: " + pushData);
117
-
118
- try {
119
- synchronized (mStartPushLock) {
120
- mStartPushData = pushData;
121
- if (mPushCallbackRegistered) {
122
- mEventDispatcher.dispatchEvent(PushManager.PUSH_RECEIVE_EVENT, ConversionUtil.toWritableMap(ConversionUtil.stringToMap(pushData)));
123
- }
124
- if (mInitialized && INSTANCE != null) {
125
- INSTANCE.sendEvent(PUSH_OPEN_JS_EVENT, ConversionUtil.stringToMap(pushData));
126
- }
127
- }
128
- }
129
- catch (Exception e) {
130
- // React Native is highly unstable
131
- PWLog.exception(e);
132
- }
133
- }
134
-
135
- ///
136
- /// Module API
137
- ///
138
-
139
- @Override
140
- public String getName() {
141
- return "Pushwoosh";
142
- }
143
-
144
- @ReactMethod
145
- public void init(ReadableMap config, Callback success, Callback error) {
146
- String appId = config.getString("pw_appid");
147
- String projectId = config.getString("project_number");
148
-
149
- if (appId == null || projectId == null) {
150
- if (error != null) {
151
- error.invoke("Pushwoosh Application id and GCM project number not specified");
152
- }
153
- return;
154
- }
155
-
156
- Context context = getReactApplicationContext();
157
-
158
- context.registerReceiver(mRegistationReceiver, new IntentFilter(context.getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));
159
-
160
- PushManager.initializePushManager(context, appId, projectId);
161
-
162
- mPushManager = PushManager.getInstance(context);
163
-
164
- try {
165
- mPushManager.onStartup(context);
166
- }
167
- 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) {
168
525
  PWLog.exception(e);
169
- if (error != null) {
170
- error.invoke(e.getMessage());
171
- }
172
- return;
173
- }
174
-
175
- synchronized (mStartPushLock) {
176
- if (mStartPushData != null) {
177
- sendEvent(PUSH_OPEN_JS_EVENT, ConversionUtil.stringToMap(mStartPushData));
178
- }
179
- }
180
-
181
- mInitialized = true;
182
-
183
- if (success != null) {
184
- success.invoke();
185
- }
186
- }
187
-
188
- @ReactMethod
189
- public void register(Callback success, Callback error) {
190
- mEventDispatcher.subscribe(PushManager.REGISTER_EVENT, success);
191
- mEventDispatcher.subscribe(PushManager.REGISTER_ERROR_EVENT, error);
192
- mPushManager.registerForPushNotifications();
193
- }
194
-
195
- @ReactMethod
196
- public void unregister(Callback success, Callback error) {
197
- mEventDispatcher.subscribe(PushManager.UNREGISTER_EVENT, success);
198
- mEventDispatcher.subscribe(PushManager.UNREGISTER_ERROR_EVENT, error);
199
- mPushManager.unregisterForPushNotifications();
200
- }
201
-
202
- @ReactMethod
203
- public void onPushOpen(Callback callback) {
204
- synchronized (mStartPushLock) {
205
- if (!mPushCallbackRegistered && mStartPushData != null) {
206
- callback.invoke(ConversionUtil.toWritableMap(ConversionUtil.stringToMap(mStartPushData)));
207
- mPushCallbackRegistered = true;
208
- return;
209
- }
210
-
211
- mPushCallbackRegistered = true;
212
- mEventDispatcher.subscribe(PushManager.PUSH_RECEIVE_EVENT, callback);
213
526
  }
214
- }
215
-
216
- @ReactMethod
217
- public void setTags(ReadableMap tags, final Callback success, final Callback error) {
218
- mPushManager.sendTags(getReactApplicationContext(), ConversionUtil.toMap(tags), new SendPushTagsCallBack() {
219
- @Override
220
- public void taskStarted() {
221
-
222
- }
223
-
224
- @Override
225
- public void onSentTagsSuccess(Map<String, String> result) {
226
- if (success != null) {
227
- success.invoke();
228
- }
229
- }
230
-
231
- @Override
232
- public void onSentTagsError(Exception e) {
233
- if (error != null) {
234
- error.invoke(e.getMessage());
235
- }
236
- }
237
- });
238
- }
239
-
240
- @ReactMethod
241
- public void getTags(final Callback success, final Callback error) {
242
- mPushManager.getTagsAsync(getReactApplicationContext(), new PushManager.GetTagsListener() {
243
- @Override
244
- public void onTagsReceived(Map<String, Object> tags) {
245
- if (success != null) {
246
- success.invoke(ConversionUtil.toWritableMap(tags));
247
- }
248
- }
249
-
250
- @Override
251
- public void onError(Exception e) {
252
- if (error != null) {
253
- error.invoke(e.getMessage());
254
- }
255
- }
256
- });
257
- }
258
-
259
- @ReactMethod
260
- public void getPushToken(Callback callback) {
261
- callback.invoke(mPushManager.getPushToken(getReactApplicationContext()));
262
- }
263
-
264
- @ReactMethod
265
- public void getHwid(Callback callback) {
266
- callback.invoke(mPushManager.getPushwooshHWID(getReactApplicationContext()));
267
- }
268
-
269
- @ReactMethod
270
- public void setUserId(String userId) {
271
- mPushManager.setUserId(getReactApplicationContext(), userId);
272
- }
273
-
274
- @ReactMethod
275
- public void postEvent(String event, ReadableMap attributes) {
276
- Intent intent = PostEventActivity.createIntent(getReactApplicationContext(), event, ConversionUtil.toMap(attributes));
277
- getReactApplicationContext().startActivity(intent);
278
- }
279
-
280
- @ReactMethod
281
- public void startLocationTracking() {
282
- mPushManager.startTrackingGeoPushes();
283
- }
284
-
285
- @ReactMethod
286
- public void stopLocationTracking() {
287
- mPushManager.stopTrackingGeoPushes();
288
- }
289
-
290
- @ReactMethod
291
- public void setApplicationIconBadgeNumber(int badgeNumber) {
292
- mPushManager.setBadgeNumber(badgeNumber);
293
- }
294
-
295
- @ReactMethod
296
- public void getApplicationIconBadgeNumber(Callback callback) {
297
- callback.invoke(mPushManager.getBadgeNumber());
298
- }
299
-
300
- @ReactMethod
301
- public void addToApplicationIconBadgeNumber(int badgeNumber) {
302
- mPushManager.addBadgeNumber(badgeNumber);
303
- }
304
-
305
- @ReactMethod
306
- public void setMultiNotificationMode(boolean on) {
307
- Context context = getReactApplicationContext();
308
- if (on) {
309
- PushManager.setMultiNotificationMode(context);
310
- }
311
- else {
312
- PushManager.setSimpleNotificationMode(context);
313
- }
314
- }
315
-
316
- @ReactMethod
317
- public void setLightScreenOnNotification(boolean on) {
318
- Context context = getReactApplicationContext();
319
- PushManager.setLightScreenOnNotification(context, on);
320
- }
321
-
322
- @ReactMethod
323
- public void setEnableLED(boolean on) {
324
- Context context = getReactApplicationContext();
325
- PushManager.setEnableLED(context, on);
326
- }
327
-
328
- @ReactMethod
329
- public void setColorLED(int color) {
330
- Context context = getReactApplicationContext();
331
- PushManager.setColorLED(context, color);
332
- }
333
-
334
- @ReactMethod
335
- public void setSoundType(int type) {
336
- Context context = getReactApplicationContext();
337
- PushManager.setSoundNotificationType(context, SoundType.fromInt(type));
338
- }
339
-
340
- @ReactMethod
341
- public void setVibrateType(int type) {
342
- Context context = getReactApplicationContext();
343
- PushManager.setVibrateNotificationType(context, VibrateType.fromInt(type));
344
- }
345
-
346
- ///
347
- /// LifecycleEventListener callbacks
348
- ///
349
-
350
- @Override
351
- public void onHostResume() {
352
- PWLog.noise(TAG, "Host resumed");
353
-
354
- registerPushReceiver();
355
- }
356
-
357
- @Override
358
- public void onHostPause() {
359
- PWLog.noise(TAG, "Host paused");
360
-
361
- unregisterPushReceiver();
362
- }
363
-
364
- @Override
365
- public void onHostDestroy() {
366
- PWLog.noise(TAG, "Host destroyed");
367
-
368
- try {
369
- Context context = getReactApplicationContext();
370
- context.unregisterReceiver(mRegistationReceiver);
371
- }
372
- catch (Exception e) {
373
-
374
- }
375
-
376
- mPushCallbackRegistered = false;
377
- mStartPushData = null;
378
- }
379
-
380
- ///
381
- /// Private methods
382
- ///
383
-
384
- private void registerPushReceiver() {
385
- if (!mBroadcastPush) {
386
- return;
387
- }
388
-
389
- try {
390
- Context context = getReactApplicationContext();
391
- IntentFilter intentFilter = new IntentFilter(context.getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
392
- context.registerReceiver(mPushMessageReceiver, intentFilter);
393
- }
394
- catch (Exception e) {
395
-
396
- }
397
- }
398
-
399
- private void unregisterPushReceiver() {
400
- if (!mBroadcastPush) {
401
- return;
402
- }
403
-
404
- try {
405
- Context context = getReactApplicationContext();
406
- context.unregisterReceiver(mPushMessageReceiver);
407
- }
408
- catch (Exception e) {
409
-
410
- }
411
- }
412
-
413
- private void sendEvent(String event, Map<String, Object> params) {
414
- mEventDispatcher.sendJSEvent(getReactApplicationContext(), event, params);
415
- }
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
+ }
416
629
  }