From 4f2c9f46bdd33271f566bbc00b853f59c51f83b4 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 19 Mar 2019 20:16:22 -0700 Subject: [PATCH] actions: Improve format for delete events. There were several problems with the old format: * The sender was not necessarily the sender; it was the person who did the deletion (which could be an organization administrator) * It didn't include the ID of the sender, just the email address. * It didn't include the recipient ID, instead having a semi-malformed recipient_type_id under the weird name recipient_user_ids. Since nothing was relying on the old behavior, we can just fix the event structure. --- zerver/lib/actions.py | 5 +++-- zerver/tests/test_events.py | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index 1c2e3ed371..58651c8c5e 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -4379,14 +4379,15 @@ def do_delete_messages(user_profile: UserProfile, messages: Iterable[Message]) - event = { 'type': 'delete_message', - 'sender': user_profile.email, + 'sender': message.sender.email, + 'sender_id': message.sender_id, 'message_id': message.id, 'message_type': message_type, } # type: Dict[str, Any] if message_type == "stream": event['stream_id'] = message.recipient.type_id event['topic'] = message.topic_name() else: - event['recipient_user_ids'] = message.recipient.type_id + event['recipient_id'] = message.recipient_id # TODO: Each part of the following should be changed to bulk # queries, since right now if you delete 1000 messages, you'll diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py index 023c154638..8716f46bf3 100644 --- a/zerver/tests/test_events.py +++ b/zerver/tests/test_events.py @@ -2464,6 +2464,7 @@ class EventsRegisterTest(ZulipTestCase): ('type', equals('delete_message')), ('message_id', check_int), ('sender', check_string), + ('sender_id', check_int), ('message_type', equals("stream")), ('stream_id', check_int), ('topic', check_string), @@ -2482,8 +2483,9 @@ class EventsRegisterTest(ZulipTestCase): ('type', equals('delete_message')), ('message_id', check_int), ('sender', check_string), + ('sender_id', check_int), ('message_type', equals("private")), - ('recipient_user_ids', check_int), + ('recipient_id', check_int), ]) msg_id = self.send_personal_message( self.example_email("cordelia"),