Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

message_edit: Don't rely on .recipient_id change not affecting recipient.

Mateusz Mandera3623681d3037
diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py
index b7071c12dfa..554c6745e4a 100644
--- a/zerver/lib/actions.py
+++ b/zerver/lib/actions.py
@@ -4680,6 +4680,7 @@ def do_update_message(user_profile: UserProfile, message: Message,
event["propagate_mode"] = propagate_mode
event["stream_id"] = message.recipient.type_id
+ old_recipient_id = None
if new_stream is not None:
assert content is None
assert message.is_stream_message()
@@ -4687,6 +4688,7 @@ def do_update_message(user_profile: UserProfile, message: Message,
edit_history_event['prev_stream'] = stream_being_edited.id
event[ORIG_TOPIC] = orig_topic_name
+ old_recipient_id = message.recipient_id
message.recipient_id = new_stream.recipient_id
event["new_stream_id"] = new_stream.id
@@ -4751,6 +4753,7 @@ def do_update_message(user_profile: UserProfile, message: Message,
orig_topic_name=orig_topic_name,
topic_name=topic_name,
new_stream=new_stream,
+ old_recipient_id=old_recipient_id,
edit_history_event=edit_history_event,
last_edit_time=timestamp
)
diff --git a/zerver/lib/topic.py b/zerver/lib/topic.py
index 79df3b079a0..2862754d5f4 100644
--- a/zerver/lib/topic.py
+++ b/zerver/lib/topic.py
@@ -111,10 +111,17 @@ def update_messages_for_topic_edit(message: Message,
orig_topic_name: str,
topic_name: Optional[str],
new_stream: Optional[Stream],
+ old_recipient_id: Optional[int],
edit_history_event: Dict[str, Any],
last_edit_time: datetime) -> List[Message]:
+ assert (new_stream and old_recipient_id) or (not new_stream and not old_recipient_id)
- propagate_query = Q(recipient = message.recipient, subject__iexact = orig_topic_name)
+ if old_recipient_id is not None:
+ recipient_id = old_recipient_id
+ else:
+ recipient_id = message.recipient_id
+
+ propagate_query = Q(recipient_id = recipient_id, subject__iexact = orig_topic_name)
if propagate_mode == 'change_all':
propagate_query = propagate_query & ~Q(id = message.id)
if propagate_mode == 'change_later':