mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 04:43:58 +00:00
push_notifications: Fix interface for handle_remove_push_notification.
This really should just accept a message ID.
This commit is contained in:
@@ -548,7 +548,7 @@ def get_gcm_payload(user_profile: UserProfile, message: Message) -> Dict[str, An
|
|||||||
})
|
})
|
||||||
return data
|
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
|
"""This should be called when a message that had previously had a
|
||||||
mobile push executed is read. This triggers a mobile push notifica
|
mobile push executed is read. This triggers a mobile push notifica
|
||||||
mobile app when the message is read on the server, to remove the
|
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)
|
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 = get_common_payload(message)
|
||||||
gcm_payload.update({
|
gcm_payload.update({
|
||||||
'event': 'remove',
|
'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():
|
if uses_notification_bouncer():
|
||||||
|
|||||||
@@ -544,15 +544,12 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
message=message
|
message=message
|
||||||
)
|
)
|
||||||
|
|
||||||
remove_message = {
|
|
||||||
'message_id': message.id,
|
|
||||||
}
|
|
||||||
with self.settings(PUSH_NOTIFICATION_BOUNCER_URL=True), \
|
with self.settings(PUSH_NOTIFICATION_BOUNCER_URL=True), \
|
||||||
mock.patch('zerver.lib.push_notifications'
|
mock.patch('zerver.lib.push_notifications'
|
||||||
'.send_notifications_to_bouncer') as mock_send_android, \
|
'.send_notifications_to_bouncer') as mock_send_android, \
|
||||||
mock.patch('zerver.lib.push_notifications.get_common_payload',
|
mock.patch('zerver.lib.push_notifications.get_common_payload',
|
||||||
return_value={'gcm': True}):
|
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, {},
|
mock_send_android.assert_called_with(user_profile.id, {},
|
||||||
{'gcm': True,
|
{'gcm': True,
|
||||||
'event': 'remove',
|
'event': 'remove',
|
||||||
@@ -575,15 +572,11 @@ class HandlePushNotificationTest(PushNotificationTest):
|
|||||||
PushDeviceToken.objects.filter(user=self.user_profile,
|
PushDeviceToken.objects.filter(user=self.user_profile,
|
||||||
kind=PushDeviceToken.GCM))
|
kind=PushDeviceToken.GCM))
|
||||||
|
|
||||||
remove_message = {
|
|
||||||
'message_id': message.id,
|
|
||||||
}
|
|
||||||
|
|
||||||
with mock.patch('zerver.lib.push_notifications'
|
with mock.patch('zerver.lib.push_notifications'
|
||||||
'.send_android_push_notification') as mock_send_android, \
|
'.send_android_push_notification') as mock_send_android, \
|
||||||
mock.patch('zerver.lib.push_notifications.get_common_payload',
|
mock.patch('zerver.lib.push_notifications.get_common_payload',
|
||||||
return_value={'gcm': True}):
|
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,
|
mock_send_android.assert_called_with(android_devices,
|
||||||
{'gcm': True,
|
{'gcm': True,
|
||||||
'event': 'remove',
|
'event': 'remove',
|
||||||
|
|||||||
Reference in New Issue
Block a user