expo-notifications 0.28.14 → 0.28.16
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.md +12 -0
- package/android/build.gradle +2 -2
- package/android/src/main/java/expo/modules/notifications/Utils.kt +89 -0
- package/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java +29 -32
- package/build/getAllScheduledNotificationsAsync.d.ts.map +1 -1
- package/build/getAllScheduledNotificationsAsync.js +2 -1
- package/build/getAllScheduledNotificationsAsync.js.map +1 -1
- package/build/getPresentedNotificationsAsync.d.ts.map +1 -1
- package/build/getPresentedNotificationsAsync.js +2 -1
- package/build/getPresentedNotificationsAsync.js.map +1 -1
- package/build/utils/mapNotificationResponse.d.ts +40 -7
- package/build/utils/mapNotificationResponse.d.ts.map +1 -1
- package/build/utils/mapNotificationResponse.js +31 -6
- package/build/utils/mapNotificationResponse.js.map +1 -1
- package/package.json +2 -2
- package/src/getAllScheduledNotificationsAsync.ts +4 -1
- package/src/getPresentedNotificationsAsync.ts +4 -1
- package/src/utils/mapNotificationResponse.ts +39 -9
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,18 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.28.16 — 2024-08-21
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- [Android] Fix content.data in scheduled notifications surfaced to JS. ([#31048](https://github.com/expo/expo/pull/31048) by [@douglowder](https://github.com/douglowder))
|
|
18
|
+
|
|
19
|
+
## 0.28.15 — 2024-08-05
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- [Android] Eliminate unsupported types when processing notification intents from onCreate/onNewIntent. ([#30750](https://github.com/expo/expo/pull/30750) by [@douglowder](https://github.com/douglowder))
|
|
24
|
+
|
|
13
25
|
## 0.28.14 — 2024-07-30
|
|
14
26
|
|
|
15
27
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
apply plugin: 'com.android.library'
|
|
2
2
|
|
|
3
3
|
group = 'host.exp.exponent'
|
|
4
|
-
version = '0.28.
|
|
4
|
+
version = '0.28.16'
|
|
5
5
|
|
|
6
6
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
7
7
|
apply from: expoModulesCorePlugin
|
|
@@ -14,7 +14,7 @@ android {
|
|
|
14
14
|
namespace "expo.modules.notifications"
|
|
15
15
|
defaultConfig {
|
|
16
16
|
versionCode 21
|
|
17
|
-
versionName '0.28.
|
|
17
|
+
versionName '0.28.16'
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
buildFeatures {
|
|
@@ -3,8 +3,13 @@ package expo.modules.notifications
|
|
|
3
3
|
import android.os.Bundle
|
|
4
4
|
import android.os.Handler
|
|
5
5
|
import android.os.ResultReceiver
|
|
6
|
+
import expo.modules.kotlin.types.JSTypeConverter
|
|
7
|
+
import org.json.JSONArray
|
|
8
|
+
import org.json.JSONException
|
|
9
|
+
import org.json.JSONObject
|
|
6
10
|
|
|
7
11
|
typealias ResultReceiverBody = (resultCode: Int, resultData: Bundle?) -> Unit
|
|
12
|
+
typealias BundleConversionTester = (bundle: Bundle) -> Boolean
|
|
8
13
|
|
|
9
14
|
internal fun createDefaultResultReceiver(
|
|
10
15
|
handler: Handler?,
|
|
@@ -17,3 +22,87 @@ internal fun createDefaultResultReceiver(
|
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Given an input bundle, creates a new bundle with non-convertible objects removed
|
|
28
|
+
*/
|
|
29
|
+
internal fun filteredBundleForJSTypeConverter(bundle: Bundle): Bundle {
|
|
30
|
+
return filteredBundleForJSTypeConverter(bundle, isBundleConvertibleToJSValue)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
internal fun filteredBundleForJSTypeConverter(bundle: Bundle, testBundle: BundleConversionTester): Bundle {
|
|
34
|
+
return when (testBundle(bundle)) {
|
|
35
|
+
true -> bundle
|
|
36
|
+
else -> {
|
|
37
|
+
// Store keys whose values are convertible
|
|
38
|
+
val goodKeys: MutableSet<String> = mutableSetOf()
|
|
39
|
+
// Do first pass to filter any values that are bundles
|
|
40
|
+
bundle.keySet().forEach { key: String ->
|
|
41
|
+
val value = bundle[key]
|
|
42
|
+
if (value is Bundle) {
|
|
43
|
+
bundle.putBundle(key, filteredBundleForJSTypeConverter(value, testBundle))
|
|
44
|
+
goodKeys.add(key)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
// Second pass: create a bundle with just the value for that key, and see if it converts
|
|
48
|
+
// There is no generic put() method for bundles, so we putAll() and then remove values
|
|
49
|
+
// other than the one we are testing
|
|
50
|
+
bundle.keySet().forEach { key: String ->
|
|
51
|
+
if (!goodKeys.contains(key)) {
|
|
52
|
+
val test = Bundle()
|
|
53
|
+
test.putAll(bundle)
|
|
54
|
+
bundle.keySet().forEach { otherKey: String ->
|
|
55
|
+
if (!otherKey.equals(key)) {
|
|
56
|
+
test.remove(otherKey)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (testBundle(test)) {
|
|
60
|
+
goodKeys.add(key)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Now create a new bundle, remove keys that are not good, and return
|
|
65
|
+
val result = Bundle()
|
|
66
|
+
result.putAll(bundle)
|
|
67
|
+
bundle.keySet().forEach { key: String ->
|
|
68
|
+
if (!goodKeys.contains(key)) {
|
|
69
|
+
result.remove(key)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
result
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
internal val isBundleConvertibleToJSValue: BundleConversionTester = { bundle: Bundle ->
|
|
78
|
+
try {
|
|
79
|
+
JSTypeConverter.convertToJSValue(bundle)
|
|
80
|
+
true
|
|
81
|
+
} catch (e: Throwable) {
|
|
82
|
+
false
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Returns true if the argument is a valid JSON string, false otherwise
|
|
88
|
+
*/
|
|
89
|
+
internal fun isValidJSONString(test: Any?): Boolean {
|
|
90
|
+
when (test is String) {
|
|
91
|
+
true -> {
|
|
92
|
+
try {
|
|
93
|
+
JSONObject(test as String)
|
|
94
|
+
return true
|
|
95
|
+
} catch (objectEx: JSONException) {
|
|
96
|
+
try {
|
|
97
|
+
JSONArray(test as String)
|
|
98
|
+
return true
|
|
99
|
+
} catch (arrayEx: JSONException) {
|
|
100
|
+
return false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else -> {
|
|
105
|
+
return false
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
package/android/src/main/java/expo/modules/notifications/notifications/NotificationSerializer.java
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
package expo.modules.notifications.notifications;
|
|
2
2
|
|
|
3
|
+
import static expo.modules.notifications.UtilsKt.filteredBundleForJSTypeConverter;
|
|
4
|
+
import static expo.modules.notifications.UtilsKt.isValidJSONString;
|
|
5
|
+
|
|
3
6
|
import android.os.Build;
|
|
4
7
|
import android.os.Bundle;
|
|
5
8
|
|
|
@@ -9,7 +12,6 @@ import com.google.firebase.messaging.RemoteMessage;
|
|
|
9
12
|
|
|
10
13
|
import org.jetbrains.annotations.NotNull;
|
|
11
14
|
import org.json.JSONArray;
|
|
12
|
-
import org.json.JSONException;
|
|
13
15
|
import org.json.JSONObject;
|
|
14
16
|
import expo.modules.core.arguments.MapArguments;
|
|
15
17
|
|
|
@@ -21,6 +23,7 @@ import java.util.Map;
|
|
|
21
23
|
import java.util.Set;
|
|
22
24
|
|
|
23
25
|
import expo.modules.notifications.notifications.interfaces.NotificationTrigger;
|
|
26
|
+
import expo.modules.notifications.notifications.interfaces.SchedulableNotificationTrigger;
|
|
24
27
|
import expo.modules.notifications.notifications.model.Notification;
|
|
25
28
|
import expo.modules.notifications.notifications.model.NotificationContent;
|
|
26
29
|
import expo.modules.notifications.notifications.model.NotificationRequest;
|
|
@@ -59,19 +62,26 @@ public class NotificationSerializer {
|
|
|
59
62
|
Bundle content = toBundle(request.getContent());
|
|
60
63
|
Bundle existingContentData = content.getBundle("data");
|
|
61
64
|
if (existingContentData == null) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
65
|
+
if(request.getTrigger() instanceof FirebaseNotificationTrigger trigger) {
|
|
66
|
+
RemoteMessage message = trigger.getRemoteMessage();
|
|
67
|
+
RemoteMessage.Notification notification = message.getNotification();
|
|
68
|
+
Map<String, String> data = message.getData();
|
|
69
|
+
String dataBody = data.get("body");
|
|
70
|
+
String notificationBody = notification != null ? notification.getBody() : null;
|
|
71
|
+
if (isValidJSONString(dataBody) && notificationBody != null && notificationBody.equals(data.get("message"))) {
|
|
72
|
+
// Expo sends notification.body as data.message, and JSON stringifies data.body
|
|
73
|
+
content.putString("dataString", dataBody);
|
|
74
|
+
} else {
|
|
75
|
+
// The message was sent directly from Firebase or some other service,
|
|
76
|
+
// and we copy the data as is
|
|
77
|
+
content.putBundle("data", toBundle(data));
|
|
78
|
+
}
|
|
79
|
+
} else if(request.getTrigger() instanceof SchedulableNotificationTrigger) {
|
|
80
|
+
JSONObject body = request.getContent().getBody();
|
|
81
|
+
if (body != null) {
|
|
82
|
+
// Expo sends notification.body as data.message, and JSON stringifies data.body
|
|
83
|
+
content.putString("dataString", body.toString());
|
|
84
|
+
}
|
|
75
85
|
}
|
|
76
86
|
}
|
|
77
87
|
serializedRequest.putBundle("content", content);
|
|
@@ -226,17 +236,17 @@ public class NotificationSerializer {
|
|
|
226
236
|
Bundle serializedContent = new Bundle();
|
|
227
237
|
serializedContent.putString("title", extras.getString("title"));
|
|
228
238
|
String body = extras.getString("body");
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
// If projectId is set in the bundle, and the body is a JSON string,
|
|
239
|
+
if (isValidJSONString(body) ) {
|
|
240
|
+
// If the body is a JSON string,
|
|
232
241
|
// the notification was sent by the Expo notification service,
|
|
233
242
|
// so we do the expected remapping of fields
|
|
234
243
|
serializedContent.putString("dataString", body);
|
|
235
244
|
serializedContent.putString("body", extras.getString("message"));
|
|
236
245
|
} else {
|
|
237
246
|
// The notification came directly from Firebase or some other service,
|
|
238
|
-
// so we copy the data as is from the extras bundle
|
|
239
|
-
|
|
247
|
+
// so we copy the data as is from the extras bundle, after
|
|
248
|
+
// ensuring it can be converted for emitting to JS
|
|
249
|
+
serializedContent.putBundle("data", filteredBundleForJSTypeConverter(extras));
|
|
240
250
|
}
|
|
241
251
|
|
|
242
252
|
Bundle serializedTrigger = new Bundle();
|
|
@@ -259,17 +269,4 @@ public class NotificationSerializer {
|
|
|
259
269
|
return serializedResponse;
|
|
260
270
|
}
|
|
261
271
|
|
|
262
|
-
public static boolean isValidJSONString(String test) {
|
|
263
|
-
try {
|
|
264
|
-
new JSONObject(test);
|
|
265
|
-
} catch (JSONException objectEx) {
|
|
266
|
-
try {
|
|
267
|
-
new JSONArray(test);
|
|
268
|
-
} catch (JSONException arrayEx) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
return true;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
272
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllScheduledNotificationsAsync.d.ts","sourceRoot":"","sources":["../src/getAllScheduledNotificationsAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"getAllScheduledNotificationsAsync.d.ts","sourceRoot":"","sources":["../src/getAllScheduledNotificationsAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAG5D;;;;GAIG;AACH,wBAA8B,iCAAiC,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAQhG"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UnavailabilityError } from 'expo-modules-core';
|
|
2
2
|
import NotificationScheduler from './NotificationScheduler';
|
|
3
|
+
import { mapNotificationRequest } from './utils/mapNotificationResponse';
|
|
3
4
|
/**
|
|
4
5
|
* Fetches information about all scheduled notifications.
|
|
5
6
|
* @return Returns a Promise resolving to an array of objects conforming to the [`Notification`](#notification) interface.
|
|
@@ -9,6 +10,6 @@ export default async function getAllScheduledNotificationsAsync() {
|
|
|
9
10
|
if (!NotificationScheduler.getAllScheduledNotificationsAsync) {
|
|
10
11
|
throw new UnavailabilityError('Notifications', 'getAllScheduledNotificationsAsync');
|
|
11
12
|
}
|
|
12
|
-
return await NotificationScheduler.getAllScheduledNotificationsAsync();
|
|
13
|
+
return (await NotificationScheduler.getAllScheduledNotificationsAsync()).map((request) => mapNotificationRequest(request));
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=getAllScheduledNotificationsAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getAllScheduledNotificationsAsync.js","sourceRoot":"","sources":["../src/getAllScheduledNotificationsAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"getAllScheduledNotificationsAsync.js","sourceRoot":"","sources":["../src/getAllScheduledNotificationsAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,qBAAqB,MAAM,yBAAyB,CAAC;AAE5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AAEzE;;;;GAIG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,iCAAiC;IAC7D,IAAI,CAAC,qBAAqB,CAAC,iCAAiC,EAAE;QAC5D,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,mCAAmC,CAAC,CAAC;KACrF;IAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,iCAAiC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CACvF,sBAAsB,CAAC,OAAO,CAAC,CAChC,CAAC;AACJ,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport { NotificationRequest } from './Notifications.types';\nimport { mapNotificationRequest } from './utils/mapNotificationResponse';\n\n/**\n * Fetches information about all scheduled notifications.\n * @return Returns a Promise resolving to an array of objects conforming to the [`Notification`](#notification) interface.\n * @header schedule\n */\nexport default async function getAllScheduledNotificationsAsync(): Promise<NotificationRequest[]> {\n if (!NotificationScheduler.getAllScheduledNotificationsAsync) {\n throw new UnavailabilityError('Notifications', 'getAllScheduledNotificationsAsync');\n }\n\n return (await NotificationScheduler.getAllScheduledNotificationsAsync()).map((request) =>\n mapNotificationRequest(request)\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPresentedNotificationsAsync.d.ts","sourceRoot":"","sources":["../src/getPresentedNotificationsAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"getPresentedNotificationsAsync.d.ts","sourceRoot":"","sources":["../src/getPresentedNotificationsAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD;;;;;GAKG;AACH,wBAA8B,8BAA8B,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAQtF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { UnavailabilityError } from 'expo-modules-core';
|
|
2
2
|
import NotificationPresenter from './NotificationPresenterModule';
|
|
3
|
+
import { mapNotification } from './utils/mapNotificationResponse';
|
|
3
4
|
/**
|
|
4
5
|
* Fetches information about all notifications present in the notification tray (Notification Center).
|
|
5
6
|
* > This method is not supported on Android below 6.0 (API level 23) – on these devices it will resolve to an empty array.
|
|
@@ -10,6 +11,6 @@ export default async function getPresentedNotificationsAsync() {
|
|
|
10
11
|
if (!NotificationPresenter.getPresentedNotificationsAsync) {
|
|
11
12
|
throw new UnavailabilityError('Notifications', 'getPresentedNotificationsAsync');
|
|
12
13
|
}
|
|
13
|
-
return await NotificationPresenter.getPresentedNotificationsAsync();
|
|
14
|
+
return (await NotificationPresenter.getPresentedNotificationsAsync()).map((notification) => mapNotification(notification));
|
|
14
15
|
}
|
|
15
16
|
//# sourceMappingURL=getPresentedNotificationsAsync.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPresentedNotificationsAsync.js","sourceRoot":"","sources":["../src/getPresentedNotificationsAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"getPresentedNotificationsAsync.js","sourceRoot":"","sources":["../src/getPresentedNotificationsAsync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,qBAAqB,MAAM,+BAA+B,CAAC;AAElE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,8BAA8B;IAC1D,IAAI,CAAC,qBAAqB,CAAC,8BAA8B,EAAE;QACzD,MAAM,IAAI,mBAAmB,CAAC,eAAe,EAAE,gCAAgC,CAAC,CAAC;KAClF;IAED,OAAO,CAAC,MAAM,qBAAqB,CAAC,8BAA8B,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,YAAY,EAAE,EAAE,CACzF,eAAe,CAAC,YAAY,CAAC,CAC9B,CAAC;AACJ,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport NotificationPresenter from './NotificationPresenterModule';\nimport { Notification } from './Notifications.types';\nimport { mapNotification } from './utils/mapNotificationResponse';\n\n/**\n * Fetches information about all notifications present in the notification tray (Notification Center).\n * > This method is not supported on Android below 6.0 (API level 23) – on these devices it will resolve to an empty array.\n * @return A Promise which resolves with a list of notifications ([`Notification`](#notification)) currently present in the notification tray (Notification Center).\n * @header dismiss\n */\nexport default async function getPresentedNotificationsAsync(): Promise<Notification[]> {\n if (!NotificationPresenter.getPresentedNotificationsAsync) {\n throw new UnavailabilityError('Notifications', 'getPresentedNotificationsAsync');\n }\n\n return (await NotificationPresenter.getPresentedNotificationsAsync()).map((notification) =>\n mapNotification(notification)\n );\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Notification, NotificationResponse } from '../Notifications.types';
|
|
1
|
+
import { Notification, NotificationContent, NotificationRequest, NotificationResponse } from '../Notifications.types';
|
|
2
2
|
/**
|
|
3
3
|
* @hidden
|
|
4
4
|
*
|
|
@@ -10,12 +10,15 @@ import { Notification, NotificationResponse } from '../Notifications.types';
|
|
|
10
10
|
* @returns the mapped response.
|
|
11
11
|
*/
|
|
12
12
|
export declare const mapNotificationResponse: (response: NotificationResponse) => {
|
|
13
|
-
notification:
|
|
13
|
+
notification: {
|
|
14
14
|
request: {
|
|
15
|
-
content: {
|
|
16
|
-
dataString?: string;
|
|
15
|
+
content: NotificationContent & {
|
|
16
|
+
dataString?: string | undefined;
|
|
17
17
|
};
|
|
18
|
+
identifier: string;
|
|
19
|
+
trigger: import("../Notifications.types").NotificationTrigger;
|
|
18
20
|
};
|
|
21
|
+
date: number;
|
|
19
22
|
};
|
|
20
23
|
actionIdentifier: string;
|
|
21
24
|
userText?: string | undefined;
|
|
@@ -29,11 +32,41 @@ export declare const mapNotificationResponse: (response: NotificationResponse) =
|
|
|
29
32
|
* @param notification The raw notification passed in from native code
|
|
30
33
|
* @returns the mapped notification.
|
|
31
34
|
*/
|
|
32
|
-
export declare const mapNotification: (notification: Notification) =>
|
|
35
|
+
export declare const mapNotification: (notification: Notification) => {
|
|
33
36
|
request: {
|
|
34
|
-
content: {
|
|
35
|
-
dataString?: string;
|
|
37
|
+
content: NotificationContent & {
|
|
38
|
+
dataString?: string | undefined;
|
|
36
39
|
};
|
|
40
|
+
identifier: string;
|
|
41
|
+
trigger: import("../Notifications.types").NotificationTrigger;
|
|
37
42
|
};
|
|
43
|
+
date: number;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* @hidden
|
|
47
|
+
*
|
|
48
|
+
* Does any required processing of a notification request from native code
|
|
49
|
+
* before it is passed to other JS code.
|
|
50
|
+
*
|
|
51
|
+
* @param request The raw request passed in from native code
|
|
52
|
+
* @returns the mapped request.
|
|
53
|
+
*/
|
|
54
|
+
export declare const mapNotificationRequest: (request: NotificationRequest) => {
|
|
55
|
+
content: NotificationContent & {
|
|
56
|
+
dataString?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
identifier: string;
|
|
59
|
+
trigger: import("../Notifications.types").NotificationTrigger;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* @hidden
|
|
63
|
+
* Does any required processing of notification content from native code
|
|
64
|
+
* before being passed to other JS code.
|
|
65
|
+
*
|
|
66
|
+
* @param content The raw content passed in from native code
|
|
67
|
+
* @returns the mapped content.
|
|
68
|
+
*/
|
|
69
|
+
export declare const mapNotificationContent: (content: NotificationContent) => NotificationContent & {
|
|
70
|
+
dataString?: string | undefined;
|
|
38
71
|
};
|
|
39
72
|
//# sourceMappingURL=mapNotificationResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapNotificationResponse.d.ts","sourceRoot":"","sources":["../../src/utils/mapNotificationResponse.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"mapNotificationResponse.d.ts","sourceRoot":"","sources":["../../src/utils/mapNotificationResponse.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,aAAc,oBAAoB;;;;;;;;;;;;;CAKrE,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,iBAAkB,YAAY;;;;;;;;;CAGxD,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,YAAa,mBAAmB;;;;;;CAGjE,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,YAAa,mBAAmB;;CAYlE,CAAC"}
|
|
@@ -23,18 +23,43 @@ export const mapNotificationResponse = (response) => {
|
|
|
23
23
|
* @param notification The raw notification passed in from native code
|
|
24
24
|
* @returns the mapped notification.
|
|
25
25
|
*/
|
|
26
|
-
export const mapNotification = (notification) => {
|
|
27
|
-
|
|
26
|
+
export const mapNotification = (notification) => ({
|
|
27
|
+
...notification,
|
|
28
|
+
request: mapNotificationRequest(notification.request),
|
|
29
|
+
});
|
|
30
|
+
/**
|
|
31
|
+
* @hidden
|
|
32
|
+
*
|
|
33
|
+
* Does any required processing of a notification request from native code
|
|
34
|
+
* before it is passed to other JS code.
|
|
35
|
+
*
|
|
36
|
+
* @param request The raw request passed in from native code
|
|
37
|
+
* @returns the mapped request.
|
|
38
|
+
*/
|
|
39
|
+
export const mapNotificationRequest = (request) => ({
|
|
40
|
+
...request,
|
|
41
|
+
content: mapNotificationContent(request.content),
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* @hidden
|
|
45
|
+
* Does any required processing of notification content from native code
|
|
46
|
+
* before being passed to other JS code.
|
|
47
|
+
*
|
|
48
|
+
* @param content The raw content passed in from native code
|
|
49
|
+
* @returns the mapped content.
|
|
50
|
+
*/
|
|
51
|
+
export const mapNotificationContent = (content) => {
|
|
52
|
+
const mappedContent = { ...content };
|
|
28
53
|
try {
|
|
29
|
-
const dataString =
|
|
54
|
+
const dataString = mappedContent['dataString'];
|
|
30
55
|
if (typeof dataString === 'string') {
|
|
31
|
-
|
|
32
|
-
delete
|
|
56
|
+
mappedContent.data = JSON.parse(dataString);
|
|
57
|
+
delete mappedContent.dataString;
|
|
33
58
|
}
|
|
34
59
|
}
|
|
35
60
|
catch (e) {
|
|
36
61
|
console.log(`Error in notification: ${e}`);
|
|
37
62
|
}
|
|
38
|
-
return
|
|
63
|
+
return mappedContent;
|
|
39
64
|
};
|
|
40
65
|
//# sourceMappingURL=mapNotificationResponse.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mapNotificationResponse.js","sourceRoot":"","sources":["../../src/utils/mapNotificationResponse.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mapNotificationResponse.js","sourceRoot":"","sources":["../../src/utils/mapNotificationResponse.ts"],"names":[],"mappings":"AAOA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,QAA8B,EAAE,EAAE;IACxE,OAAO;QACL,GAAG,QAAQ;QACX,YAAY,EAAE,eAAe,CAAC,QAAQ,CAAC,YAAY,CAAC;KACrD,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,YAA0B,EAAE,EAAE,CAAC,CAAC;IAC9D,GAAG,YAAY;IACf,OAAO,EAAE,sBAAsB,CAAC,YAAY,CAAC,OAAO,CAAC;CACtD,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAE,EAAE,CAAC,CAAC;IACvE,GAAG,OAAO;IACV,OAAO,EAAE,sBAAsB,CAAC,OAAO,CAAC,OAAO,CAAC;CACjD,CAAC,CAAC;AAEH;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,OAA4B,EAAE,EAAE;IACrE,MAAM,aAAa,GAAkD,EAAE,GAAG,OAAO,EAAE,CAAC;IACpF,IAAI;QACF,MAAM,UAAU,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC5C,OAAO,aAAa,CAAC,UAAU,CAAC;SACjC;KACF;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC;KAC5C;IACD,OAAO,aAAa,CAAC;AACvB,CAAC,CAAC","sourcesContent":["import {\n Notification,\n NotificationContent,\n NotificationRequest,\n NotificationResponse,\n} from '../Notifications.types';\n\n/**\n * @hidden\n *\n * Does any required processing of a notification response from native code\n * before it is passed to a notification response listener, or to the\n * last notification response hook.\n *\n * @param response The raw response passed in from native code\n * @returns the mapped response.\n */\nexport const mapNotificationResponse = (response: NotificationResponse) => {\n return {\n ...response,\n notification: mapNotification(response.notification),\n };\n};\n\n/**\n * @hidden\n *\n * Does any required processing of a notification from native code\n * before it is passed to a notification listener.\n *\n * @param notification The raw notification passed in from native code\n * @returns the mapped notification.\n */\nexport const mapNotification = (notification: Notification) => ({\n ...notification,\n request: mapNotificationRequest(notification.request),\n});\n\n/**\n * @hidden\n *\n * Does any required processing of a notification request from native code\n * before it is passed to other JS code.\n *\n * @param request The raw request passed in from native code\n * @returns the mapped request.\n */\nexport const mapNotificationRequest = (request: NotificationRequest) => ({\n ...request,\n content: mapNotificationContent(request.content),\n});\n\n/**\n * @hidden\n * Does any required processing of notification content from native code\n * before being passed to other JS code.\n *\n * @param content The raw content passed in from native code\n * @returns the mapped content.\n */\nexport const mapNotificationContent = (content: NotificationContent) => {\n const mappedContent: NotificationContent & { dataString?: string } = { ...content };\n try {\n const dataString = mappedContent['dataString'];\n if (typeof dataString === 'string') {\n mappedContent.data = JSON.parse(dataString);\n delete mappedContent.dataString;\n }\n } catch (e: any) {\n console.log(`Error in notification: ${e}`);\n }\n return mappedContent;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-notifications",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.16",
|
|
4
4
|
"description": "Notifications module",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"expo": "*"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "a9cfcf600ccaf5122932629472eb3bb2adb941fe"
|
|
59
59
|
}
|
|
@@ -2,6 +2,7 @@ import { UnavailabilityError } from 'expo-modules-core';
|
|
|
2
2
|
|
|
3
3
|
import NotificationScheduler from './NotificationScheduler';
|
|
4
4
|
import { NotificationRequest } from './Notifications.types';
|
|
5
|
+
import { mapNotificationRequest } from './utils/mapNotificationResponse';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Fetches information about all scheduled notifications.
|
|
@@ -13,5 +14,7 @@ export default async function getAllScheduledNotificationsAsync(): Promise<Notif
|
|
|
13
14
|
throw new UnavailabilityError('Notifications', 'getAllScheduledNotificationsAsync');
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
return await NotificationScheduler.getAllScheduledNotificationsAsync()
|
|
17
|
+
return (await NotificationScheduler.getAllScheduledNotificationsAsync()).map((request) =>
|
|
18
|
+
mapNotificationRequest(request)
|
|
19
|
+
);
|
|
17
20
|
}
|
|
@@ -2,6 +2,7 @@ import { UnavailabilityError } from 'expo-modules-core';
|
|
|
2
2
|
|
|
3
3
|
import NotificationPresenter from './NotificationPresenterModule';
|
|
4
4
|
import { Notification } from './Notifications.types';
|
|
5
|
+
import { mapNotification } from './utils/mapNotificationResponse';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Fetches information about all notifications present in the notification tray (Notification Center).
|
|
@@ -14,5 +15,7 @@ export default async function getPresentedNotificationsAsync(): Promise<Notifica
|
|
|
14
15
|
throw new UnavailabilityError('Notifications', 'getPresentedNotificationsAsync');
|
|
15
16
|
}
|
|
16
17
|
|
|
17
|
-
return await NotificationPresenter.getPresentedNotificationsAsync()
|
|
18
|
+
return (await NotificationPresenter.getPresentedNotificationsAsync()).map((notification) =>
|
|
19
|
+
mapNotification(notification)
|
|
20
|
+
);
|
|
18
21
|
}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Notification,
|
|
3
|
+
NotificationContent,
|
|
4
|
+
NotificationRequest,
|
|
5
|
+
NotificationResponse,
|
|
6
|
+
} from '../Notifications.types';
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* @hidden
|
|
@@ -26,18 +31,43 @@ export const mapNotificationResponse = (response: NotificationResponse) => {
|
|
|
26
31
|
* @param notification The raw notification passed in from native code
|
|
27
32
|
* @returns the mapped notification.
|
|
28
33
|
*/
|
|
29
|
-
export const mapNotification = (notification: Notification) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
34
|
+
export const mapNotification = (notification: Notification) => ({
|
|
35
|
+
...notification,
|
|
36
|
+
request: mapNotificationRequest(notification.request),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @hidden
|
|
41
|
+
*
|
|
42
|
+
* Does any required processing of a notification request from native code
|
|
43
|
+
* before it is passed to other JS code.
|
|
44
|
+
*
|
|
45
|
+
* @param request The raw request passed in from native code
|
|
46
|
+
* @returns the mapped request.
|
|
47
|
+
*/
|
|
48
|
+
export const mapNotificationRequest = (request: NotificationRequest) => ({
|
|
49
|
+
...request,
|
|
50
|
+
content: mapNotificationContent(request.content),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @hidden
|
|
55
|
+
* Does any required processing of notification content from native code
|
|
56
|
+
* before being passed to other JS code.
|
|
57
|
+
*
|
|
58
|
+
* @param content The raw content passed in from native code
|
|
59
|
+
* @returns the mapped content.
|
|
60
|
+
*/
|
|
61
|
+
export const mapNotificationContent = (content: NotificationContent) => {
|
|
62
|
+
const mappedContent: NotificationContent & { dataString?: string } = { ...content };
|
|
33
63
|
try {
|
|
34
|
-
const dataString =
|
|
64
|
+
const dataString = mappedContent['dataString'];
|
|
35
65
|
if (typeof dataString === 'string') {
|
|
36
|
-
|
|
37
|
-
delete
|
|
66
|
+
mappedContent.data = JSON.parse(dataString);
|
|
67
|
+
delete mappedContent.dataString;
|
|
38
68
|
}
|
|
39
69
|
} catch (e: any) {
|
|
40
70
|
console.log(`Error in notification: ${e}`);
|
|
41
71
|
}
|
|
42
|
-
return
|
|
72
|
+
return mappedContent;
|
|
43
73
|
};
|