pushwoosh-cordova-plugin 6.1.0 → 6.1.1

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 (79) hide show
  1. package/{MIT-LICENSE.txt → LICENSE.md} +0 -0
  2. package/README.md +20 -32
  3. package/README_PGB.md +32 -0
  4. package/package.json +1 -1
  5. package/package_pgb.json +29 -0
  6. package/plugin.xml +71 -85
  7. package/src/android/src/com/pushwoosh/plugin/internal/PhonegapPluginProvider.java +22 -0
  8. package/src/android/src/com/pushwoosh/plugin/pushnotifications/CustomFirebaseMessagingService.java +29 -0
  9. package/src/android/src/com/pushwoosh/plugin/pushnotifications/InboxUiStyleManager.java +136 -0
  10. package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java +339 -388
  11. package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushwooshNotificationServiceExtension.java +38 -0
  12. package/src/ios/PWBackward.h +25 -0
  13. package/src/ios/PWBackward.m +53 -0
  14. package/src/ios/PushNotification.m +409 -158
  15. package/src/ios/Pushwoosh.framework/Modules/module.modulemap +6 -0
  16. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWAppDelegate.h +20 -0
  17. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWGDPRManager.h +46 -0
  18. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInAppManager.h +174 -0
  19. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInbox.h +147 -0
  20. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInlineInAppView.h +26 -0
  21. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWLog.h +23 -0
  22. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWMessaging.h +20 -0
  23. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWNotificationExtensionManager.h +33 -0
  24. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaManager.h +118 -0
  25. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaStyle.h +122 -0
  26. package/src/ios/Pushwoosh.framework/Versions/A/Headers/PushNotificationManager.h +263 -151
  27. package/src/ios/Pushwoosh.framework/Versions/A/Headers/Pushwoosh.h +525 -0
  28. package/src/ios/Pushwoosh.framework/Versions/A/libPushwoosh.a +0 -0
  29. package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
  30. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
  31. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
  32. package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
  33. package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
  34. package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
  35. package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
  36. package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
  37. package/src/ios/PushwooshInboxUI.framework/Modules/module.modulemap +6 -0
  38. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxStyle.h +122 -0
  39. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxUI.h +39 -0
  40. package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PushwooshInboxUI.h +19 -0
  41. package/src/ios/PushwooshInboxUI.framework/Versions/A/libPushwooshInboxUI.a +0 -0
  42. package/src/windows/PushSDK/Newtonsoft.Json.dll +0 -0
  43. package/src/windows/PushSDK/PushSDK.winmd +0 -0
  44. package/src/windows/PushwooshPluginProxy.js +88 -74
  45. package/src/wp8/PushNotification.cs +14 -0
  46. package/src/wp8/PushSDK/PushSDK.dll +0 -0
  47. package/www/PushNotification.js +171 -45
  48. package/Documentation/files/PushNotification-js.html +0 -157
  49. package/Documentation/index/Classes.html +0 -33
  50. package/Documentation/index/Functions.html +0 -61
  51. package/Documentation/index/General.html +0 -65
  52. package/Documentation/index.html +0 -1
  53. package/Documentation/javascript/main.js +0 -841
  54. package/Documentation/javascript/prettify.js +0 -1526
  55. package/Documentation/javascript/searchdata.js +0 -92
  56. package/Documentation/search/ClassesP.html +0 -20
  57. package/Documentation/search/FunctionsA.html +0 -20
  58. package/Documentation/search/FunctionsC.html +0 -20
  59. package/Documentation/search/FunctionsG.html +0 -20
  60. package/Documentation/search/FunctionsO.html +0 -20
  61. package/Documentation/search/FunctionsP.html +0 -20
  62. package/Documentation/search/FunctionsR.html +0 -20
  63. package/Documentation/search/FunctionsS.html +0 -20
  64. package/Documentation/search/FunctionsU.html +0 -20
  65. package/Documentation/search/GeneralA.html +0 -20
  66. package/Documentation/search/GeneralC.html +0 -20
  67. package/Documentation/search/GeneralF.html +0 -20
  68. package/Documentation/search/GeneralG.html +0 -20
  69. package/Documentation/search/GeneralO.html +0 -20
  70. package/Documentation/search/GeneralP.html +0 -20
  71. package/Documentation/search/GeneralR.html +0 -20
  72. package/Documentation/search/GeneralS.html +0 -20
  73. package/Documentation/search/GeneralU.html +0 -20
  74. package/Documentation/search/NoResults.html +0 -15
  75. package/Documentation/styles/main.css +0 -828
  76. package/VERSION.md +0 -138
  77. package/push.gradle +0 -21
  78. package/src/android/src/com/pushwoosh/plugin/pushnotifications/NotificationFactory.java +0 -29
  79. package/src/ios/Pushwoosh.framework/Versions/A/Pushwoosh +0 -0
@@ -10,53 +10,65 @@
10
10
 
11
11
  package com.pushwoosh.plugin.pushnotifications;
12
12
 
13
- import java.lang.annotation.Retention;
14
- import java.lang.reflect.Method;
15
- import java.util.ArrayList;
16
- import java.util.Arrays;
17
- import java.util.HashMap;
18
- import java.util.Iterator;
19
- import java.util.List;
20
- import java.util.Map;
21
-
22
- import android.content.BroadcastReceiver;
23
- import android.content.Context;
24
13
  import android.content.Intent;
25
- import android.content.IntentFilter;
26
14
  import android.os.Bundle;
