From e9f4d9db2b0543c8ea84bdbe4e58a40a066bf088 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 1 Aug 2018 16:28:28 -0700 Subject: [PATCH] push_notifications: Fix interface for handle_remove_push_notification. This really should just accept a message ID. --- zerver/lib/push_notifications.py | 6 +++--- zerver/tests/test_push_notifications.py | 11 ++--------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/zerver/lib/push_notifications.py b/zerver/lib/push_notifications.py index ba8a323329..543f2ab81f 100644 --- a/zerver/lib/push_notifications.py +++ b/zerver/lib/push_notifications.py @@ -548,7 +548,7 @@ 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: +def handle_remove_push_notification(user_profile_id: int, message_id: int) -> 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 @@ -556,11 +556,11 @@ def handle_remove_push_notification(user_profile_id: int, remove_message: Dict[s """ user_profile = get_user_profile_by_id(user_profile_id) - message = access_message(user_profile, remove_message['message_id'])[0] + message = access_message(user_profile, 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 + 'zulip_message_id': message_id, # message_id is reserved for CCS }) if uses_notification_bouncer(): diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index 514b5b0b25..d62f1640c5 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -544,15 +544,12 @@ class HandlePushNotificationTest(PushNotificationTest): message=message ) - remove_message = { - 'message_id': message.id, - } with self.settings(PUSH_NOTIFICATION_BOUNCER_URL=True), \ mock.patch('zerver.lib.push_notifications' '.send_notifications_to_bouncer') as mock_send_android, \ mock.patch('zerver.lib.push_notifications.get_common_payload', return_value={'gcm': True}): - apn.handle_remove_push_notification(user_profile.id, remove_message) + apn.handle_remove_push_notification(user_profile.id, message.id) mock_send_android.assert_called_with(user_profile.id, {}, {'gcm': True, 'event': 'remove', @@ -575,15 +572,11 @@ class HandlePushNotificationTest(PushNotificationTest): PushDeviceToken.objects.filter(user=self.user_profile, kind=PushDeviceToken.GCM)) - remove_message = { - 'message_id': message.id, - } - with mock.patch('zerver.lib.push_notifications' '.send_android_push_notification') as mock_send_android, \ mock.patch('zerver.lib.push_notifications.get_common_payload', return_value={'gcm': True}): - apn.handle_remove_push_notification(self.user_profile.id, remove_message) + apn.handle_remove_push_notification(self.user_profile.id, message.id) mock_send_android.assert_called_with(android_devices, {'gcm': True, 'event': 'remove',