Skip to content
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

set different messages be specified for each user #653

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,16 @@ value per user. Assuming User model has a method get_badge returning badge count
badge=lambda token: APNSDevice.objects.get(registration_id=token).user.get_badge()
)

Similar to the above, It's also possible to pass message parameter as a function which accepts token parameter in order
to set different message value per user. Assuming User model has a method get_message returning message for a user:

.. code-block:: python

devices.send_message(
message=lambda token: APNSDevice.objects.get(registration_id=token).user.get_message()
badge=5
)

Firebase vs Google Cloud Messaging
----------------------------------

Expand Down
3 changes: 3 additions & 0 deletions push_notifications/apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
token, alert, application_id=None, badge=None, sound=None, category=None,
content_available=False, action_loc_key=None, loc_key=None, loc_args=[],
extra={}, mutable_content=False, thread_id=None, url_args=None):
if callable(alert):
alert = alert(token)

Check warning on line 46 in push_notifications/apns.py

View check run for this annotation

Codecov / codecov/patch

push_notifications/apns.py#L46

Added line #L46 was not covered by tests

if action_loc_key or loc_key or loc_args:
apns2_alert = apns2_payload.PayloadAlert(
body=alert if alert else {}, body_localized_key=loc_key,
Expand Down