From 014900c2e506ed64d53e946d2df733ea3a1dc6f3 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Fri, 15 Dec 2017 18:01:49 -0800 Subject: [PATCH] push notifs: Include same stream and sender info on GCM as on APNs. This takes the information added to APNs payloads by #7080, and adds to our GCM payloads the parts that it didn't already have. --- zerver/lib/push_notifications.py | 12 +++++++++--- zerver/tests/test_push_notifications.py | 12 ++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index a52fd3ec32..d5d5153282 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -440,13 +440,22 @@ def truncate_content(content: Text) -> Text: def get_common_payload(message: Message) -> Dict[str, Any]: data = {} # type: Dict[str, Any] + + # These will let the app support logging into multiple realms and servers. + data['server'] = settings.EXTERNAL_HOST + data['realm_id'] = message.sender.realm.id + + # `sender_id` is preferred, but some existing versions use `sender_email`. + data['sender_id'] = message.sender.id data['sender_email'] = message.sender.email + if message.is_stream_message(): data['recipient_type'] = "stream" data['stream'] = get_display_recipient(message.recipient) data['topic'] = message.subject else: data['recipient_type'] = "private" + return data def get_apns_payload(message: Message) -> Dict[str, Any]: @@ -456,9 +465,6 @@ def get_apns_payload(message: Message) -> Dict[str, Any]: zulip_data = get_common_payload(message) zulip_data.update({ 'message_ids': [message.id], - 'sender_id': message.sender.id, - 'server': settings.EXTERNAL_HOST, - 'realm_id': message.sender.realm.id, }) apns_data = { diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 69dfceb766..a379081d55 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -750,6 +750,9 @@ class TestGetGCMPayload(PushNotificationTest): "time": apn.datetime_to_timestamp(message.pub_date), "content": 'a' * 200 + '…', "content_truncated": True, + "server": settings.EXTERNAL_HOST, + "realm_id": self.example_user("hamlet").realm.id, + "sender_id": self.example_user("hamlet").id, "sender_email": self.example_email("hamlet"), "sender_full_name": "King Hamlet", "sender_avatar_url": apn.absolute_avatar_url(message.sender), @@ -772,6 +775,9 @@ class TestGetGCMPayload(PushNotificationTest): "time": apn.datetime_to_timestamp(message.pub_date), "content": message.content, "content_truncated": False, + "server": settings.EXTERNAL_HOST, + "realm_id": self.example_user("hamlet").realm.id, + "sender_id": self.example_user("hamlet").id, "sender_email": self.example_email("hamlet"), "sender_full_name": "King Hamlet", "sender_avatar_url": apn.absolute_avatar_url(message.sender), @@ -793,6 +799,9 @@ class TestGetGCMPayload(PushNotificationTest): "time": apn.datetime_to_timestamp(message.pub_date), "content": message.content, "content_truncated": False, + "server": settings.EXTERNAL_HOST, + "realm_id": self.example_user("hamlet").realm.id, + "sender_id": self.example_user("hamlet").id, "sender_email": self.example_email("hamlet"), "sender_full_name": "King Hamlet", "sender_avatar_url": apn.absolute_avatar_url(message.sender), @@ -817,6 +826,9 @@ class TestGetGCMPayload(PushNotificationTest): "time": apn.datetime_to_timestamp(message.pub_date), "content": "***REDACTED***", "content_truncated": False, + "server": settings.EXTERNAL_HOST, + "realm_id": self.example_user("hamlet").realm.id, + "sender_id": self.example_user("hamlet").id, "sender_email": self.example_email("hamlet"), "sender_full_name": "King Hamlet", "sender_avatar_url": apn.absolute_avatar_url(message.sender),