Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
events: Fix apply_events when raw_unread_msgs not present.
Tim Abbott2aae32f642b8
diff --git a/zerver/lib/events.py b/zerver/lib/events.pyindex 8d4ccfa5efe..9eb875e3f66 100644--- a/zerver/lib/events.py+++ b/zerver/lib/events.py@@ -1216,14 +1216,14 @@ def apply_event(# We don't return messages in /register, so we don't need to# do anything for content updates, but we may need to update# the unread_msgs data if the topic of an unread message changed.- if "new_stream_id" in event:+ if "raw_unread_msgs" in state and "new_stream_id" in event:stream_dict = state["raw_unread_msgs"]["stream_dict"]stream_id = event["new_stream_id"]for message_id in event["message_ids"]:if message_id in stream_dict:stream_dict[message_id]["stream_id"] = stream_id- if TOPIC_NAME in event:+ if "raw_unread_msgs" in state and TOPIC_NAME in event:stream_dict = state["raw_unread_msgs"]["stream_dict"]topic = event[TOPIC_NAME]for message_id in event["message_ids"]:@@ -1275,7 +1275,7 @@ def apply_event(if "raw_unread_msgs" in state and event["flag"] == "read" and event["op"] == "add":for remove_id in event["messages"]:remove_message_id_from_unread_mgs(state["raw_unread_msgs"], remove_id)- if event["flag"] == "read" and event["op"] == "remove":+ if "raw_unread_msgs" in state and event["flag"] == "read" and event["op"] == "remove":for message_id_str, message_details in event["message_details"].items():add_message_to_unread_msgs(user_profile.id,diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.pyindex 7249ed4feaf..be64f33fe2a 100644--- a/zerver/tests/test_events.py+++ b/zerver/tests/test_events.py@@ -621,8 +621,8 @@ class NormalActionsTest(BaseAction):)# Verify move topic to different stream.-- # Send 2 messages in "test" topic.+ self.subscribe(self.user_profile, "Verona")+ self.subscribe(self.user_profile, "Denmark")self.send_stream_message(self.user_profile, "Verona")message_id = self.send_stream_message(self.user_profile, "Verona")message = Message.objects.get(id=message_id)@@ -660,6 +660,48 @@ class NormalActionsTest(BaseAction):is_embedded_update_only=False,)+ # Move both stream and topic, with update_message_flags+ # excluded from event types.+ self.send_stream_message(self.user_profile, "Verona")+ message_id = self.send_stream_message(self.user_profile, "Verona")+ message = Message.objects.get(id=message_id)+ stream = get_stream("Denmark", self.user_profile.realm)+ propagate_mode = "change_all"+ prior_mention_user_ids = set()++ events = self.verify_action(+ lambda: do_update_message(+ self.user_profile,+ message,+ stream,+ "final_topic",+ propagate_mode,+ True,+ True,+ None,+ None,+ set(),+ None,+ ),+ state_change_expected=True,+ # Skip "update_message_flags" to exercise the code path+ # where raw_unread_msgs does not exist in the state.+ event_types=["message", "update_message"],+ # There are 3 events generated for this action+ # * update_message: For updating existing messages+ # * 2 new message events: Breadcrumb messages in the new and old topics.+ num_events=3,+ )+ check_update_message(+ "events[0]",+ events[0],+ is_stream_message=True,+ has_content=False,+ has_topic=True,+ has_new_stream_id=True,+ is_embedded_update_only=False,+ )+def test_update_message_flags(self) -> None:# Test message flag update eventsmessage = self.send_personal_message(