From 02f3f73b0c8664624fbde2dd2bee497e048b763b Mon Sep 17 00:00:00 2001 From: Prakhar Pratyush Date: Sat, 19 Aug 2023 15:34:27 +0530 Subject: [PATCH] recipient_info: Include 'sender_id' in 'topic_participant_user_ids'. This commit includes the message's sender id in the 'topic_participant_user_ids' set. The 'participants_for_topic' function doesn't include the sender_id, if the user is sending their first message in the topic, because 'participants_for_topic' queries the 'Message' table, but the message is actually sent at a later stage in the codepath, resulting in missing the sender_id in this case. This is needed to set the 'wildcard_mentioned' flag for the sender's user message in the case of topic wildcard mentions. This doesn't lead to sending email and push notifications to the sender because we have a check to skip notifications if the user to receive notifications is the sender itself. This should have been included in c0c30bc. --- zerver/actions/message_send.py | 5 +++++ zerver/tests/test_users.py | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/zerver/actions/message_send.py b/zerver/actions/message_send.py index d6f5663729..0dcacf122c 100644 --- a/zerver/actions/message_send.py +++ b/zerver/actions/message_send.py @@ -239,6 +239,11 @@ def get_recipient_info( topic_participant_user_ids = participants_for_topic( realm_id, recipient.id, stream_topic.topic_name ) + # We explicitly include the sender as a topic participant because the message will + # be actually sent at a later stage in this codepath, so `participants_for_topic` + # misses this sender. This is useful when the sender is sending their first message + # in the topic. + topic_participant_user_ids.add(sender_id) subscription_rows = ( get_subscriptions_for_send_message( realm_id=realm_id, diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index 5f79c52417..31adb70644 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -1967,11 +1967,13 @@ class RecipientInfoTest(ZulipTestCase): possible_stream_wildcard_mention=False, ) self.assertEqual(info.stream_wildcard_mention_user_ids, set()) - self.assertEqual(info.topic_wildcard_mention_user_ids, set()) + self.assertEqual(info.topic_wildcard_mention_user_ids, {hamlet.id}) # User who sent a message to the topic, or reacted to a message on the topic # is only considered as a possible user to be notified for topic mention. - self.send_stream_message(hamlet, stream_name, content="test message", topic_name=topic_name) + self.send_stream_message( + othello, stream_name, content="test message", topic_name=topic_name + ) info = get_recipient_info( realm_id=realm.id, recipient=recipient, @@ -1981,7 +1983,7 @@ class RecipientInfoTest(ZulipTestCase): possible_stream_wildcard_mention=False, ) self.assertEqual(info.stream_wildcard_mention_user_ids, set()) - self.assertEqual(info.topic_wildcard_mention_user_ids, {hamlet.id}) + self.assertEqual(info.topic_wildcard_mention_user_ids, {hamlet.id, othello.id}) info = get_recipient_info( realm_id=realm.id, @@ -2003,7 +2005,7 @@ class RecipientInfoTest(ZulipTestCase): possible_stream_wildcard_mention=True, ) self.assertEqual(info.stream_wildcard_mention_user_ids, {hamlet.id, othello.id}) - self.assertEqual(info.topic_wildcard_mention_user_ids, {hamlet.id}) + self.assertEqual(info.topic_wildcard_mention_user_ids, {hamlet.id, othello.id}) sub = get_subscription(stream_name, hamlet) sub.push_notifications = False