diff --git a/src/notification/extract.js b/src/notification/extract.js index 42acefec5bf..847d4093f64 100644 --- a/src/notification/extract.js +++ b/src/notification/extract.js @@ -34,44 +34,28 @@ class ApnsMsgValidationError extends logging.ExtendableError { // @returns A `Notification` on success, `undefined` on suppressible failure. // @throws An ApnsMsgValidationError on unexpected failure. // -export const fromAPNsImpl = (rawData: ?JSONableDict): Notification | void => { +export const fromAPNsImpl = (data: ?JSONableDict): Notification | void => { // // For the format this parses, see `ApnsPayload` in src/api/notificationTypes.js . // // Though what it actually receives is more like this: // $Rest - // See comment below about PushNotificationsIOS. + // because the `ApnsPayload` gets parsed by the `PushNotificationIOS` + // library, and what it gives us through `getData` is everything but the + // `aps` property. /** Helper function: fail. */ const err = (style: string) => new ApnsMsgValidationError(`Received ${style} APNs notification`, { // an `undefined` value would make `extras` not JSONable, but we will // want to know if the value is undefined - data: rawData === undefined ? '__undefined__' : rawData, + data: data === undefined ? '__undefined__' : data, }); - if (rawData == null) { + if (data == null) { throw err('nullish'); } - // APNs messages are JSON dictionaries. The `aps` entry of this dictionary is - // required, with a structure defined by Apple; all other entries are - // available to the application. - // - // PushNotificationsIOS filters out `aps`, parses it, and hands us the rest - // as "data". Pretty much any iOS notifications library should do - // the same, but we don't rely on that. - - const data: JSONableInputDict = (() => { - if ('aps' in rawData) { - // eslint-disable-next-line no-unused-vars - const { aps, ...rest } = rawData; - return rest; - } else { - return rawData; - } - })(); - // Always present; see `ApnsPayload`. const zulip: JSONableInputDict | void = asDict(data.zulip); if (!zulip) {