27
- import android.content.pm.ApplicationInfo;
28
- import android.content.pm.PackageManager;
29
-
30
- import com.pushwoosh.PushManager;
15
+ import android.os.Handler;
16
+ import android.os.Looper;
17
+ import androidx.annotation.NonNull;
18
+ import androidx.core.app.NotificationManagerCompat;
19
+ import android.webkit.JavascriptInterface;
20
+
21
+ import com.pushwoosh.GDPRManager;
22
+ import com.pushwoosh.Pushwoosh;
23
+ import com.pushwoosh.badge.PushwooshBadge;
24
+ import com.pushwoosh.exception.GetTagsException;
25
+ import com.pushwoosh.exception.PushwooshException;
26
+ import com.pushwoosh.exception.RegisterForPushNotificationsException;
27
+ import com.pushwoosh.exception.UnregisterForPushNotificationException;
28
+ import com.pushwoosh.function.Callback;
29
+ import com.pushwoosh.function.Result;
30
+ import com.pushwoosh.inapp.PushwooshInApp;
31
+ import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
32
+ import com.pushwoosh.internal.platform.utils.GeneralUtils;
31
33
  import com.pushwoosh.internal.utils.PWLog;
34
+ import com.pushwoosh.notification.LocalNotification;
35
+ import com.pushwoosh.notification.LocalNotificationReceiver;
36
+ import com.pushwoosh.notification.PushMessage;
37
+ import com.pushwoosh.notification.PushwooshNotificationSettings;
32
38
  import com.pushwoosh.notification.SoundType;
33
39
  import com.pushwoosh.notification.VibrateType;
34
- import com.pushwoosh.PushManager.GetTagsListener;
35
- import com.pushwoosh.BasePushMessageReceiver;
36
- import com.pushwoosh.BaseRegistrationReceiver;
37
- import com.pushwoosh.SendPushTagsCallBack;
38
- import com.pushwoosh.internal.utils.GeneralUtils;
39
- import com.pushwoosh.internal.utils.JsonUtils;
40
- import com.pushwoosh.inapp.InAppFacade;
40
+ import com.pushwoosh.tags.Tags;
41
+ import com.pushwoosh.tags.TagsBundle;
41
42
 
42
43
  import org.apache.cordova.CallbackContext;
43
44
  import org.apache.cordova.CordovaPlugin;
45
+ import org.apache.cordova.CordovaWebView;
44
46
  import org.json.JSONArray;
45
47
  import org.json.JSONException;
46
48
  import org.json.JSONObject;
47
49
 
50
+ import java.lang.annotation.Retention;
51
+ import java.lang.reflect.Method;
52
+ import java.util.ArrayList;
53
+ import java.util.Arrays;
54
+ import java.util.HashMap;
55
+ import java.util.List;
56
+ import java.util.Map;
57
+ import java.util.concurrent.atomic.AtomicBoolean;
58
+
48
59
  import static java.lang.annotation.RetentionPolicy.RUNTIME;
49
60
 
