Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions src/notification/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<ApnsPayload, {| aps: mixed |}>
// 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) {
Expand Down