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.
This commit is contained in:
Prakhar Pratyush 2023-08-19 15:34:27 +05:30 committed by Tim Abbott
parent b274169ccc
commit 02f3f73b0c
2 changed files with 11 additions and 4 deletions

View File

@ -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,

View File

@ -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