Commit Graph

7 Commits

Author SHA1 Message Date
Prakhar Pratyush
eefb88f0ea push_notification: Fix invalid data arg to firebase_messaging.Message.
Earlier, we were passing invalid `data` argument to
`firebase_messaging.Message` which would result in an error while
sending E2EE push notification for android devices.

The API requires all keys and values in the `data` dictionary
to be strings. One of the value was an integer.

This commit fixes the bug by converting the values to str if they
are not.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
2025-11-04 12:39:39 -08:00
Prakhar Pratyush
25630f316b push_notification: Improve logged message when apns_context is None.
Earlier, while sending notification if `apns_context=None` - we logged:
"APNs: Dropping a notification because nothing configured. Set
ZULIP_SERVICES_URL (or APNS_CERT_FILE)." which is not accurate for E2EE
case.

For the non-E2EE case it is correct because configuring
ZULIP_SERVICES_URL results in transfering the responsbility to
make API call to APNs to the bouncer. Or they can configure
APNS_CERT_FILE if they want to send directly.

In E2EE case, the `send_e2ee_push_notification_apple` is part of
bouncer so configuring `ZULIP_SERVICES_URL` doesn't help. One needs
to configure either `APNS_TOKEN_KEY_FILE` or `APNS_CERT_FILE`.

Message to log is updated accordingly + severity increased from
DEBUG to ERROR.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
2025-11-03 15:45:22 -08:00
Prakhar Pratyush
d893496de1 push_notification: Drop notif if ANDROID_FCM_CREDENTIALS_PATH is unset.
If `ANDROID_FCM_CREDENTIALS_PATH` is unset it results in fcm_app=None.
We should log error in this case and return, not doing so will result
in runtime error.

Signed-off-by: Prakhar Pratyush <prakhar@zulip.com>
2025-11-03 15:45:22 -08:00
Prakhar Pratyush
3548764e21 push_notifications: Use SentPushNotificationResult dataclass.
Refactoring, no functional change.

This commit refactors `send_e2ee_push_notification_apple`
and `send_e2ee_push_notification_android` to return a
`SentPushNotificationResult` dataclass.

It's a cleaner protocol than passing a mutable data structure
`delete_device_ids` as argument and updating it within
functions.

Fixes part of #35368.
2025-08-27 10:56:42 -07:00
Prakhar Pratyush
6ab6df96c8 push_notification: Send a list of push requests.
Earlier, we were passing a map `device_id_to_encrypted_data`
and http headers as separate fields to bouncer.

The downside of that approach is it restricts the bouncer to
process only one type of notice i.e. either notification for
a new message or removal of sent notification, because it
used to receive a fixed priority and push_type for all the
entries in the map.

Also, using map restricts the bouncer to receive only one
request per device_id. Server can't send multiple notices
to a device in a single call to bouncer.

Currently, the server isn't modelled in a way to make a
single call to the bouncer with:
* Both send-notification & remove-notification request data.
* Multiple send-notification request data to the same device.

This commit replaces the old protocol of sending data with
a list of objects where each object has the required data
for bouncer to send it to FCM or APNs.

This makes things a lot flexible and opens possibility for
server to batch requests in a different way if we'd like to.
2025-07-25 12:47:55 -07:00
Prakhar Pratyush
29ea8a07c2 push_notification: Add support to configure priority and push_type.
This commit adds support to let server configure:
* fcm_priority
* apns_priority
* apns_push_type

while sending E2EE push notifications.

The values of these fields will vary depending on whether the
send request is to send push notification for a message or
revoke an already sent notification.

Since, the bouncer receives encrypted data so it can't inspect
the payload to determine whether it is a removal request or not,
hence can't configure priority on its own.

The server needs to specify explicitly.

We're not simply sending a single 'is_removal' flag because
allowing the server to configure them separately will help in
future to support other types of notifications with a different
combination of priority and push_type, like whose aim is to notify
user about information other than a new message or removal request.

Fixes part of #35368.
2025-07-24 11:56:42 -07:00
Prakhar Pratyush
7e1afa0e8a push_notification: Send end-to-end encrypted push notifications.
This commit adds support to send encrypted push notifications
to devices registered to receive encrypted notifications.

URL: `POST /api/v1/remotes/push/e2ee/notify`
payload: `realm_uuid` and `device_id_to_encrypted_data`

The POST request needs to be authenticated with the server’s
API key.

Note: For Zulip Cloud, a background fact about the push bouncer is
that it runs on the same server and database as the main application;
it’s not a separate service. So, as an optimization we directly call
'send_e2ee_push_notifications' function and skip the HTTP request.
2025-07-22 17:08:55 -07:00