50
- public class PushNotifications extends CordovaPlugin
51
- {
52
- private static final String TAG = "CordovaPlugin";
61
+ public class PushNotifications extends CordovaPlugin {
62
+ public static final String TAG = "CordovaPlugin";
63
+ private static final Object sStartPushLock = new Object();
53
64
 
54
- boolean receiversRegistered = false;
55
- boolean broadcastPush = true;
56
- JSONObject startPushData = null;
65
+ private static String sStartPushData;
66
+ private static String sReceivedPushData;
57
67
 
58
- HashMap<String, CallbackContext> callbackIds = new HashMap<String, CallbackContext>();
59
- PushManager mPushManager = null;
68
+ private static AtomicBoolean sAppReady = new AtomicBoolean();
69
+ private static PushNotifications sInstance;
70
+
71
+ private final HashMap<String, CallbackContext> callbackIds = new HashMap<String, CallbackContext>();
60
72
 
61
73
  private static final Map<String, Method> exportedMethods;
62
74
 
@@ -65,8 +77,8 @@ public class PushNotifications extends CordovaPlugin
65
77
 
66
78
  }
67
79
 
68
- static
69
- {
80
+
81
+ static {
70
82
  HashMap<String, Method> methods = new HashMap<String, Method>();
71
83
 
72
84
  final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(PushNotifications.class.getDeclaredMethods()));
@@ -79,116 +91,30 @@ public class PushNotifications extends CordovaPlugin
79
91
  exportedMethods = methods;
80
92
  }
81
93
 
82
- /**
83
- * Called when the activity receives a new intent.
84
- */
85
- public void onNewIntent(Intent intent)
86
- {
87
- super.onNewIntent(intent);
88
-
89
- startPushData = getPushFromIntent(intent);
90
- checkMessage(intent);
91
- }
92
-
93
- private BroadcastReceiver mRegistrationReceiver = new BaseRegistrationReceiver()
94
- {
95
- @Override
96
- public void onRegisterActionReceive(Context context, Intent intent)
97
- {
98
- checkMessage(intent);
99
- }
100
- };
101
-
102
- private BroadcastReceiver mPushReceiver = new BasePushMessageReceiver()
103
- {
104
- @Override
105
- protected void onMessageReceive(Intent intent)
106
- {
107
- doOnPushOpened(intent.getStringExtra(JSON_DATA_KEY));
108
- }
109
- };
110
-
111
- //Registration of the receivers
112
- public void registerReceivers()
113
- {
114
- if (receiversRegistered)
115
- return;
116
-
117
- IntentFilter intentFilter = new IntentFilter(cordova.getActivity().getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
118
-
119
- //comment this code out if you would like to receive the notifications in the notifications center when the app is in foreground
120
- if (broadcastPush)
121
- cordova.getActivity().registerReceiver(mPushReceiver, intentFilter);
122
-
123
- //registration receiver
124
- cordova.getActivity().registerReceiver(mRegistrationReceiver, new IntentFilter(cordova.getActivity().getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));
94
+ private final Handler handler = new Handler(Looper.getMainLooper());
125
95
 
126
- receiversRegistered = true;
127
- }
128
-
129
- public void unregisterReceivers()
130
- {
131
- if (!receiversRegistered)
132
- return;
133
-
134
- try
135
- {
136
- cordova.getActivity().unregisterReceiver(mPushReceiver);
137
- }
138
- catch (Exception e)
139
- {
140
- // pass. for some reason Phonegap call this method before onResume. Not Android lifecycle style...
141
- }
142
-
143
- try
144
- {
145
- cordova.getActivity().unregisterReceiver(mRegistrationReceiver);
146
- }
147
- catch (Exception e)
148
- {
149
- //pass through
150
- }
151
-
152
- receiversRegistered = false;
153
- }
154
-
155
- @Override
156
- public void onResume(boolean multitasking)
157
- {
158
- super.onResume(multitasking);
159
- registerReceivers();
96
+ public PushNotifications () {
97
+ sInstance = this;
98
+ sAppReady.set(false);
160
99
  }
161
100
 
162
101
  @Override
163
- public void onPause(boolean multitasking)
164
- {
165
- super.onPause(multitasking);
166
- unregisterReceivers();
167
- }
168
-
169
- /**
170
- * The final call you receive before your activity is destroyed.
171
- */
172
- public void onDestroy()
173
- {
102
+ public void onDestroy() {
174
103
  super.onDestroy();
104
+ PWLog.noise("OnDestroy");
105
+ sAppReady.set(false);
175
106
  }
176
107
 
177
- private JSONObject getPushFromIntent(Intent intent)
178
- {
108
+ private JSONObject getPushFromIntent(Intent intent) {
179
109
  if (null == intent)
180
110
  return null;
181
111
 
182
- if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
183
- {
184
- String pushString = intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT);
112
+ if (intent.hasExtra(Pushwoosh.PUSH_RECEIVE_EVENT)) {
113
+ String pushString = intent.getExtras().getString(Pushwoosh.PUSH_RECEIVE_EVENT);
185
114
  JSONObject pushObject = null;
186
- try
187
- {
115
+ try {
188
116
  pushObject = new JSONObject(pushString);
189
- }
190
- catch (JSONException e)
191
- {
117
+ } catch (JSONException e) {
192
118
  PWLog.error(TAG, "Failed to parse push notification", e);
193
119
  }
194
120
 
@@ -198,132 +124,92 @@ public class PushNotifications extends CordovaPlugin
198
124
  return null;
199
125
  }
200
126
 
201
- private void checkMessage(Intent intent)
202
- {
203
- if (null != intent)
204
- {
205
- if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
206
- {
207
- doOnPushOpened(intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT));
208
- }
209
- else if (intent.hasExtra(PushManager.REGISTER_EVENT))
210
- {
211
- doOnRegistered(intent.getExtras().getString(PushManager.REGISTER_EVENT));
212
- }
213
- else if (intent.hasExtra(PushManager.UNREGISTER_EVENT))
214
- {
215
- doOnUnregistered(intent.getExtras().getString(PushManager.UNREGISTER_EVENT));
216
- }
217
- else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
218
- {
219
- doOnRegisteredError(intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT));
220
- }
221
- else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
222
- {
223
- doOnUnregisteredError(intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT));
224
- }
225
-
226
- intent.removeExtra(PushManager.PUSH_RECEIVE_EVENT);
227
- intent.removeExtra(PushManager.REGISTER_EVENT);
228
- intent.removeExtra(PushManager.UNREGISTER_EVENT);
229
- intent.removeExtra(PushManager.REGISTER_ERROR_EVENT);
230
- intent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT);
231
-
232
- cordova.getActivity().setIntent(intent);
233
- }
234
- }
235
-
236
127
  @CordovaMethod
237
- private boolean onDeviceReady(JSONArray data, CallbackContext callbackContext)
238
- {
128
+ private boolean onDeviceReady(JSONArray data, CallbackContext callbackContext) {
239
129
  JSONObject params = null;
240
- try
241
- {
130
+ try {
242
131
  params = data.getJSONObject(0);
243
- }
244
- catch (JSONException e)
245
- {
132
+ } catch (JSONException e) {
246
133
  PWLog.error(TAG, "No parameters has been passed to onDeviceReady function. Did you follow the guide correctly?", e);
247
134
  return false;
248
135
  }
249
136
 
250
- try
251
- {
252
- String packageName = cordova.getActivity().getApplicationContext().getPackageName();
253
- ApplicationInfo ai = cordova.getActivity().getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
254
-
255
- if (ai.metaData != null && ai.metaData.containsKey("PW_NO_BROADCAST_PUSH"))
256
- broadcastPush = !(ai.metaData.getBoolean("PW_NO_BROADCAST_PUSH"));
257
-
258
- PWLog.debug(TAG, "broadcastPush = " + broadcastPush);
259
- }
260
- catch (Exception e)
261
- {
262
- PWLog.error(TAG, "Failed to read AndroidManifest");
263
- }
264
-
265
- try
266
- {
267
- //make sure the receivers are on
268
- registerReceivers();
269
-
270
- startPushData = getPushFromIntent(cordova.getActivity().getIntent());
137
+ try {
271
138
 
272
139
  String appid = null;
273
- if (params.has("appid"))
140
+ if (params.has("appid")) {
274
141
  appid = params.getString("appid");
275
- else
142
+ } else {
276
143
  appid = params.getString("pw_appid");
144
+ }
277
145
 
278
- PushManager.initializePushManager(cordova.getActivity(), appid, params.getString("projectid"));
279
- mPushManager = PushManager.getInstance(cordova.getActivity());
280
- mPushManager.onStartup(cordova.getActivity());
146
+ Pushwoosh.getInstance().setAppId(appid);
147
+ Pushwoosh.getInstance().setSenderId(params.getString("projectid"));
281
148
 
282
- NotificationFactory factory = new NotificationFactory();
283
- factory.setPlugin(this);
284
- mPushManager.setNotificationFactory(factory);
285
- }
286
- catch (Exception e)
287
- {
149
+
150
+ synchronized (sStartPushLock) {
151
+ if (sReceivedPushData != null) {
152
+ doOnPushReceived(sReceivedPushData);
153
+ }
154
+
155
+ if (sStartPushData != null) {
156
+ doOnPushOpened(sStartPushData);
157
+ }
158
+ }
159
+
160
+ sAppReady.set(true);
161
+ } catch (Exception e) {
288
162
  PWLog.error(TAG, "Missing pw_appid parameter. Did you follow the guide correctly?", e);
289
163
  return false;
290
164
  }
291
-
292
- checkMessage(cordova.getActivity().getIntent());
293
165
  return true;
294
166
  }
295
167
 
296
168
  @CordovaMethod
297
- private boolean registerDevice(JSONArray data, CallbackContext callbackContext)
298
- {
299
- try
300
- {
169
+ private boolean additionalAuthorizationOptions(JSONArray data, CallbackContext callbackContext) {
170
+ // Stub, this is iOS only method
171
+ }
172
+
173
+ @CordovaMethod
174
+ private boolean registerDevice(JSONArray data, CallbackContext callbackContext) {
175
+ try {
301
176
  callbackIds.put("registerDevice", callbackContext);
302
- mPushManager.registerForPushNotifications();
303
- }
304
- catch (java.lang.RuntimeException e)
305
- {
306
- callbackIds.remove("registerDevice");;
177
+ Pushwoosh.getInstance().registerForPushNotifications(new Callback<String, RegisterForPushNotificationsException>() {
178
+ @Override
179
+ public void process(@NonNull final Result<String, RegisterForPushNotificationsException> result) {
180
+ if (result.isSuccess()) {
181
+ doOnRegistered(result.getData());
182
+ } else if (result.getException() != null) {
183
+ doOnRegisteredError(result.getException().getMessage());
184
+ }
185
+ }
186
+ });
187
+ } catch (java.lang.RuntimeException e) {
188
+ callbackIds.remove("registerDevice");
307
189
  PWLog.error(TAG, "registering for push notifications failed", e);
308
190
 
309
191
  callbackContext.error(e.getMessage());
310
192
  }
311
193
 
312
- checkMessage(cordova.getActivity().getIntent());
313
194
  return true;
314
195
  }
315
196
 
316
197
  @CordovaMethod
317
- private boolean unregisterDevice(JSONArray data, CallbackContext callbackContext)
318
- {
198
+ private boolean unregisterDevice(JSONArray data, CallbackContext callbackContext) {
319
199
  callbackIds.put("unregisterDevice", callbackContext);
320
200
 
321
- try
322
- {
323
- mPushManager.unregisterForPushNotifications();
324
- }
325
- catch (Exception e)
326
- {
201
+ try {
202
+ Pushwoosh.getInstance().unregisterForPushNotifications(new Callback<String, UnregisterForPushNotificationException>() {
203
+ @Override
204
+ public void process(@NonNull final Result<String, UnregisterForPushNotificationException> result) {
205
+ if (result.isSuccess()) {
206
+ doOnUnregistered(result.getData());
207
+ } else if (result.getException() != null) {
208
+ doOnUnregisteredError(result.getException().getMessage());
209
+ }
210
+ }
211
+ });
212
+ } catch (Exception e) {
327
213
  callbackIds.remove("unregisterDevice");
328
214
  callbackContext.error(e.getMessage());
329
215
  }
@@ -332,162 +218,68 @@ public class PushNotifications extends CordovaPlugin
332
218
  }
333
219
 
334
220
  @CordovaMethod
335
- private boolean setTags(JSONArray data, final CallbackContext callbackContext)
336
- {
221
+ private boolean setTags(JSONArray data, final CallbackContext callbackContext) {
337
222
  JSONObject params;
338
- try
339
- {
223
+ try {
340
224
  params = data.getJSONObject(0);
341
- }
342
- catch (JSONException e)
343
- {
225
+ } catch (JSONException e) {
344
226
  PWLog.error(TAG, "No tags information passed (missing parameters)", e);
345
227
  return false;
346
228
  }
347
-
348
- @SuppressWarnings("unchecked")
349
- Iterator<String> nameItr = params.keys();
350
- Map<String, Object> paramsMap = new HashMap<String, Object>();
351
- while (nameItr.hasNext())
352
- {
353
- try
354
- {
355
- String name = nameItr.next();
356
- paramsMap.put(name, params.get(name));
357
- }
358
- catch (JSONException e)
359
- {
360
- PWLog.error(TAG, "Tag parameter is invalid", e);
361
- return false;
362
- }
363
- }
364
-
365
229
  callbackIds.put("setTags", callbackContext);
366
230
 
367
- final class SendTagsListenerImpl implements SendPushTagsCallBack
368
- {
231
+ Pushwoosh.getInstance().sendTags(Tags.fromJson(params), new Callback<Void, PushwooshException>() {
369
232
  @Override
370
- public void onSentTagsSuccess(Map<String, String> skippedTags)
371
- {
233
+ public void process(@NonNull final Result<Void, PushwooshException> result) {
372
234
  CallbackContext callback = callbackIds.get("setTags");
373
- if (callback == null)
235
+ if (callback == null) {
374
236
  return;
237
+ }
375
238
 
376
- callback.success(new JSONObject(skippedTags));
377
- callbackIds.remove("setTags");
378
- }
239
+ if(result.isSuccess()){
240
+ callback.success(new JSONObject());
241
+ } else if(result.getException()!=null){
242
+ callback.error(result.getException().getMessage());
243
+ }
379
244
 
380
- @Override
381
- public void onSentTagsError(Exception e)
382
- {
383
- CallbackContext callback = callbackIds.get("setTags");
384
- if (callback == null)
385
- return;
386
-
387
- callback.error(e.getMessage());
388
245
  callbackIds.remove("setTags");
389
246
  }
247
+ });
390
248
 
391
- @Override
392
- public void taskStarted()
393
- {
394
- }
395
- }
396
-
397
- PushManager.sendTags(cordova.getActivity(), paramsMap, new SendTagsListenerImpl());
398
249
  return true;
399
250
  }
400
251
 
401
252
  @CordovaMethod
402
- private boolean getTags(JSONArray data, final CallbackContext callbackContext)
403
- {
253
+ private boolean getTags(JSONArray data, final CallbackContext callbackContext) {
404
254
  callbackIds.put("getTags", callbackContext);
405
255
 
406
- final class GetTagsListenerImpl implements GetTagsListener
407
- {
408
- @Override
409
- public void onTagsReceived(Map<String, Object> tags)
410
- {
411
- CallbackContext callback = callbackIds.get("getTags");
412
- if (callback == null)
413
- return;
414
-
415
- callback.success(new JSONObject(tags));
416
- callbackIds.remove("getTags");
417
- }
418
-
256
+ Pushwoosh.getInstance().getTags(new Callback<TagsBundle, GetTagsException>() {
419
257
  @Override
420
- public void onError(Exception e)
421
- {
258
+ public void process(@NonNull final Result<TagsBundle, GetTagsException> result) {
422
259
  CallbackContext callback = callbackIds.get("getTags");
423
260
  if (callback == null)
424
261
  return;
425
262
 
426
- callback.error(e.getMessage());
263
+ if(result.isSuccess()) {
264
+ callback.success(result.getData().toJson());
265
+ } else {
266
+ callback.error(result.getException().getMessage());
267
+ }
427
268
  callbackIds.remove("getTags");
428
269
  }
429
- }
430
-
431
- PushManager.getTagsAsync(cordova.getActivity(), new GetTagsListenerImpl());
432
- return true;
433
- }
434
-
435
- @CordovaMethod
436
- private boolean getPushToken(JSONArray data, final CallbackContext callbackContext)
437
- {
438
- callbackContext.success(PushManager.getPushToken(cordova.getActivity()));
439
- return true;
440
- }
441
-
442
- @CordovaMethod
443
- private boolean getPushwooshHWID(JSONArray data, final CallbackContext callbackContext)
444
- {
445
- callbackContext.success(PushManager.getPushwooshHWID(cordova.getActivity()));
446
- return true;
447
- }
448
-
449
- @CordovaMethod
450
- private boolean startLocationTracking(JSONArray data, final CallbackContext callbackContext)
451
- {
452
- mPushManager.startTrackingGeoPushes();
453
- return true;
454
- }
455
-
456
- @CordovaMethod
457
- private boolean stopLocationTracking(JSONArray data, final CallbackContext callbackContext)
458
- {
459
- mPushManager.stopTrackingGeoPushes();
460
- return true;
461
- }
462
-
463
- @CordovaMethod
464
- private boolean startBeaconPushes(JSONArray data, final CallbackContext callbackContext)
465
- {
466
- mPushManager.startTrackingBeaconPushes();
270
+ });
467
271
  return true;
468
272
  }
469
273
 
470
274
  @CordovaMethod
471
- private boolean stopBeaconPushes(JSONArray data, final CallbackContext callbackContext)
472
- {
473
- mPushManager.stopTrackingBeaconPushes();
275
+ private boolean getPushToken(JSONArray data, final CallbackContext callbackContext) {
276
+ callbackContext.success(Pushwoosh.getInstance().getPushToken());
474
277
  return true;
475
278
  }
476
279
 
477
280
  @CordovaMethod
478
- private boolean setBeaconBackgroundMode(JSONArray data, final CallbackContext callbackContext)
479
- {
480
- try
481
- {
482
- boolean type = data.getBoolean(0);
483
- PushManager.setBeaconBackgroundMode(cordova.getActivity(), type);
484
- }
485
- catch (Exception e)
486
- {
487
- PWLog.error(TAG, "No parameters passed (missing parameters)", e);
488
- return false;
489
- }
490
-
281
+ private boolean getPushwooshHWID(JSONArray data, final CallbackContext callbackContext) {
282
+ callbackContext.success(Pushwoosh.getInstance().getHwid());
491
283
  return true;
492
284
  }
493
285
 
@@ -509,17 +301,22 @@ public class PushNotifications extends CordovaPlugin
509
301
  {
510
302
  //config params: {msg:"message", seconds:30, userData:"optional"}
511
303
  String message = params.getString("msg");
512
- Integer seconds = params.getInt("seconds");
513
- if (message == null || seconds == null)
304
+ int seconds = params.getInt("seconds");
305
+ if (message == null) {
514
306
  return false;
515
-
516
- String userData = params.getString("userData");
517
-
307
+ }
308
+
518
309
  Bundle extras = new Bundle();
519
- if (userData != null)
520
- extras.putString("u", userData);
521
-
522
- PushManager.scheduleLocalNotification(cordova.getActivity(), message, extras, seconds);
310
+ if (params.has("userData")) {
311
+ extras.putString("u", params.getString("userData"));
312
+ }
313
+
314
+ LocalNotification notification = new LocalNotification.Builder()
315
+ .setMessage(message)
316
+ .setDelay(seconds)
317
+ .setExtras(extras)
318
+ .build();
319
+ Pushwoosh.getInstance().scheduleLocalNotification(notification);
523
320
  }
524
321
  catch (JSONException e)
525
322
  {
@@ -533,22 +330,18 @@ public class PushNotifications extends CordovaPlugin
533
330
  @CordovaMethod
534
331
  private boolean clearLocalNotification(JSONArray data, final CallbackContext callbackContext)
535
332
  {
536
- PushManager.clearLocalNotifications(cordova.getActivity());
333
+ LocalNotificationReceiver.cancelAll();
537
334
  return true;
538
335
  }
539
336
 
540
337
  @CordovaMethod
541
338
  private boolean getLaunchNotification(JSONArray data, final CallbackContext callbackContext)
542
339
  {
543
- String launchNotification = mPushManager.getLaunchNotification();
544
- // unfortunately null object can only be returned as String
545
- if (launchNotification != null)
546
- {
547
- callbackContext.success(launchNotification);
548
- }
549
- else
550
- {
340
+ PushMessage launchNotification = Pushwoosh.getInstance().getLaunchNotification();
341
+ if (launchNotification == null) {
551
342
  callbackContext.success((String) null);
343
+ } else {
344
+ callbackContext.success(launchNotification.toJson().toString());
552
345
  }
553
346
  return true;
554
347
  }
@@ -556,21 +349,21 @@ public class PushNotifications extends CordovaPlugin
556
349
  @CordovaMethod
557
350
  private boolean clearLaunchNotification(JSONArray data, final CallbackContext callbackContext)
558
351
  {
559
- mPushManager.clearLaunchNotification();
352
+ Pushwoosh.getInstance().clearLaunchNotification();
560
353
  return true;
561
354
  }
562
355
 
563
356
  @CordovaMethod
564
357
  private boolean setMultiNotificationMode(JSONArray data, final CallbackContext callbackContext)
565
358
  {
566
- PushManager.setMultiNotificationMode(cordova.getActivity());
359
+ PushwooshNotificationSettings.setMultiNotificationMode(true);
567
360
  return true;
568
361
  }
569
362
 
570
363
  @CordovaMethod
571
364
  private boolean setSingleNotificationMode(JSONArray data, final CallbackContext callbackContext)
572
365
  {
573
- PushManager.setSimpleNotificationMode(cordova.getActivity());
366
+ PushwooshNotificationSettings.setMultiNotificationMode(false);
574
367
  return true;
575
368
  }
576
369
 
@@ -583,7 +376,7 @@ public class PushNotifications extends CordovaPlugin
583
376
  if (type == null)
584
377
  return false;
585
378
 
586
- PushManager.setSoundNotificationType(cordova.getActivity(), SoundType.fromInt(type));
379
+ PushwooshNotificationSettings.setSoundNotificationType(SoundType.fromInt(type));
587
380
  }
588
381
  catch (Exception e)
589
382
  {
@@ -603,7 +396,7 @@ public class PushNotifications extends CordovaPlugin
603
396
  if (type == null)
604
397
  return false;
605
398
 
606
- PushManager.setVibrateNotificationType(cordova.getActivity(), VibrateType.fromInt(type));
399
+ PushwooshNotificationSettings.setVibrateNotificationType(VibrateType.fromInt(type));
607
400
  }
608
401
  catch (Exception e)
609
402
  {
@@ -620,7 +413,7 @@ public class PushNotifications extends CordovaPlugin
620
413
  try
621
414
  {
622
415
  boolean type = (boolean) data.getBoolean(0);
623
- PushManager.setLightScreenOnNotification(cordova.getActivity(), type);
416
+ PushwooshNotificationSettings.setLightScreenOnNotification(type);
624
417
  }
625
418
  catch (Exception e)
626
419
  {
@@ -637,7 +430,7 @@ public class PushNotifications extends CordovaPlugin
637
430
  try
638
431
  {
639
432
  boolean type = (boolean) data.getBoolean(0);
640
- PushManager.setEnableLED(cordova.getActivity(), type);
433
+ PushwooshNotificationSettings.setEnableLED(type);
641
434
  }
642
435
  catch (Exception e)
643
436
  {
@@ -658,7 +451,7 @@ public class PushNotifications extends CordovaPlugin
658
451
  return false;
659
452
 
660
453
  int colorLed = GeneralUtils.parseColor(colorString);
661
- PushManager.setColorLED(cordova.getActivity(), colorLed);
454
+ PushwooshNotificationSettings.setColorLED(colorLed);
662
455
  }
663
456
  catch (Exception e)
664
457
  {
@@ -672,7 +465,12 @@ public class PushNotifications extends CordovaPlugin
672
465
  @CordovaMethod
673
466
  private boolean getPushHistory(JSONArray data, final CallbackContext callbackContext)
674
467
  {
675
- ArrayList<String> pushHistory = mPushManager.getPushHistory();
468
+ List<PushMessage> pushMessageHistory = Pushwoosh.getInstance().getPushHistory();
469
+ List<String> pushHistory = new ArrayList<String>();
470
+
471
+ for (PushMessage pushMessage: pushMessageHistory){
472
+ pushHistory.add(pushMessage.toJson().toString());
473
+ }
676
474
  callbackContext.success(new JSONArray(pushHistory));
677
475
  return true;
678
476
  }
@@ -680,14 +478,14 @@ public class PushNotifications extends CordovaPlugin
680
478
  @CordovaMethod
681
479
  private boolean clearPushHistory(JSONArray data, final CallbackContext callbackContext)
682
480
  {
683
- mPushManager.clearPushHistory();
481
+ Pushwoosh.getInstance().clearPushHistory();
684
482
  return true;
685
483
  }
686
484
 
687
485
  @CordovaMethod
688
486
  private boolean clearNotificationCenter(JSONArray data, final CallbackContext callbackContext)
689
487
  {
690
- PushManager.clearNotificationCenter(cordova.getActivity());
488
+ NotificationManagerCompat.from(cordova.getActivity()).cancelAll();
691
489
  return true;
692
490
  }
693
491
 
@@ -697,10 +495,7 @@ public class PushNotifications extends CordovaPlugin
697
495
  try
698
496
  {
699
497
  Integer badgeNumber = data.getJSONObject(0).getInt("badge");
700
- if (badgeNumber == null)
701
- return false;
702
-
703
- mPushManager.setBadgeNumber(badgeNumber);
498
+ PushwooshBadge.setBadgeNumber(badgeNumber);
704
499
  }
705
500
  catch (JSONException e)
706
501
  {
@@ -713,7 +508,7 @@ public class PushNotifications extends CordovaPlugin
713
508
  @CordovaMethod
714
509
  private boolean getApplicationIconBadgeNumber(JSONArray data, final CallbackContext callbackContext)
715
510
  {
716
- Integer badgeNumber = new Integer(mPushManager.getBadgeNumber());
511
+ Integer badgeNumber = PushwooshBadge.getBadgeNumber();
717
512
  callbackContext.success(badgeNumber);
718
513
  return true;
719
514
  }
@@ -724,9 +519,7 @@ public class PushNotifications extends CordovaPlugin
724
519
  try
725
520
  {
726
521
  Integer badgeNumber = data.getJSONObject(0).getInt("badge");
727
- if (badgeNumber == null)
728
- return false;
729
- mPushManager.addBadgeNumber(badgeNumber);
522
+ PushwooshBadge.addBadgeNumber(badgeNumber);
730
523
  }
731
524
  catch (JSONException e)
732
525
  {
@@ -742,7 +535,7 @@ public class PushNotifications extends CordovaPlugin
742
535
  try
743
536
  {
744
537
  String userId = data.getString(0);
745
- mPushManager.setUserId(cordova.getActivity(), userId);
538
+ PushwooshInApp.getInstance().setUserId(userId);
746
539
  }
747
540
  catch (JSONException e)
748
541
  {
@@ -758,7 +551,7 @@ public class PushNotifications extends CordovaPlugin
758
551
  {
759
552
  String event = data.getString(0);
760
553
  JSONObject attributes = data.getJSONObject(1);
761
- InAppFacade.postEvent(cordova.getActivity(), event, JsonUtils.jsonToMap(attributes));
554
+ PushwooshInApp.getInstance().postEvent(event, Tags.fromJson(attributes));
762
555
  }
763
556
  catch (JSONException e)
764
557
  {
@@ -772,7 +565,7 @@ public class PushNotifications extends CordovaPlugin
772
565
  {
773
566
  try
774
567
  {
775
- String enabled = PushManager.isNotificationEnabled(cordova.getActivity()) ? "1" : "0";
568
+ String enabled = PushwooshNotificationSettings.areNotificationsEnabled() ? "1" : "0";
776
569
  JSONObject result = new JSONObject();
777
570
  result.put("enabled", enabled);
778
571
  callbackContext.success(result);
@@ -785,6 +578,91 @@ public class PushNotifications extends CordovaPlugin
785
578
  return true;
786
579
  }
787
580
 
581
+ @CordovaMethod
582
+ private boolean presentInboxUI(JSONArray data, final CallbackContext callbackContext) {
583
+ if (data.length() > 0)
584
+ InboxUiStyleManager.setStyle(this.cordova.getActivity(), data.optJSONObject(0));
585
+ this.cordova.getActivity().startActivity(new Intent(this.cordova.getActivity(), InboxActivity.class));
586
+ return true;
587
+ }
588
+
589
+ @CordovaMethod
590
+ public boolean showGDPRConsentUI(JSONArray data, final CallbackContext callbackContext){
591
+ GDPRManager.getInstance().showGDPRConsentUI();
592
+ return true;
593
+ }
594
+
595
+ @CordovaMethod
596
+ public boolean showGDPRDeletionUI(JSONArray data, final CallbackContext callbackContext){
597
+ GDPRManager.getInstance().showGDPRDeletionUI();
598
+ return true;
599
+ }
600
+
601
+ @CordovaMethod
602
+ public boolean isDeviceDataRemoved(JSONArray data, final CallbackContext callbackContext){
603
+ boolean removed = GDPRManager.getInstance().isDeviceDataRemoved();
604
+ callbackContext.success(removed ? 1 : 0);
605
+ return true;
606
+ }
607
+
608
+ @CordovaMethod
609
+ public boolean isCommunicationEnabled(JSONArray data, final CallbackContext callbackContext){
610
+ boolean enabled = GDPRManager.getInstance().isCommunicationEnabled();
611
+ callbackContext.success(enabled ? 1 : 0);
612
+ return true;
613
+
614
+ }
615
+
616
+ @CordovaMethod
617
+ public boolean isAvailableGDPR(JSONArray data, final CallbackContext callbackContext){
618
+ boolean isAvailableGDPR = GDPRManager.getInstance().isAvailable();
619
+ callbackContext.success(isAvailableGDPR ? 1 : 0);
620
+ return true;
621
+ }
622
+
623
+ @CordovaMethod
624
+ public boolean removeAllDeviceData(JSONArray data, final CallbackContext callbackContext){
625
+ GDPRManager.getInstance().removeAllDeviceData(new Callback<Void, PushwooshException>() {
626
+ @Override
627
+ public void process(@NonNull Result<Void, PushwooshException> result) {
628
+ if(result.isSuccess()){
629
+ callbackContext.success();
630
+ }else {
631
+ callbackContext.error(result.getException().getMessage());
632
+ }
633
+ }
634
+ });
635
+ return true;
636
+ }
637
+
638
+ @CordovaMethod
639
+ public boolean setCommunicationEnabled(JSONArray data, final CallbackContext callbackContext){
640
+ try {
641
+ boolean enable = data.getBoolean(0);
642
+ GDPRManager.getInstance().setCommunicationEnabled(enable, new Callback<Void, PushwooshException>() {
643
+ @Override
644
+ public void process(@NonNull Result<Void, PushwooshException> result) {
645
+ if(result.isSuccess()){
646
+ callbackContext.success();
647
+ }else {
648
+ callbackContext.error(result.getException().getMessage());
649
+ }
650
+ }
651
+ });
652
+ return true;
653
+ } catch (JSONException e) {
654
+ e.printStackTrace();
655
+ }
656
+ return false;
657
+ }
658
+
659
+ @CordovaMethod
660
+ public boolean enableHuaweiPushNotifications(JSONArray data, final CallbackContext callbackContext) {
661
+ Pushwoosh.getInstance().enableHuaweiPushNotifications();
662
+ return true;
663
+ }
664
+
665
+
788
666
  @Override
789
667
  public boolean execute(String action, JSONArray data, CallbackContext callbackId)
790
668
  {
@@ -865,6 +743,7 @@ public class PushNotifications extends CordovaPlugin
865
743
 
866
744
  String jsStatement = String.format("cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").notificationCallback(%s);", convertNotification(notification));
867
745
  evalJs(jsStatement);
746
+ sStartPushData = null;
868
747
  }
869
748
 
870
749
  public void doOnPushReceived(String notification)
@@ -873,6 +752,8 @@ public class PushNotifications extends CordovaPlugin
873
752
 
874
753
  String jsStatement = String.format("cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").pushReceivedCallback(%s);", convertNotification(notification));
875
754
  evalJs(jsStatement);
755
+
756
+ sReceivedPushData = null;
876
757
  }
877
758
 
878
759
  private String convertNotification(String notification)
@@ -901,7 +782,7 @@ public class PushNotifications extends CordovaPlugin
901
782
  String result = unifiedNotification.toString();
902
783
 
903
784
  // wrap special characters
904
- result.replace("%", "%\"+\"");
785
+ result = result.replace("%", "%\"+\"");
905
786
 
906
787
  return result;
907
788
  }
@@ -910,13 +791,83 @@ public class PushNotifications extends CordovaPlugin
910
791
  {
911
792
  final String url = "javascript:" + statement;
912
793
 
913
- cordova.getActivity().runOnUiThread(new Runnable()
794
+ handler.post(new Runnable()
914
795
  {
915
796
  @Override
916
797
  public void run()
917
798
  {
918
- webView.loadUrl(url);
799
+ try
800
+ {
801
+ webView.loadUrl(url);
802
+ }
803
+ catch (Exception e)
804
+ {
805
+ PWLog.exception(e);
806
+ }
919
807
  }
920
808
  });
921
809
  }
810
+
811
+
812
+ static void openPush(String pushData) {
813
+ try {
814
+ synchronized (sStartPushLock) {
815
+ sStartPushData = pushData;
816
+ if (sAppReady.get() && sInstance != null) {
817
+ sInstance.doOnPushOpened(pushData);
818
+ }
819
+ }
820
+ } catch (Exception e) {
821
+ // React Native is highly unstable
822
+ PWLog.exception(e);
823
+ }
824
+ }
825
+
826
+ static void messageReceived(String pushData) {
827
+ try {
828
+ synchronized (sStartPushLock) {
829
+ sReceivedPushData = pushData;
830
+ if (sAppReady.get() && sInstance != null) {
831
+ sInstance.doOnPushReceived(pushData);
832
+ }
833
+ }
834
+ } catch (Exception e) {
835
+ // React Native is highly unstable
836
+ PWLog.exception(e);
837
+ }
838
+ }
839
+
840
+
841
+ public class JavascriptInterfaceCordova {
842
+ @JavascriptInterface
843
+ public void callFunction(String functionName) {
844
+ String url = String.format("%s();", functionName);
845
+ evalJs(url);
846
+ }
847
+
848
+ @JavascriptInterface
849
+ public void callFunction(String functionName, String args) {
850
+ String url;
851
+ if (args == null || args.isEmpty()) {
852
+ url = String.format("%s();", functionName);
853
+ } else {
854
+ url = String.format("%s(%s);", functionName, args);
855
+ }
856
+ evalJs(url);
857
+ }
858
+ }
859
+
860
+ @CordovaMethod
861
+ private boolean addJavaScriptInterface(JSONArray data, final CallbackContext callbackContext) {
862
+ try {
863
+ String name = data.getString(0);
864
+ PushwooshInApp.getInstance().addJavascriptInterface(new JavascriptInterfaceCordova(), name);
865
+ } catch (JSONException e) {
866
+ PWLog.error(TAG, "No parameters has been passed to addJavaScriptInterface function. Did you follow the guide correctly?", e);
867
+ return false;
868
+ }
869
+
870
+ return true;
871
+ }
872
+
922
873
  }