expo-notifications 0.28.15 → 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 CHANGED
@@ -10,6 +10,12 @@
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
+
13
19
  ## 0.28.15 — 2024-08-05
14
20
 
15
21
  ### 🐛 Bug fixes
@@ -1,7 +1,7 @@
1
1
  apply plugin: 'com.android.library'
2
2
 
3
3
  group = 'host.exp.exponent'
4
- version = '0.28.15'
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.15'
17
+ versionName '0.28.16'
18
18
  }
19
19
 
20
20
  buildFeatures {
@@ -23,6 +23,7 @@ import java.util.Map;
23
23
  import java.util.Set;
24
24
 
25
25
  import expo.modules.notifications.notifications.interfaces.NotificationTrigger;
26
+ import expo.modules.notifications.notifications.interfaces.SchedulableNotificationTrigger;
26
27
  import expo.modules.notifications.notifications.model.Notification;
27
28
  import expo.modules.notifications.notifications.model.NotificationContent;
28
29
  import expo.modules.notifications.notifications.model.NotificationRequest;
@@ -60,19 +61,27 @@ public class NotificationSerializer {
60
61
  serializedRequest.putBundle("trigger", toBundle(request.getTrigger()));
61
62
  Bundle content = toBundle(request.getContent());
62
63
  Bundle existingContentData = content.getBundle("data");
63
- if (existingContentData == null && request.getTrigger() instanceof FirebaseNotificationTrigger trigger) {
64
- RemoteMessage message = trigger.getRemoteMessage();
65
- RemoteMessage.Notification notification = message.getNotification();
66
- Map<String, String> data = message.getData();
67
- String dataBody = data.get("body");
68
- String notificationBody = notification != null ? notification.getBody() : null;
69
- if (isValidJSONString(dataBody) && notificationBody != null && notificationBody.equals(data.get("message"))) {
70
- // Expo sends notification.body as data.message, and JSON stringifies data.body
71
- content.putString("dataString", dataBody);
72
- } else {
73
- // The message was sent directly from Firebase or some other service,
74
- // and we copy the data as is
75
- content.putBundle("data", toBundle(data));
64
+ if (existingContentData == null) {
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
+ }
76
85
  }
77
86
  }
78
87
  serializedRequest.putBundle("content", content);
@@ -1 +1 @@
1
- {"version":3,"file":"getAllScheduledNotificationsAsync.d.ts","sourceRoot":"","sources":["../src/getAllScheduledNotificationsAsync.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;;;GAIG;AACH,wBAA8B,iCAAiC,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAMhG"}
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;AAG5D;;;;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,MAAM,qBAAqB,CAAC,iCAAiC,EAAE,CAAC;AACzE,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport NotificationScheduler from './NotificationScheduler';\nimport { NotificationRequest } from './Notifications.types';\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();\n}\n"]}
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;AAErD;;;;;GAKG;AACH,wBAA8B,8BAA8B,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC,CAMtF"}
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;AAGlE;;;;;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,MAAM,qBAAqB,CAAC,8BAA8B,EAAE,CAAC;AACtE,CAAC","sourcesContent":["import { UnavailabilityError } from 'expo-modules-core';\n\nimport NotificationPresenter from './NotificationPresenterModule';\nimport { Notification } from './Notifications.types';\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();\n}\n"]}
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: 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) => 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,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE5E;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,aAAc,oBAAoB;;iBAkBzD;YAAE,OAAO,EAAE;gBAAE,UAAU,CAAC,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE;;;;CAbhD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,iBAAkB,YAAY;aAE7C;QAAE,OAAO,EAAE;YAAE,UAAU,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAAE;CAYhD,CAAC"}
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
- const mappedNotification = { ...notification };
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 = mappedNotification?.request?.content['dataString'];
54
+ const dataString = mappedContent['dataString'];
30
55
  if (typeof dataString === 'string') {
31
- mappedNotification.request.content.data = JSON.parse(dataString);
32
- delete mappedNotification.request.content.dataString;
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 mappedNotification;
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":"AAEA;;;;;;;;;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;IAC5D,MAAM,kBAAkB,GAEpB,EAAE,GAAG,YAAY,EAAE,CAAC;IACxB,IAAI;QACF,MAAM,UAAU,GAAG,kBAAkB,EAAE,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;QACtE,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACjE,OAAO,kBAAkB,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;SACtD;KACF;IAAC,OAAO,CAAM,EAAE;QACf,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC;KAC5C;IACD,OAAO,kBAAkB,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["import { Notification, NotificationResponse } 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 const mappedNotification: Notification & {\n request: { content: { dataString?: string } };\n } = { ...notification };\n try {\n const dataString = mappedNotification?.request?.content['dataString'];\n if (typeof dataString === 'string') {\n mappedNotification.request.content.data = JSON.parse(dataString);\n delete mappedNotification.request.content.dataString;\n }\n } catch (e: any) {\n console.log(`Error in notification: ${e}`);\n }\n return mappedNotification;\n};\n"]}
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.15",
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": "760c0c1a3bebcedc19836db8bc98c737f0db8c8d"
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 { Notification, NotificationResponse } from '../Notifications.types';
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
- const mappedNotification: Notification & {
31
- request: { content: { dataString?: string } };
32
- } = { ...notification };
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 = mappedNotification?.request?.content['dataString'];
64
+ const dataString = mappedContent['dataString'];
35
65
  if (typeof dataString === 'string') {
36
- mappedNotification.request.content.data = JSON.parse(dataString);
37
- delete mappedNotification.request.content.dataString;
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 mappedNotification;
72
+ return mappedContent;
43
73
  };