reteno-react-native-sdk 2.2.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +9 -1
- package/android/src/main/java/com/retenosdk/RetenoClickReceiver.java +8 -0
- package/android/src/main/java/com/retenosdk/RetenoNotificationGroupingRuleProvider.java +18 -6
- package/android/src/main/java/com/retenosdk/RetenoNotificationSummaryManager.java +273 -0
- package/android/src/main/java/com/retenosdk/RetenoSdkModule.java +89 -43
- package/android/src/oldarch/java/com/retenosdk/NativeRetenoSdkSpec.java +10 -0
- package/ios/RetenoSdk.mm +172 -0
- package/ios/RetenoSdk.swift +90 -32
- package/ios/RetenoSdk.xcodeproj/project.pbxproj +2 -2
- package/lib/commonjs/NativeRetenoSdk.js +9 -0
- package/lib/commonjs/NativeRetenoSdk.js.map +1 -0
- package/lib/commonjs/index.js +239 -107
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/NativeRetenoSdk.js +3 -0
- package/lib/module/NativeRetenoSdk.js.map +1 -0
- package/lib/module/index.js +234 -108
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/NativeRetenoSdk.d.ts +50 -0
- package/lib/typescript/NativeRetenoSdk.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +200 -50
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +15 -6
- package/src/NativeRetenoSdk.ts +62 -0
- package/src/index.ts +387 -153
- package/ios/RetenoSdk.m +0 -135
package/android/build.gradle
CHANGED
|
@@ -57,6 +57,14 @@ android {
|
|
|
57
57
|
targetCompatibility JavaVersion.VERSION_1_8
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
sourceSets {
|
|
61
|
+
main {
|
|
62
|
+
if (!isNewArchitectureEnabled()) {
|
|
63
|
+
java.srcDirs += ["src/oldarch/java"]
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
60
68
|
}
|
|
61
69
|
|
|
62
70
|
repositories {
|
|
@@ -81,7 +89,7 @@ dependencies {
|
|
|
81
89
|
if (isNewArchitectureEnabled()) {
|
|
82
90
|
react {
|
|
83
91
|
jsRootDir = file("../src/")
|
|
84
|
-
libraryName = "
|
|
92
|
+
libraryName = "RetenoSdkSpec"
|
|
85
93
|
codegenJavaPackageName = "com.retenosdk"
|
|
86
94
|
}
|
|
87
95
|
}
|
|
@@ -3,10 +3,18 @@ package com.retenosdk;
|
|
|
3
3
|
import android.content.BroadcastReceiver;
|
|
4
4
|
import android.content.Context;
|
|
5
5
|
import android.content.Intent;
|
|
6
|
+
import android.os.Bundle;
|
|
7
|
+
|
|
8
|
+
import com.reteno.push.events.NotificationClick;
|
|
6
9
|
|
|
7
10
|
public class RetenoClickReceiver extends BroadcastReceiver {
|
|
8
11
|
@Override
|
|
9
12
|
public void onReceive(Context context, Intent intent) {
|
|
13
|
+
Bundle extras = intent.getExtras();
|
|
14
|
+
// Registering this receiver in the manifest's NotificationClicked meta-data replaces
|
|
15
|
+
// Reteno's own click receiver, which is what normally drives NotificationClick listeners
|
|
16
|
+
// (e.g. RetenoNotificationSummaryManager). Notify it ourselves so those listeners still fire.
|
|
17
|
+
NotificationClick.INSTANCE.notifyListeners(extras != null ? extras : Bundle.EMPTY);
|
|
10
18
|
RetenoSdkModule.onRetenoPushClicked(context, intent);
|
|
11
19
|
}
|
|
12
20
|
}
|
|
@@ -17,6 +17,7 @@ public final class RetenoNotificationGroupingRuleProvider extends ContentProvide
|
|
|
17
17
|
private static final String PREFERENCES = "com.retenosdk.notification-grouping-rule";
|
|
18
18
|
private static final String PAYLOAD_KEY = "payloadKey";
|
|
19
19
|
private static final String GROUP_ID = "groupId";
|
|
20
|
+
private static final String SHOW_SUMMARY = "showSummary";
|
|
20
21
|
|
|
21
22
|
@Override
|
|
22
23
|
public boolean onCreate() {
|
|
@@ -27,27 +28,33 @@ public final class RetenoNotificationGroupingRuleProvider extends ContentProvide
|
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
static void configure(Context context, String payloadKey, String groupId) {
|
|
31
|
+
static void configure(Context context, String payloadKey, String groupId, boolean showSummary) {
|
|
31
32
|
SharedPreferences.Editor editor = preferences(context).edit().clear();
|
|
32
33
|
if (!TextUtils.isEmpty(payloadKey)) {
|
|
33
34
|
editor.putString(PAYLOAD_KEY, payloadKey);
|
|
34
35
|
} else if (!TextUtils.isEmpty(groupId)) {
|
|
35
36
|
editor.putString(GROUP_ID, groupId);
|
|
36
37
|
}
|
|
38
|
+
if (showSummary) {
|
|
39
|
+
editor.putBoolean(SHOW_SUMMARY, true);
|
|
40
|
+
}
|
|
41
|
+
// Persist before returning so a process restart cannot lose a just-configured rule.
|
|
37
42
|
editor.commit();
|
|
38
|
-
install(payloadKey, groupId);
|
|
43
|
+
install(context, payloadKey, groupId, showSummary);
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
private static void restore(Context context) {
|
|
42
47
|
SharedPreferences preferences = preferences(context);
|
|
43
48
|
install(
|
|
49
|
+
context,
|
|
44
50
|
preferences.getString(PAYLOAD_KEY, null),
|
|
45
|
-
preferences.getString(GROUP_ID, null)
|
|
51
|
+
preferences.getString(GROUP_ID, null),
|
|
52
|
+
preferences.getBoolean(SHOW_SUMMARY, false)
|
|
46
53
|
);
|
|
47
54
|
}
|
|
48
55
|
|
|
49
|
-
/** Resolves the group a received push belongs to under the
|
|
50
|
-
|
|
56
|
+
/** Resolves the group a received push belongs to under the persisted rule. */
|
|
57
|
+
static String resolveGroup(Context context, Map<String, String> payload) {
|
|
51
58
|
SharedPreferences preferences = preferences(context);
|
|
52
59
|
String payloadKey = preferences.getString(PAYLOAD_KEY, null);
|
|
53
60
|
if (!TextUtils.isEmpty(payloadKey)) {
|
|
@@ -62,7 +69,7 @@ public final class RetenoNotificationGroupingRuleProvider extends ContentProvide
|
|
|
62
69
|
return context.getSharedPreferences(PREFERENCES, Context.MODE_PRIVATE);
|
|
63
70
|
}
|
|
64
71
|
|
|
65
|
-
private static void install(String payloadKey, String groupId) {
|
|
72
|
+
private static void install(Context context, String payloadKey, String groupId, boolean showSummary) {
|
|
66
73
|
if (!TextUtils.isEmpty(payloadKey)) {
|
|
67
74
|
RetenoNotifications.setGroupingRule((Map<String, String> payload) -> {
|
|
68
75
|
String value = payload.get(payloadKey);
|
|
@@ -73,6 +80,11 @@ public final class RetenoNotificationGroupingRuleProvider extends ContentProvide
|
|
|
73
80
|
} else {
|
|
74
81
|
RetenoNotifications.setGroupingRule(null);
|
|
75
82
|
}
|
|
83
|
+
RetenoNotificationSummaryManager.setEnabled(
|
|
84
|
+
context,
|
|
85
|
+
showSummary && (!TextUtils.isEmpty(payloadKey) || !TextUtils.isEmpty(groupId)),
|
|
86
|
+
!TextUtils.isEmpty(payloadKey) ? "payloadKey:" + payloadKey : "groupId:" + groupId
|
|
87
|
+
);
|
|
76
88
|
}
|
|
77
89
|
|
|
78
90
|
@Override
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
package com.retenosdk;
|
|
2
|
+
|
|
3
|
+
import android.Manifest;
|
|
4
|
+
import android.app.Notification;
|
|
5
|
+
import android.app.NotificationChannel;
|
|
6
|
+
import android.app.NotificationManager;
|
|
7
|
+
import android.content.Context;
|
|
8
|
+
import android.content.pm.PackageManager;
|
|
9
|
+
import android.os.Build;
|
|
10
|
+
import android.os.Bundle;
|
|
11
|
+
import android.os.Handler;
|
|
12
|
+
import android.os.Looper;
|
|
13
|
+
import android.service.notification.StatusBarNotification;
|
|
14
|
+
|
|
15
|
+
import androidx.core.app.ActivityCompat;
|
|
16
|
+
import androidx.core.app.NotificationCompat;
|
|
17
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
18
|
+
|
|
19
|
+
import com.reteno.core.util.Procedure;
|
|
20
|
+
import com.reteno.push.RetenoNotifications;
|
|
21
|
+
|
|
22
|
+
import java.util.HashMap;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
import java.util.Objects;
|
|
25
|
+
|
|
26
|
+
/** Maintains optional Android group-summary notifications for Reteno pushes. */
|
|
27
|
+
final class RetenoNotificationSummaryManager {
|
|
28
|
+
private static final String SUMMARY_CHANNEL_ID = "reteno_group_summary";
|
|
29
|
+
private static final String SUMMARY_TAG_PREFIX = "com.retenosdk.group-summary:";
|
|
30
|
+
private static final int SUMMARY_NOTIFICATION_ID = 1;
|
|
31
|
+
private static final int MAX_POST_ATTEMPTS = 25;
|
|
32
|
+
private static final int MAX_REMOVAL_ATTEMPTS = 10;
|
|
33
|
+
private static final long RETRY_DELAY_MS = 200L;
|
|
34
|
+
|
|
35
|
+
private static RetenoNotificationSummaryManager instance;
|
|
36
|
+
|
|
37
|
+
private final Context context;
|
|
38
|
+
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
|
39
|
+
private final Handler retryHandler = new Handler(Looper.getMainLooper());
|
|
40
|
+
private final NotificationManagerCompat notificationManager;
|
|
41
|
+
|
|
42
|
+
private Procedure<Bundle> receivedListener;
|
|
43
|
+
private Procedure<Bundle> clickListener;
|
|
44
|
+
private Procedure<Bundle> closeListener;
|
|
45
|
+
private boolean enabled;
|
|
46
|
+
private String ruleIdentity;
|
|
47
|
+
|
|
48
|
+
private RetenoNotificationSummaryManager(Context context) {
|
|
49
|
+
this.context = context.getApplicationContext();
|
|
50
|
+
this.notificationManager = NotificationManagerCompat.from(this.context);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static synchronized void setEnabled(Context context, boolean enabled, String ruleIdentity) {
|
|
54
|
+
if (instance == null) {
|
|
55
|
+
instance = new RetenoNotificationSummaryManager(context);
|
|
56
|
+
}
|
|
57
|
+
instance.runOnMainThread(() -> instance.updateEnabled(enabled, ruleIdentity));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
private void runOnMainThread(Runnable action) {
|
|
61
|
+
if (Looper.myLooper() == Looper.getMainLooper()) {
|
|
62
|
+
action.run();
|
|
63
|
+
} else {
|
|
64
|
+
mainHandler.post(action);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private void updateEnabled(boolean shouldEnable, String ruleIdentity) {
|
|
69
|
+
if (shouldEnable) {
|
|
70
|
+
enable(ruleIdentity);
|
|
71
|
+
} else {
|
|
72
|
+
disable();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private void enable(String ruleIdentity) {
|
|
77
|
+
if (enabled) {
|
|
78
|
+
if (Objects.equals(this.ruleIdentity, ruleIdentity)) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// The grouping rule may have changed since we were last enabled. Drop any pending
|
|
82
|
+
// retry first - it closed over the old group and would otherwise recreate a stale
|
|
83
|
+
// summary via reconcile() after we cancel it below.
|
|
84
|
+
retryHandler.removeCallbacksAndMessages(null);
|
|
85
|
+
cancelAllSummaries();
|
|
86
|
+
this.ruleIdentity = ruleIdentity;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
|
90
|
+
// NotificationManagerCompat#getActiveNotifications() is unsupported before API 23, so
|
|
91
|
+
// child counts can't be tracked and summaries can't be maintained.
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
enabled = true;
|
|
95
|
+
this.ruleIdentity = ruleIdentity;
|
|
96
|
+
createSummaryChannel();
|
|
97
|
+
|
|
98
|
+
receivedListener = bundle -> runOnMainThread(() -> onReceived(bundle));
|
|
99
|
+
clickListener = bundle -> runOnMainThread(() -> onRemoved(bundle));
|
|
100
|
+
closeListener = bundle -> runOnMainThread(() -> onRemoved(bundle));
|
|
101
|
+
RetenoNotifications.getReceived().addListener(receivedListener);
|
|
102
|
+
RetenoNotifications.getClick().addListener(clickListener);
|
|
103
|
+
RetenoNotifications.getClose().addListener(closeListener);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private void disable() {
|
|
107
|
+
enabled = false;
|
|
108
|
+
ruleIdentity = null;
|
|
109
|
+
retryHandler.removeCallbacksAndMessages(null);
|
|
110
|
+
if (receivedListener != null) {
|
|
111
|
+
RetenoNotifications.getReceived().removeListener(receivedListener);
|
|
112
|
+
receivedListener = null;
|
|
113
|
+
}
|
|
114
|
+
if (clickListener != null) {
|
|
115
|
+
RetenoNotifications.getClick().removeListener(clickListener);
|
|
116
|
+
clickListener = null;
|
|
117
|
+
}
|
|
118
|
+
if (closeListener != null) {
|
|
119
|
+
RetenoNotifications.getClose().removeListener(closeListener);
|
|
120
|
+
closeListener = null;
|
|
121
|
+
}
|
|
122
|
+
cancelAllSummaries();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private void createSummaryChannel() {
|
|
126
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
127
|
+
// NotificationChannel doesn't exist before API 26.
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
NotificationChannel channel = new NotificationChannel(
|
|
131
|
+
SUMMARY_CHANNEL_ID,
|
|
132
|
+
"Grouped notifications summary",
|
|
133
|
+
NotificationManager.IMPORTANCE_DEFAULT
|
|
134
|
+
);
|
|
135
|
+
notificationManager.createNotificationChannel(channel);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private void onReceived(Bundle bundle) {
|
|
139
|
+
String group = resolveGroup(bundle);
|
|
140
|
+
if (group == null) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
awaitChildAndReconcile(group, notificationId(bundle), 0);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private void awaitChildAndReconcile(String group, int notificationId, int attempt) {
|
|
147
|
+
if (!enabled) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (hasChild(group, notificationId) || attempt >= MAX_POST_ATTEMPTS) {
|
|
151
|
+
reconcile(group);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
retryHandler.postDelayed(
|
|
155
|
+
() -> awaitChildAndReconcile(group, notificationId, attempt + 1),
|
|
156
|
+
RETRY_DELAY_MS
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private void onRemoved(Bundle bundle) {
|
|
161
|
+
if (!enabled) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
String group = resolveGroup(bundle);
|
|
165
|
+
if (group == null) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
awaitRemovalAndReconcile(group, notificationId(bundle), 0);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
private void awaitRemovalAndReconcile(String group, int notificationId, int attempt) {
|
|
172
|
+
if (!enabled) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (hasChild(group, notificationId) && attempt < MAX_REMOVAL_ATTEMPTS) {
|
|
176
|
+
retryHandler.postDelayed(
|
|
177
|
+
() -> awaitRemovalAndReconcile(group, notificationId, attempt + 1),
|
|
178
|
+
RETRY_DELAY_MS
|
|
179
|
+
);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
reconcile(group);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private String resolveGroup(Bundle bundle) {
|
|
186
|
+
return RetenoNotificationGroupingRuleProvider.resolveGroup(context, toStringMap(bundle));
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private Map<String, String> toStringMap(Bundle bundle) {
|
|
190
|
+
Map<String, String> payload = new HashMap<>();
|
|
191
|
+
if (bundle == null) {
|
|
192
|
+
return payload;
|
|
193
|
+
}
|
|
194
|
+
for (String key : bundle.keySet()) {
|
|
195
|
+
Object value = bundle.get(key);
|
|
196
|
+
payload.put(key, value == null ? null : value.toString());
|
|
197
|
+
}
|
|
198
|
+
return payload;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
private int notificationId(Bundle bundle) {
|
|
202
|
+
String interactionId = bundle == null ? null : bundle.getString("es_interaction_id");
|
|
203
|
+
return interactionId == null ? 1 : interactionId.hashCode();
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private boolean hasChild(String group, int notificationId) {
|
|
207
|
+
for (StatusBarNotification sbn : notificationManager.getActiveNotifications()) {
|
|
208
|
+
if (sbn.getId() == notificationId && isChildInGroup(sbn.getNotification(), group)) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
private void reconcile(String group) {
|
|
216
|
+
if (!enabled) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
int childCount = 0;
|
|
221
|
+
for (StatusBarNotification sbn : notificationManager.getActiveNotifications()) {
|
|
222
|
+
if (isChildInGroup(sbn.getNotification(), group)) {
|
|
223
|
+
childCount++;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
String tag = summaryTag(group);
|
|
228
|
+
if (childCount < 2) {
|
|
229
|
+
notificationManager.cancel(tag, SUMMARY_NOTIFICATION_ID);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS)
|
|
233
|
+
!= PackageManager.PERMISSION_GRANTED) {
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
Notification summary = new NotificationCompat.Builder(context, SUMMARY_CHANNEL_ID)
|
|
238
|
+
.setContentTitle("New notifications")
|
|
239
|
+
.setContentText("You have " + childCount + " new notifications")
|
|
240
|
+
.setSmallIcon(resolveSmallIcon())
|
|
241
|
+
.setGroup(group)
|
|
242
|
+
.setGroupSummary(true)
|
|
243
|
+
.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN)
|
|
244
|
+
.setOnlyAlertOnce(true)
|
|
245
|
+
.build();
|
|
246
|
+
|
|
247
|
+
notificationManager.notify(tag, SUMMARY_NOTIFICATION_ID, summary);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
private int resolveSmallIcon() {
|
|
251
|
+
int icon = context.getResources().getIdentifier(
|
|
252
|
+
"reteno_default_push_icon", "drawable", context.getPackageName()
|
|
253
|
+
);
|
|
254
|
+
return icon != 0 ? icon : android.R.drawable.ic_dialog_info;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
private boolean isChildInGroup(Notification notification, String group) {
|
|
258
|
+
return group.equals(notification.getGroup()) && !NotificationCompat.isGroupSummary(notification);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
private String summaryTag(String group) {
|
|
262
|
+
return SUMMARY_TAG_PREFIX + group;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
private void cancelAllSummaries() {
|
|
266
|
+
for (StatusBarNotification sbn : notificationManager.getActiveNotifications()) {
|
|
267
|
+
String tag = sbn.getTag();
|
|
268
|
+
if (tag != null && tag.startsWith(SUMMARY_TAG_PREFIX)) {
|
|
269
|
+
notificationManager.cancel(tag, sbn.getId());
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
@@ -14,7 +14,6 @@ import com.facebook.react.bridge.Arguments;
|
|
|
14
14
|
import com.facebook.react.bridge.Promise;
|
|
15
15
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
16
16
|
import com.facebook.react.bridge.ReactContext;
|
|
17
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
18
17
|
import com.facebook.react.bridge.ReactMethod;
|
|
19
18
|
import com.facebook.react.bridge.ReadableMap;
|
|
20
19
|
import com.facebook.react.bridge.ReadableArray;
|
|
@@ -60,7 +59,7 @@ import java.time.ZonedDateTime;
|
|
|
60
59
|
import java.util.Map;
|
|
61
60
|
import java.util.concurrent.CompletableFuture;
|
|
62
61
|
|
|
63
|
-
public class RetenoSdkModule extends
|
|
62
|
+
public class RetenoSdkModule extends NativeRetenoSdkSpec {
|
|
64
63
|
public static final String NAME = "RetenoSdk";
|
|
65
64
|
private static final String PREFS_NAME = "RetenoPrefs";
|
|
66
65
|
private static final String AUTO_OPEN_LINKS_KEY = "autoOpenLinks";
|
|
@@ -89,6 +88,16 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
89
88
|
return NAME;
|
|
90
89
|
}
|
|
91
90
|
|
|
91
|
+
@ReactMethod
|
|
92
|
+
public void addListener(String eventName) {
|
|
93
|
+
// Required by NativeEventEmitter. Events are registered eagerly by the Reteno callbacks.
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactMethod
|
|
97
|
+
public void removeListeners(double count) {
|
|
98
|
+
// Required by NativeEventEmitter. Individual listener cleanup is handled on the JS side.
|
|
99
|
+
}
|
|
100
|
+
|
|
92
101
|
@Override
|
|
93
102
|
public void onCatalystInstanceDestroy() {
|
|
94
103
|
cleanupRetenoNotificationsListeners();
|
|
@@ -346,6 +355,11 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
346
355
|
promise.resolve(parseIntent(activity.getIntent()));
|
|
347
356
|
}
|
|
348
357
|
|
|
358
|
+
@ReactMethod
|
|
359
|
+
public void registerForRemoteNotifications() {
|
|
360
|
+
// iOS-only API. Kept as an explicit no-op so the generated Spec can be cross-platform.
|
|
361
|
+
}
|
|
362
|
+
|
|
349
363
|
@ReactMethod
|
|
350
364
|
public void logEvent(ReadableMap payload, Promise promise) {
|
|
351
365
|
try {
|
|
@@ -361,6 +375,21 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
361
375
|
promise.resolve(res);
|
|
362
376
|
}
|
|
363
377
|
|
|
378
|
+
@ReactMethod
|
|
379
|
+
public void logScreenView(String screenName, Promise promise) {
|
|
380
|
+
if (screenName == null || screenName.trim().isEmpty()) {
|
|
381
|
+
promise.reject("InvalidArgument", "Missing argument: screenName");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
try {
|
|
386
|
+
getRetenoInstance().logScreenView(screenName);
|
|
387
|
+
promise.resolve(true);
|
|
388
|
+
} catch (Exception e) {
|
|
389
|
+
promise.reject("Reteno Android SDK logScreenView Error", e);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
364
393
|
@ReactMethod
|
|
365
394
|
public void setAnonymousUserAttributes(ReadableMap payload, Promise promise) {
|
|
366
395
|
|
|
@@ -391,7 +420,7 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
391
420
|
}
|
|
392
421
|
|
|
393
422
|
@ReactMethod
|
|
394
|
-
public void pauseInAppMessages(
|
|
423
|
+
public void pauseInAppMessages(boolean isPaused, Promise promise) {
|
|
395
424
|
try {
|
|
396
425
|
getRetenoInstance()
|
|
397
426
|
.pauseInAppMessages(isPaused);
|
|
@@ -809,11 +838,18 @@ public class RetenoSdkModule extends ReactContextBaseJavaModule {
|
|
|
809
838
|
}
|
|
810
839
|
|
|
811
840
|
@ReactMethod
|
|
812
|
-
public void markAsOpened(
|
|
841
|
+
public void markAsOpened(ReadableArray messageIds, Promise promise) {
|
|
813
842
|
try {
|
|
814
|
-
|
|
815
|
-
.
|
|
816
|
-
|
|
843
|
+
if (messageIds != null) {
|
|
844
|
+
for (int i = 0; i < messageIds.size(); i++) {
|
|
845
|
+
String messageId = messageIds.getString(i);
|
|
846
|
+
if (messageId != null && !messageId.isEmpty()) {
|
|
847
|
+
getRetenoInstance()
|
|
848
|
+
.getAppInbox()
|
|
849
|
+
.markAsOpened(messageId);
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
817
853
|
promise.resolve(true);
|
|
818
854
|
} catch (Exception e) {
|
|
819
855
|
promise.reject("Reteno Android SDK markAsOpened Error", e);
|
|
@@ -1134,42 +1170,7 @@ public void logEcomEventSearchRequest(ReadableMap payload, Promise promise) {
|
|
|
1134
1170
|
}
|
|
1135
1171
|
|
|
1136
1172
|
@ReactMethod
|
|
1137
|
-
public void
|
|
1138
|
-
if (rule == null) {
|
|
1139
|
-
RetenoNotificationGroupingRuleProvider.configure(context, null, null);
|
|
1140
|
-
promise.resolve(true);
|
|
1141
|
-
return;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
boolean payloadKeyIsString = rule.hasKey("payloadKey")
|
|
1145
|
-
&& !rule.isNull("payloadKey")
|
|
1146
|
-
&& rule.getType("payloadKey") == ReadableType.String;
|
|
1147
|
-
boolean groupIdIsString = rule.hasKey("groupId")
|
|
1148
|
-
&& !rule.isNull("groupId")
|
|
1149
|
-
&& rule.getType("groupId") == ReadableType.String;
|
|
1150
|
-
String payloadKey = payloadKeyIsString ? rule.getString("payloadKey").trim() : null;
|
|
1151
|
-
String groupId = groupIdIsString ? rule.getString("groupId").trim() : null;
|
|
1152
|
-
boolean hasPayloadKey = payloadKey != null && !payloadKey.isEmpty();
|
|
1153
|
-
boolean hasGroupId = groupId != null && !groupId.isEmpty();
|
|
1154
|
-
|
|
1155
|
-
if (hasPayloadKey == hasGroupId) {
|
|
1156
|
-
promise.reject(
|
|
1157
|
-
"InvalidArgument",
|
|
1158
|
-
"Invalid argument: provide exactly one non-empty payloadKey or groupId"
|
|
1159
|
-
);
|
|
1160
|
-
return;
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
RetenoNotificationGroupingRuleProvider.configure(
|
|
1164
|
-
context,
|
|
1165
|
-
hasPayloadKey ? payloadKey : null,
|
|
1166
|
-
hasGroupId ? groupId : null
|
|
1167
|
-
);
|
|
1168
|
-
promise.resolve(true);
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
@ReactMethod
|
|
1172
|
-
public void pausePushInAppMessages(Boolean isPaused, Promise promise) {
|
|
1173
|
+
public void pausePushInAppMessages(boolean isPaused, Promise promise) {
|
|
1173
1174
|
try {
|
|
1174
1175
|
getRetenoInstance()
|
|
1175
1176
|
.pausePushInAppMessages(isPaused);
|
|
@@ -1206,4 +1207,49 @@ public void logEcomEventSearchRequest(ReadableMap payload, Promise promise) {
|
|
|
1206
1207
|
promise.reject("Reteno Android SDK setPushInAppMessagesPauseBehaviour Error", e);
|
|
1207
1208
|
}
|
|
1208
1209
|
}
|
|
1210
|
+
|
|
1211
|
+
@ReactMethod
|
|
1212
|
+
public void setNotificationGroupingRule(@Nullable ReadableMap rule, Promise promise) {
|
|
1213
|
+
if (rule == null) {
|
|
1214
|
+
RetenoNotificationGroupingRuleProvider.configure(context, null, null, false);
|
|
1215
|
+
promise.resolve(true);
|
|
1216
|
+
return;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
boolean payloadKeyIsString = rule.hasKey("payloadKey")
|
|
1220
|
+
&& !rule.isNull("payloadKey")
|
|
1221
|
+
&& rule.getType("payloadKey") == ReadableType.String;
|
|
1222
|
+
boolean groupIdIsString = rule.hasKey("groupId")
|
|
1223
|
+
&& !rule.isNull("groupId")
|
|
1224
|
+
&& rule.getType("groupId") == ReadableType.String;
|
|
1225
|
+
String payloadKey = payloadKeyIsString ? rule.getString("payloadKey").trim() : null;
|
|
1226
|
+
String groupId = groupIdIsString ? rule.getString("groupId").trim() : null;
|
|
1227
|
+
boolean hasPayloadKey = payloadKey != null && !payloadKey.isEmpty();
|
|
1228
|
+
boolean hasGroupId = groupId != null && !groupId.isEmpty();
|
|
1229
|
+
|
|
1230
|
+
if (hasPayloadKey == hasGroupId) {
|
|
1231
|
+
promise.reject(
|
|
1232
|
+
"InvalidArgument",
|
|
1233
|
+
"Invalid argument: provide exactly one non-empty payloadKey or groupId"
|
|
1234
|
+
);
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
boolean showSummaryIsBoolean = rule.hasKey("showSummary")
|
|
1239
|
+
&& !rule.isNull("showSummary")
|
|
1240
|
+
&& rule.getType("showSummary") == ReadableType.Boolean;
|
|
1241
|
+
if (rule.hasKey("showSummary") && !rule.isNull("showSummary") && !showSummaryIsBoolean) {
|
|
1242
|
+
promise.reject("InvalidArgument", "Invalid argument: showSummary must be a boolean");
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
boolean showSummary = showSummaryIsBoolean && rule.getBoolean("showSummary");
|
|
1246
|
+
|
|
1247
|
+
RetenoNotificationGroupingRuleProvider.configure(
|
|
1248
|
+
context,
|
|
1249
|
+
hasPayloadKey ? payloadKey : null,
|
|
1250
|
+
hasGroupId ? groupId : null,
|
|
1251
|
+
showSummary
|
|
1252
|
+
);
|
|
1253
|
+
promise.resolve(true);
|
|
1254
|
+
}
|
|
1209
1255
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
package com.retenosdk;
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
4
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
5
|
+
|
|
6
|
+
abstract class NativeRetenoSdkSpec extends ReactContextBaseJavaModule {
|
|
7
|
+
NativeRetenoSdkSpec(ReactApplicationContext reactContext) {
|
|
8
|
+
super(reactContext);
|
|
9
|
+
}
|
|
10
|
+
}
|