Skip to content

ios notif [nfc]: Simplify out some redundant logic #5252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2022
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