mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
notifications: Add function for cancelling GCM notifications.
This adds a new function called handle_remove_push_notification in zerver/lib/push_notifications.py which requires user_profile id and the message id which has to be removed in the function. For now, the function only supports GCM (and is mostly there for prototyping). The payload which is being delivered needs to contain the narrow information and the content of the message.
This commit is contained in:
@@ -548,6 +548,39 @@ def get_gcm_payload(user_profile: UserProfile, message: Message) -> Dict[str, An
|
||||
})
|
||||
return data
|
||||
|
||||
def handle_remove_push_notification(user_profile_id: int, remove_message: Dict[str, Any]) -> None:
|
||||
"""This should be called when a message that had previously had a
|
||||
mobile push executed is read. This triggers a mobile push notifica
|
||||
mobile app when the message is read on the server, to remove the
|
||||
message from the notification.
|
||||
|
||||
"""
|
||||
user_profile = get_user_profile_by_id(user_profile_id)
|
||||
message = access_message(user_profile, remove_message['message_id'])[0]
|
||||
gcm_payload = get_common_payload(message)
|
||||
gcm_payload.update({
|
||||
'event': 'remove',
|
||||
'zulip_message_id': remove_message['message_id'], # message_id is reserved for CCS
|
||||
})
|
||||
|
||||
if uses_notification_bouncer():
|
||||
try:
|
||||
send_notifications_to_bouncer(user_profile_id,
|
||||
{},
|
||||
gcm_payload)
|
||||
except requests.ConnectionError: # nocoverage
|
||||
def failure_processor(event: Dict[str, Any]) -> None:
|
||||
logging.warning(
|
||||
"Maximum retries exceeded for trigger:%s event:push_notification" % (
|
||||
event['user_profile_id']))
|
||||
return
|
||||
|
||||
android_devices = list(PushDeviceToken.objects.filter(user=user_profile,
|
||||
kind=PushDeviceToken.GCM))
|
||||
|
||||
if android_devices:
|
||||
send_android_push_notification(android_devices, gcm_payload)
|
||||
|
||||
@statsd_increment("push_notifications")
|
||||
def handle_push_notification(user_profile_id: int, missed_message: Dict[str, Any]) -> None:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user