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: Fix moved msg not updated when user not sub of new stream.

Aman Agrawal6801c6de7b85
diff --git a/zerver/actions/message_edit.py b/zerver/actions/message_edit.py
index 37026e5bbab..e04e2107ac5 100644
--- a/zerver/actions/message_edit.py
+++ b/zerver/actions/message_edit.py
@@ -876,6 +876,24 @@ def do_update_message(
return subs
+ old_stream_subs_not_in_new_stream = set()
+ if message_edit_request.is_stream_edited:
+ # We also need to include users who are not subscribed to new stream
+ # but are subscribed to the old stream.
+ old_stream_subscriptions = get_active_subscriptions_for_stream_id(
+ stream_being_edited.id, include_deactivated_users=False
+ )
+ old_stream_subscriptions = exclude_duplicates_from_subscription(
+ old_stream_subscriptions
+ )
+ old_stream_subscriber_ids = set(
+ old_stream_subscriptions.values_list("user_profile_id", flat=True)
+ )
+ new_stream_subscriber_ids = set(subscriptions.values_list("user_profile_id", flat=True))
+ old_stream_subs_not_in_new_stream = old_stream_subscriber_ids.difference(
+ new_stream_subscriber_ids
+ )
+
subscriptions = exclude_duplicates_from_subscription(subscriptions)
if message_edit_request.is_stream_edited:
# TODO: Guest users don't see the new moved topic
@@ -901,7 +919,8 @@ def do_update_message(
)
subscriber_ids = set(subscriptions.values_list("user_profile_id", flat=True))
- users_to_be_notified += map(subscriber_info, sorted(subscriber_ids))
+ notifiable_ids = subscriber_ids.union(old_stream_subs_not_in_new_stream)
+ users_to_be_notified += map(subscriber_info, sorted(notifiable_ids))
# UserTopic updates and the content of notifications depend on
# whether we've moved the entire topic, or just part of it. We
diff --git a/zerver/tests/test_message_move_stream.py b/zerver/tests/test_message_move_stream.py
index ae1c6f4bb02..b9b5c891de3 100644
--- a/zerver/tests/test_message_move_stream.py
+++ b/zerver/tests/test_message_move_stream.py
@@ -1211,7 +1211,7 @@ class MessageMoveStreamTest(ZulipTestCase):
"iago", "test move stream", "new stream", "test"
)
- with self.assert_database_query_count(59), self.assert_memcached_count(14):
+ with self.assert_database_query_count(61), self.assert_memcached_count(14):
result = self.client_patch(
f"/json/messages/{msg_id}",
{
diff --git a/zerver/tests/test_message_move_topic.py b/zerver/tests/test_message_move_topic.py
index 379fbe3c850..84a648c0d3d 100644
--- a/zerver/tests/test_message_move_topic.py
+++ b/zerver/tests/test_message_move_topic.py
@@ -431,7 +431,7 @@ class MessageMoveTopicTest(ZulipTestCase):
set_topic_visibility_policy(desdemona, muted_topics, UserTopic.VisibilityPolicy.MUTED)
set_topic_visibility_policy(cordelia, muted_topics, UserTopic.VisibilityPolicy.MUTED)
- with self.assert_database_query_count(29):
+ with self.assert_database_query_count(31):
check_update_message(
user_profile=desdemona,
message_id=message_id,
@@ -461,7 +461,7 @@ class MessageMoveTopicTest(ZulipTestCase):
]
set_topic_visibility_policy(desdemona, muted_topics, UserTopic.VisibilityPolicy.MUTED)
set_topic_visibility_policy(cordelia, muted_topics, UserTopic.VisibilityPolicy.MUTED)
- with self.assert_database_query_count(34):
+ with self.assert_database_query_count(36):
check_update_message(
user_profile=desdemona,
message_id=message_id,
@@ -494,7 +494,7 @@ class MessageMoveTopicTest(ZulipTestCase):
set_topic_visibility_policy(desdemona, muted_topics, UserTopic.VisibilityPolicy.MUTED)
set_topic_visibility_policy(cordelia, muted_topics, UserTopic.VisibilityPolicy.MUTED)
- with self.assert_database_query_count(31):
+ with self.assert_database_query_count(33):
check_update_message(
user_profile=desdemona,
message_id=message_id,
@@ -517,7 +517,7 @@ class MessageMoveTopicTest(ZulipTestCase):
second_message_id = self.send_stream_message(
hamlet, stream_name, topic_name="changed topic name", content="Second message"
)
- with self.assert_database_query_count(24):
+ with self.assert_database_query_count(26):
check_update_message(
user_profile=desdemona,
message_id=second_message_id,