@snowplow/react-native-tracker 1.0.0 → 1.1.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/CHANGELOG +11 -0
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/RNSnowplowTracker.podspec +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java +49 -1
- package/android/src/main/java/com/snowplowanalytics/react/util/ConfigUtil.java +4 -1
- package/android/src/main/java/com/snowplowanalytics/react/util/EventUtil.java +205 -67
- package/android/src/main/java/com/snowplowanalytics/react/util/TrackerVersion.java +1 -1
- package/dist/index.d.ts +122 -1
- package/dist/index.js +117 -9
- package/dist/index.js.map +1 -1
- package/ios/RNSnowplowTracker.h +2 -2
- package/ios/RNSnowplowTracker.m +146 -2
- package/ios/Util/RNConfigUtils.h +2 -2
- package/ios/Util/RNConfigUtils.m +3 -2
- package/ios/Util/RNTrackerVersion.h +2 -2
- package/ios/Util/RNTrackerVersion.m +3 -3
- package/ios/Util/RNUtilities.h +2 -2
- package/ios/Util/RNUtilities.m +2 -2
- package/package.json +16 -15
package/CHANGELOG
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
Version 1.1.0 (2022-02-07)
|
|
2
|
+
--------------------------
|
|
3
|
+
Update mobile tracker dependencies to v3 (#141)
|
|
4
|
+
Add deep link and message notification events (#142)
|
|
5
|
+
Update demo app to show accessing tracker instance from platform native code (#136)
|
|
6
|
+
Fix compilation error for iOS build on ARM macs (#140)
|
|
7
|
+
Fix check for byteLimitGet when reading emitter configuration (#138)
|
|
8
|
+
Fix check for Android version in GitHub Actions (#134)
|
|
9
|
+
Update year in all copyright notices (#148)
|
|
10
|
+
Update dependencies (#150)
|
|
11
|
+
|
|
1
12
|
Version 1.0.0 (2021-08-09)
|
|
2
13
|
--------------------------
|
|
3
14
|
Fix action-gh-release to specific commit (#133)
|
package/LICENSE
CHANGED
|
@@ -187,7 +187,7 @@
|
|
|
187
187
|
same "printed page" as the copyright notice for easier
|
|
188
188
|
identification within third-party archives.
|
|
189
189
|
|
|
190
|
-
Copyright (c) 2020-
|
|
190
|
+
Copyright (c) 2020-2022 Snowplow Analytics Ltd, 2019 DataCamp.
|
|
191
191
|
All rights reserved.
|
|
192
192
|
|
|
193
193
|
Licensed under the Apache License, Version 2.0 (the "License");
|
package/README.md
CHANGED
|
@@ -169,7 +169,7 @@ Feedback and contributions are welcome - if you have identified a bug, please lo
|
|
|
169
169
|
|
|
170
170
|
## Copyright and license
|
|
171
171
|
|
|
172
|
-
The Snowplow React Native Tracker is copyright 2020-
|
|
172
|
+
The Snowplow React Native Tracker is copyright 2020-2022 Snowplow Analytics Ltd, 2019 DataCamp.
|
|
173
173
|
|
|
174
174
|
Licensed under the **[Apache License, Version 2.0][license]** (the "License");
|
|
175
175
|
you may not use this software except in compliance with the License.
|
package/android/build.gradle
CHANGED
|
@@ -48,7 +48,7 @@ dependencies {
|
|
|
48
48
|
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.+'
|
|
49
49
|
|
|
50
50
|
// Required Dependency for the Tracker
|
|
51
|
-
implementation "com.squareup.okhttp3:okhttp:4.9.
|
|
51
|
+
implementation "com.squareup.okhttp3:okhttp:4.9.3"
|
|
52
52
|
implementation "com.facebook.react:react-native:+"
|
|
53
|
-
implementation 'com.snowplowanalytics:snowplow-android-tracker:
|
|
53
|
+
implementation 'com.snowplowanalytics:snowplow-android-tracker:3.+'
|
|
54
54
|
}
|
package/android/src/main/java/com/snowplowanalytics/react/tracker/RNSnowplowTrackerModule.java
CHANGED
|
@@ -18,6 +18,8 @@ import com.snowplowanalytics.snowplow.configuration.SessionConfiguration;
|
|
|
18
18
|
import com.snowplowanalytics.snowplow.configuration.TrackerConfiguration;
|
|
19
19
|
import com.snowplowanalytics.snowplow.configuration.SubjectConfiguration;
|
|
20
20
|
import com.snowplowanalytics.snowplow.configuration.GlobalContextsConfiguration;
|
|
21
|
+
import com.snowplowanalytics.snowplow.event.DeepLinkReceived;
|
|
22
|
+
import com.snowplowanalytics.snowplow.event.MessageNotification;
|
|
21
23
|
import com.snowplowanalytics.snowplow.globalcontexts.GlobalContext;
|
|
22
24
|
import com.snowplowanalytics.snowplow.controller.TrackerController;
|
|
23
25
|
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
|
|
@@ -166,7 +168,7 @@ public class RNSnowplowTrackerModule extends ReactContextBaseJavaModule {
|
|
|
166
168
|
TrackerController trackerController = Snowplow.getTracker(namespace);
|
|
167
169
|
|
|
168
170
|
SelfDescribingJson sdj = EventUtil.createSelfDescribingJson(argmap);
|
|
169
|
-
SelfDescribing event = SelfDescribing
|
|
171
|
+
SelfDescribing event = new SelfDescribing(sdj);
|
|
170
172
|
|
|
171
173
|
List<SelfDescribingJson> evCtxts = EventUtil.createContexts(contexts);
|
|
172
174
|
event.customContexts.addAll(evCtxts);
|
|
@@ -340,6 +342,52 @@ public class RNSnowplowTrackerModule extends ReactContextBaseJavaModule {
|
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
|
|
345
|
+
@ReactMethod
|
|
346
|
+
public void trackDeepLinkReceivedEvent(ReadableMap details,
|
|
347
|
+
Promise promise) {
|
|
348
|
+
try {
|
|
349
|
+
String namespace = details.getString("tracker");
|
|
350
|
+
ReadableMap argmap = details.getMap("eventData");
|
|
351
|
+
ReadableArray contexts = details.getArray("contexts");
|
|
352
|
+
|
|
353
|
+
TrackerController trackerController = Snowplow.getTracker(namespace);
|
|
354
|
+
|
|
355
|
+
DeepLinkReceived event = EventUtil.createDeepLinkReceivedEvent(argmap);
|
|
356
|
+
|
|
357
|
+
List<SelfDescribingJson> evCtxts = EventUtil.createContexts(contexts);
|
|
358
|
+
event.customContexts.addAll(evCtxts);
|
|
359
|
+
|
|
360
|
+
trackerController.track(event);
|
|
361
|
+
promise.resolve(true);
|
|
362
|
+
|
|
363
|
+
} catch(Throwable t) {
|
|
364
|
+
promise.reject("ERROR", t.getMessage());
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
@ReactMethod
|
|
369
|
+
public void trackMessageNotificationEvent(ReadableMap details,
|
|
370
|
+
Promise promise) {
|
|
371
|
+
try {
|
|
372
|
+
String namespace = details.getString("tracker");
|
|
373
|
+
ReadableMap argmap = details.getMap("eventData");
|
|
374
|
+
ReadableArray contexts = details.getArray("contexts");
|
|
375
|
+
|
|
376
|
+
TrackerController trackerController = Snowplow.getTracker(namespace);
|
|
377
|
+
|
|
378
|
+
MessageNotification event = EventUtil.createMessageNotificationEvent(argmap);
|
|
379
|
+
|
|
380
|
+
List<SelfDescribingJson> evCtxts = EventUtil.createContexts(contexts);
|
|
381
|
+
event.customContexts.addAll(evCtxts);
|
|
382
|
+
|
|
383
|
+
trackerController.track(event);
|
|
384
|
+
promise.resolve(true);
|
|
385
|
+
|
|
386
|
+
} catch(Throwable t) {
|
|
387
|
+
promise.reject("ERROR", t.getMessage());
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
343
391
|
@ReactMethod
|
|
344
392
|
public void removeGlobalContexts(ReadableMap details,
|
|
345
393
|
Promise promise) {
|
|
@@ -158,6 +158,9 @@ public class ConfigUtil {
|
|
|
158
158
|
if (trackerConfig.hasKey("diagnosticAutotracking")) {
|
|
159
159
|
trackerConfiguration.diagnosticAutotracking(trackerConfig.getBoolean("diagnosticAutotracking"));
|
|
160
160
|
}
|
|
161
|
+
if (trackerConfig.hasKey("deepLinkContext")) {
|
|
162
|
+
trackerConfiguration.deepLinkContext(trackerConfig.getBoolean("deepLinkContext"));
|
|
163
|
+
}
|
|
161
164
|
|
|
162
165
|
return trackerConfiguration;
|
|
163
166
|
}
|
|
@@ -193,7 +196,7 @@ public class ConfigUtil {
|
|
|
193
196
|
int byteLimitPost = (int) emitterConfig.getDouble("byteLimitPost");
|
|
194
197
|
emitterConfiguration.byteLimitPost(byteLimitPost);
|
|
195
198
|
}
|
|
196
|
-
if (emitterConfig.hasKey("
|
|
199
|
+
if (emitterConfig.hasKey("byteLimitGet")) {
|
|
197
200
|
int byteLimitGet = (int) emitterConfig.getDouble("byteLimitGet");
|
|
198
201
|
emitterConfiguration.byteLimitGet(byteLimitGet);
|
|
199
202
|
}
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
package com.snowplowanalytics.react.util;
|
|
2
2
|
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
3
5
|
import com.facebook.react.bridge.ReadableMap;
|
|
4
6
|
import com.facebook.react.bridge.ReadableArray;
|
|
5
|
-
import com.snowplowanalytics.snowplow.event.
|
|
7
|
+
import com.snowplowanalytics.snowplow.event.DeepLinkReceived;
|
|
8
|
+
import com.snowplowanalytics.snowplow.event.MessageNotification;
|
|
9
|
+
import com.snowplowanalytics.snowplow.event.MessageNotificationAttachment;
|
|
10
|
+
import com.snowplowanalytics.snowplow.event.MessageNotificationTrigger;
|
|
6
11
|
import com.snowplowanalytics.snowplow.event.Structured;
|
|
7
12
|
import com.snowplowanalytics.snowplow.payload.SelfDescribingJson;
|
|
8
13
|
import com.snowplowanalytics.snowplow.event.ScreenView;
|
|
@@ -15,6 +20,7 @@ import com.snowplowanalytics.snowplow.event.EcommerceTransaction;
|
|
|
15
20
|
|
|
16
21
|
import java.util.ArrayList;
|
|
17
22
|
import java.util.List;
|
|
23
|
+
import java.util.Objects;
|
|
18
24
|
import java.util.UUID;
|
|
19
25
|
|
|
20
26
|
public class EventUtil {
|
|
@@ -37,165 +43,297 @@ public class EventUtil {
|
|
|
37
43
|
}
|
|
38
44
|
|
|
39
45
|
public static Structured createStructuredEvent(ReadableMap argmap) {
|
|
40
|
-
Structured
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
Structured event = new Structured(
|
|
47
|
+
Objects.requireNonNull(argmap.getString("category"), "category can't be null"),
|
|
48
|
+
Objects.requireNonNull(argmap.getString("action"), "action can't be null")
|
|
49
|
+
);
|
|
43
50
|
|
|
44
51
|
if (argmap.hasKey("label")) {
|
|
45
|
-
|
|
52
|
+
event.label(argmap.getString("label"));
|
|
46
53
|
}
|
|
47
54
|
if (argmap.hasKey("property")) {
|
|
48
|
-
|
|
55
|
+
event.property(argmap.getString("property"));
|
|
49
56
|
}
|
|
50
57
|
// React Native forces primitive double type - so null "value" parameter is handled by not setting at all
|
|
51
58
|
if (argmap.hasKey("value") && !argmap.isNull("value")) {
|
|
52
|
-
|
|
59
|
+
event.value(argmap.getDouble("value"));
|
|
53
60
|
}
|
|
54
61
|
|
|
55
|
-
return
|
|
62
|
+
return event;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
public static ScreenView createScreenViewEvent(ReadableMap argmap) {
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
@NonNull String name = Objects.requireNonNull(argmap.getString("name"), "name can't be null");
|
|
67
|
+
ScreenView event = (
|
|
68
|
+
argmap.hasKey("id") ?
|
|
69
|
+
new ScreenView(name, UUID.fromString(argmap.getString("id"))) :
|
|
70
|
+
new ScreenView(name)
|
|
71
|
+
);
|
|
61
72
|
|
|
62
|
-
if (argmap.hasKey("id")) {
|
|
63
|
-
UUID idUUID = UUID.fromString(argmap.getString("id"));
|
|
64
|
-
eventBuilder.id(idUUID.toString());
|
|
65
|
-
}
|
|
66
73
|
if (argmap.hasKey("type")) {
|
|
67
|
-
|
|
74
|
+
event.type(argmap.getString("type"));
|
|
68
75
|
}
|
|
69
76
|
if (argmap.hasKey("previousName")) {
|
|
70
|
-
|
|
77
|
+
event.previousName(argmap.getString("previousName"));
|
|
71
78
|
}
|
|
72
79
|
if (argmap.hasKey("previousType")) {
|
|
73
|
-
|
|
80
|
+
event.previousType(argmap.getString("previousType"));
|
|
74
81
|
}
|
|
75
82
|
if (argmap.hasKey("previousId")) {
|
|
76
|
-
|
|
83
|
+
event.previousId(argmap.getString("previousId"));
|
|
77
84
|
}
|
|
78
85
|
if (argmap.hasKey("transitionType")) {
|
|
79
|
-
|
|
86
|
+
event.transitionType(argmap.getString("transitionType"));
|
|
80
87
|
}
|
|
81
88
|
|
|
82
|
-
return
|
|
89
|
+
return event;
|
|
83
90
|
}
|
|
84
91
|
|
|
85
92
|
public static PageView createPageViewEvent(ReadableMap argmap) {
|
|
86
|
-
PageView
|
|
87
|
-
|
|
93
|
+
PageView event = new PageView(
|
|
94
|
+
Objects.requireNonNull(argmap.getString("pageUrl"), "pageUrl can't be null")
|
|
95
|
+
);
|
|
88
96
|
|
|
89
97
|
if (argmap.hasKey("pageTitle")) {
|
|
90
|
-
|
|
98
|
+
event.pageTitle(argmap.getString("pageTitle"));
|
|
91
99
|
}
|
|
92
100
|
if (argmap.hasKey("referrer")) {
|
|
93
|
-
|
|
101
|
+
event.referrer(argmap.getString("referrer"));
|
|
94
102
|
}
|
|
95
103
|
|
|
96
|
-
return
|
|
104
|
+
return event;
|
|
97
105
|
}
|
|
98
106
|
|
|
99
107
|
public static Timing createTimingEvent(ReadableMap argmap) {
|
|
100
|
-
Timing
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
108
|
+
Timing event = new Timing(
|
|
109
|
+
Objects.requireNonNull(argmap.getString("category"), "category can't be null"),
|
|
110
|
+
Objects.requireNonNull(argmap.getString("variable"), "variable can't be null"),
|
|
111
|
+
argmap.getInt("timing")
|
|
112
|
+
);
|
|
104
113
|
|
|
105
114
|
if (argmap.hasKey("label")) {
|
|
106
|
-
|
|
115
|
+
event.label(argmap.getString("label"));
|
|
107
116
|
}
|
|
108
117
|
|
|
109
|
-
return
|
|
118
|
+
return event;
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
public static ConsentGranted createConsentGrantedEvent(ReadableMap argmap) {
|
|
113
|
-
ConsentGranted
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
ConsentGranted event = new ConsentGranted(
|
|
123
|
+
Objects.requireNonNull(argmap.getString("expiry"), "expiry can't be null"),
|
|
124
|
+
Objects.requireNonNull(argmap.getString("documentId"), "documentId can't be null"),
|
|
125
|
+
Objects.requireNonNull(argmap.getString("version"), "version can't be null")
|
|
126
|
+
);
|
|
117
127
|
|
|
118
128
|
if (argmap.hasKey("name")) {
|
|
119
|
-
|
|
129
|
+
event.documentName(argmap.getString("name"));
|
|
120
130
|
}
|
|
121
131
|
if (argmap.hasKey("documentDescription")) {
|
|
122
|
-
|
|
132
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
123
133
|
}
|
|
124
134
|
|
|
125
|
-
return
|
|
135
|
+
return event;
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
public static ConsentWithdrawn createConsentWithdrawnEvent(ReadableMap argmap) {
|
|
129
|
-
ConsentWithdrawn
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
ConsentWithdrawn event = new ConsentWithdrawn(
|
|
140
|
+
argmap.getBoolean("all"),
|
|
141
|
+
Objects.requireNonNull(argmap.getString("documentId"), "documentId can't be null"),
|
|
142
|
+
Objects.requireNonNull(argmap.getString("version"), "version can't be null")
|
|
143
|
+
);
|
|
133
144
|
|
|
134
145
|
if (argmap.hasKey("name")) {
|
|
135
|
-
|
|
146
|
+
event.documentName(argmap.getString("name"));
|
|
136
147
|
}
|
|
137
148
|
if (argmap.hasKey("documentDescription")) {
|
|
138
|
-
|
|
149
|
+
event.documentDescription(argmap.getString("documentDescription"));
|
|
139
150
|
}
|
|
140
151
|
|
|
141
|
-
return
|
|
152
|
+
return event;
|
|
142
153
|
}
|
|
143
154
|
|
|
144
155
|
public static List<EcommerceTransactionItem> createEcommerceTransactionItems(ReadableArray items) {
|
|
145
156
|
List<EcommerceTransactionItem> ecomItems = new ArrayList<>();
|
|
146
157
|
for (int i = 0; i < items.size(); i++) {
|
|
147
158
|
ReadableMap argItem = items.getMap(i);
|
|
148
|
-
EcommerceTransactionItem
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
159
|
+
EcommerceTransactionItem item = new EcommerceTransactionItem(
|
|
160
|
+
Objects.requireNonNull(argItem.getString("sku"), "sku can't be null"),
|
|
161
|
+
argItem.getDouble("price"),
|
|
162
|
+
argItem.getInt("quantity")
|
|
163
|
+
);
|
|
152
164
|
|
|
153
165
|
if (argItem.hasKey("name")) {
|
|
154
|
-
|
|
166
|
+
item.name(argItem.getString("name"));
|
|
155
167
|
}
|
|
156
168
|
if (argItem.hasKey("category")) {
|
|
157
|
-
|
|
169
|
+
item.category(argItem.getString("category"));
|
|
158
170
|
}
|
|
159
171
|
if (argItem.hasKey("currency")) {
|
|
160
|
-
|
|
172
|
+
item.currency(argItem.getString("currency"));
|
|
161
173
|
}
|
|
162
174
|
|
|
163
|
-
ecomItems.add(
|
|
175
|
+
ecomItems.add(item);
|
|
164
176
|
}
|
|
165
177
|
|
|
166
178
|
return ecomItems;
|
|
167
|
-
}
|
|
179
|
+
}
|
|
168
180
|
|
|
169
181
|
public static EcommerceTransaction createEcommerceTransactionEvent(ReadableMap argmap) {
|
|
170
|
-
List<EcommerceTransactionItem> ecomItems = createEcommerceTransactionItems(
|
|
182
|
+
List<EcommerceTransactionItem> ecomItems = createEcommerceTransactionItems(
|
|
183
|
+
Objects.requireNonNull(argmap.getArray("items"), "items can't be null")
|
|
184
|
+
);
|
|
171
185
|
|
|
172
|
-
EcommerceTransaction
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
186
|
+
EcommerceTransaction event = new EcommerceTransaction(
|
|
187
|
+
Objects.requireNonNull(argmap.getString("orderId"), "orderId can't be null"),
|
|
188
|
+
argmap.getDouble("totalValue"),
|
|
189
|
+
ecomItems
|
|
190
|
+
);
|
|
176
191
|
|
|
177
192
|
if (argmap.hasKey("affiliation")) {
|
|
178
|
-
|
|
193
|
+
event.affiliation(argmap.getString("affiliation"));
|
|
179
194
|
}
|
|
180
195
|
if (argmap.hasKey("taxValue")) {
|
|
181
|
-
|
|
196
|
+
event.taxValue(argmap.getDouble("taxValue"));
|
|
182
197
|
}
|
|
183
198
|
if (argmap.hasKey("shipping")) {
|
|
184
|
-
|
|
199
|
+
event.shipping(argmap.getDouble("shipping"));
|
|
185
200
|
}
|
|
186
201
|
if (argmap.hasKey("city")) {
|
|
187
|
-
|
|
202
|
+
event.city(argmap.getString("city"));
|
|
188
203
|
}
|
|
189
204
|
if (argmap.hasKey("state")) {
|
|
190
|
-
|
|
205
|
+
event.state(argmap.getString("state"));
|
|
191
206
|
}
|
|
192
207
|
if (argmap.hasKey("country")) {
|
|
193
|
-
|
|
208
|
+
event.country(argmap.getString("country"));
|
|
194
209
|
}
|
|
195
210
|
if (argmap.hasKey("currency")) {
|
|
196
|
-
|
|
211
|
+
event.currency(argmap.getString("currency"));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return event;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
public static DeepLinkReceived createDeepLinkReceivedEvent(ReadableMap argmap) {
|
|
218
|
+
DeepLinkReceived event = new DeepLinkReceived(
|
|
219
|
+
Objects.requireNonNull(argmap.getString("url"), "url can't be null")
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
if (argmap.hasKey("referrer")) {
|
|
223
|
+
event.referrer(argmap.getString("referrer"));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return event;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
public static List<MessageNotificationAttachment> createMessageNotificationAttachments(ReadableArray items) {
|
|
230
|
+
List<MessageNotificationAttachment> attachments = new ArrayList<>();
|
|
231
|
+
for (int i = 0; i < items.size(); i++) {
|
|
232
|
+
ReadableMap argItem = items.getMap(i);
|
|
233
|
+
MessageNotificationAttachment attachment = new MessageNotificationAttachment(
|
|
234
|
+
Objects.requireNonNull(argItem.getString("identifier"), "identifier can't be null"),
|
|
235
|
+
Objects.requireNonNull(argItem.getString("type"), "type can't be null"),
|
|
236
|
+
Objects.requireNonNull(argItem.getString("url"), "url can't be null")
|
|
237
|
+
);
|
|
238
|
+
attachments.add(attachment);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return attachments;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
public static List<String> createStrings(ReadableArray items) {
|
|
245
|
+
List<String> results = new ArrayList<>();
|
|
246
|
+
for (int i = 0; i < items.size(); i++) {
|
|
247
|
+
results.add(items.getString(i));
|
|
248
|
+
}
|
|
249
|
+
return results;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static MessageNotification createMessageNotificationEvent(ReadableMap argmap) {
|
|
253
|
+
|
|
254
|
+
MessageNotificationTrigger trigger;
|
|
255
|
+
switch (Objects.requireNonNull(argmap.getString("trigger"), "trigger can't be null")) {
|
|
256
|
+
case "push":
|
|
257
|
+
trigger = MessageNotificationTrigger.push;
|
|
258
|
+
break;
|
|
259
|
+
case "location":
|
|
260
|
+
trigger = MessageNotificationTrigger.location;
|
|
261
|
+
break;
|
|
262
|
+
case "calendar":
|
|
263
|
+
trigger = MessageNotificationTrigger.calendar;
|
|
264
|
+
break;
|
|
265
|
+
case "timeInterval":
|
|
266
|
+
trigger = MessageNotificationTrigger.timeInterval;
|
|
267
|
+
break;
|
|
268
|
+
default:
|
|
269
|
+
trigger = MessageNotificationTrigger.other;
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
MessageNotification event = new MessageNotification(
|
|
274
|
+
Objects.requireNonNull(argmap.getString("title"), "title can't be null"),
|
|
275
|
+
Objects.requireNonNull(argmap.getString("body"), "body can't be null"),
|
|
276
|
+
trigger
|
|
277
|
+
);
|
|
278
|
+
|
|
279
|
+
if (argmap.hasKey("action")) {
|
|
280
|
+
event.action(argmap.getString("action"));
|
|
281
|
+
}
|
|
282
|
+
if (argmap.hasKey("attachments")) {
|
|
283
|
+
ReadableArray attachments = argmap.getArray("attachments");
|
|
284
|
+
if (attachments != null) {
|
|
285
|
+
event.attachments(createMessageNotificationAttachments(attachments));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (argmap.hasKey("bodyLocArgs")) {
|
|
289
|
+
ReadableArray bodyLocArgs = argmap.getArray("bodyLocArgs");
|
|
290
|
+
if (bodyLocArgs != null) {
|
|
291
|
+
event.bodyLocArgs(createStrings(bodyLocArgs));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (argmap.hasKey("bodyLocKey")) {
|
|
295
|
+
event.bodyLocKey(argmap.getString("bodyLocKey"));
|
|
296
|
+
}
|
|
297
|
+
if (argmap.hasKey("category")) {
|
|
298
|
+
event.category(argmap.getString("category"));
|
|
299
|
+
}
|
|
300
|
+
if (argmap.hasKey("contentAvailable")) {
|
|
301
|
+
event.contentAvailable(argmap.getBoolean("contentAvailable"));
|
|
302
|
+
}
|
|
303
|
+
if (argmap.hasKey("group")) {
|
|
304
|
+
event.group(argmap.getString("group"));
|
|
305
|
+
}
|
|
306
|
+
if (argmap.hasKey("icon")) {
|
|
307
|
+
event.icon(argmap.getString("icon"));
|
|
308
|
+
}
|
|
309
|
+
if (argmap.hasKey("notificationCount")) {
|
|
310
|
+
event.notificationCount(argmap.getInt("notificationCount"));
|
|
311
|
+
}
|
|
312
|
+
if (argmap.hasKey("notificationTimestamp")) {
|
|
313
|
+
event.notificationTimestamp(argmap.getString("notificationTimestamp"));
|
|
314
|
+
}
|
|
315
|
+
if (argmap.hasKey("sound")) {
|
|
316
|
+
event.sound(argmap.getString("sound"));
|
|
317
|
+
}
|
|
318
|
+
if (argmap.hasKey("subtitle")) {
|
|
319
|
+
event.subtitle(argmap.getString("subtitle"));
|
|
320
|
+
}
|
|
321
|
+
if (argmap.hasKey("tag")) {
|
|
322
|
+
event.tag(argmap.getString("tag"));
|
|
323
|
+
}
|
|
324
|
+
if (argmap.hasKey("threadIdentifier")) {
|
|
325
|
+
event.threadIdentifier(argmap.getString("threadIdentifier"));
|
|
326
|
+
}
|
|
327
|
+
if (argmap.hasKey("titleLocArgs")) {
|
|
328
|
+
ReadableArray titleLocArgs = argmap.getArray("titleLocArgs");
|
|
329
|
+
if (titleLocArgs != null) {
|
|
330
|
+
event.titleLocArgs(createStrings(titleLocArgs));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (argmap.hasKey("titleLocKey")) {
|
|
334
|
+
event.titleLocKey(argmap.getString("titleLocKey"));
|
|
197
335
|
}
|
|
198
336
|
|
|
199
|
-
return
|
|
337
|
+
return event;
|
|
200
338
|
}
|
|
201
339
|
}
|