real-time sync: Server sends recipent data with delete_message event.

Fixes #8853.
In certain cases, the browser is not able to look up the message.
Include the recipient data for the message in the delete_message event,
so look up of those attributes by the browser isn't required.
This commit is contained in:
Shubham Padia
2018-04-02 03:51:21 +05:30
committed by Tim Abbott
parent e1d9e3ae03
commit 10115491a3
4 changed files with 43 additions and 13 deletions

View File

@@ -479,6 +479,9 @@ var event_fixtures = {
delete_message: {
type: 'delete_message',
message_id: 1337,
message_type: "stream",
stream_id: 99,
topic: 'topic1',
},
custom_profile_fields: {
@@ -942,13 +945,6 @@ set_global('message_store', {});
with_overrides(function (override) {
// delete_message
var event = event_fixtures.delete_message;
message_store.get = function (msg_id) {
return { id: msg_id,
reactions: [],
stream_id: 99,
subject: 'topic1',
type: 'stream'};
};
override('stream_list.update_streams_sidebar', noop);
global.with_stub(function (stub) {

View File

@@ -394,15 +394,14 @@ exports.dispatch_normal_event = function dispatch_normal_event(event) {
case 'delete_message':
var msg_id = event.message_id;
var message = message_store.get(msg_id);
// message is passed to unread.get_unread_messages,
// which returns all the unread messages out of a given list.
// So double marking something as read would not occur
unread_ops.process_read_messages_event([msg_id]);
if (message.type === 'stream') {
if (event.message_type === 'stream') {
topic_data.remove_message({
stream_id: message.stream_id,
topic_name: message.subject,
stream_id: event.stream_id,
topic_name: event.topic,
});
stream_list.update_streams_sidebar();
}

View File

@@ -3737,10 +3737,21 @@ def do_update_message(user_profile: UserProfile, message: Message, topic_name: O
def do_delete_message(user_profile: UserProfile, message: Message) -> None:
message_type = "stream"
if not message.is_stream_message():
message_type = "private"
event = {
'type': 'delete_message',
'sender': user_profile.email,
'message_id': message.id} # type: Dict[str, Any]
'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.subject
else:
event['recipient_user_ids'] = message.recipient.type_id
ums = [{'id': um.user_profile_id} for um in
UserMessage.objects.filter(message=message.id)]
move_message_to_archive(message.id)

View File

@@ -2023,11 +2023,14 @@ class EventsRegisterTest(ZulipTestCase):
error = add_schema_checker('events[1]', events[1])
self.assert_on_error(error)
def test_do_delete_message(self) -> None:
def test_do_delete_message_stream(self) -> None:
schema_checker = self.check_events_dict([
('type', equals('delete_message')),
('message_id', check_int),
('sender', check_string),
('message_type', equals("stream")),
('stream_id', check_int),
('topic', check_string),
])
msg_id = self.send_stream_message("hamlet@zulip.com", "Verona")
message = Message.objects.get(id=msg_id)
@@ -2038,6 +2041,27 @@ class EventsRegisterTest(ZulipTestCase):
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)
def test_do_delete_message_personal(self) -> None:
schema_checker = self.check_events_dict([
('type', equals('delete_message')),
('message_id', check_int),
('sender', check_string),
('message_type', equals("private")),
('recipient_user_ids', check_int),
])
msg_id = self.send_personal_message(
self.example_email("cordelia"),
self.user_profile.email,
"hello",
)
message = Message.objects.get(id=msg_id)
events = self.do_test(
lambda: do_delete_message(self.user_profile, message),
state_change_expected=True,
)
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)
def test_do_delete_message_no_max_id(self) -> None:
user_profile = self.example_user('aaron')
# Delete all historical messages for this user