mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	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.
This commit is contained in:
		@@ -4379,14 +4379,15 @@ def do_delete_messages(user_profile: UserProfile, messages: Iterable[Message]) -
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        event = {
 | 
					        event = {
 | 
				
			||||||
            'type': 'delete_message',
 | 
					            'type': 'delete_message',
 | 
				
			||||||
            'sender': user_profile.email,
 | 
					            'sender': message.sender.email,
 | 
				
			||||||
 | 
					            'sender_id': message.sender_id,
 | 
				
			||||||
            'message_id': message.id,
 | 
					            'message_id': message.id,
 | 
				
			||||||
            'message_type': message_type, }  # type: Dict[str, Any]
 | 
					            'message_type': message_type, }  # type: Dict[str, Any]
 | 
				
			||||||
        if message_type == "stream":
 | 
					        if message_type == "stream":
 | 
				
			||||||
            event['stream_id'] = message.recipient.type_id
 | 
					            event['stream_id'] = message.recipient.type_id
 | 
				
			||||||
            event['topic'] = message.topic_name()
 | 
					            event['topic'] = message.topic_name()
 | 
				
			||||||
        else:
 | 
					        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
 | 
					        # TODO: Each part of the following should be changed to bulk
 | 
				
			||||||
        # queries, since right now if you delete 1000 messages, you'll
 | 
					        # queries, since right now if you delete 1000 messages, you'll
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2464,6 +2464,7 @@ class EventsRegisterTest(ZulipTestCase):
 | 
				
			|||||||
            ('type', equals('delete_message')),
 | 
					            ('type', equals('delete_message')),
 | 
				
			||||||
            ('message_id', check_int),
 | 
					            ('message_id', check_int),
 | 
				
			||||||
            ('sender', check_string),
 | 
					            ('sender', check_string),
 | 
				
			||||||
 | 
					            ('sender_id', check_int),
 | 
				
			||||||
            ('message_type', equals("stream")),
 | 
					            ('message_type', equals("stream")),
 | 
				
			||||||
            ('stream_id', check_int),
 | 
					            ('stream_id', check_int),
 | 
				
			||||||
            ('topic', check_string),
 | 
					            ('topic', check_string),
 | 
				
			||||||
@@ -2482,8 +2483,9 @@ class EventsRegisterTest(ZulipTestCase):
 | 
				
			|||||||
            ('type', equals('delete_message')),
 | 
					            ('type', equals('delete_message')),
 | 
				
			||||||
            ('message_id', check_int),
 | 
					            ('message_id', check_int),
 | 
				
			||||||
            ('sender', check_string),
 | 
					            ('sender', check_string),
 | 
				
			||||||
 | 
					            ('sender_id', check_int),
 | 
				
			||||||
            ('message_type', equals("private")),
 | 
					            ('message_type', equals("private")),
 | 
				
			||||||
            ('recipient_user_ids', check_int),
 | 
					            ('recipient_id', check_int),
 | 
				
			||||||
        ])
 | 
					        ])
 | 
				
			||||||
        msg_id = self.send_personal_message(
 | 
					        msg_id = self.send_personal_message(
 | 
				
			||||||
            self.example_email("cordelia"),
 | 
					            self.example_email("cordelia"),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user