mirror of https://github.com/zulip/zulip.git
message send: Plumb sender muters through `get_recipient_info`.
This will make it possible to share this code with the message update codepath.
This commit is contained in:
parent
4822bd0822
commit
006b92ed6d
|
@ -1423,6 +1423,7 @@ class RecipientInfoResult(TypedDict):
|
|||
stream_email_user_ids: Set[int]
|
||||
stream_push_user_ids: Set[int]
|
||||
wildcard_mention_user_ids: Set[int]
|
||||
muted_sender_user_ids: Set[int]
|
||||
um_eligible_user_ids: Set[int]
|
||||
long_term_idle_user_ids: Set[int]
|
||||
default_bot_user_ids: Set[int]
|
||||
|
@ -1441,6 +1442,7 @@ def get_recipient_info(
|
|||
stream_push_user_ids: Set[int] = set()
|
||||
stream_email_user_ids: Set[int] = set()
|
||||
wildcard_mention_user_ids: Set[int] = set()
|
||||
muted_sender_user_ids: Set[int] = get_muting_users(sender_id)
|
||||
|
||||
if recipient.type == Recipient.PERSONAL:
|
||||
# The sender and recipient may be the same id, so
|
||||
|
@ -1621,6 +1623,7 @@ def get_recipient_info(
|
|||
stream_push_user_ids=stream_push_user_ids,
|
||||
stream_email_user_ids=stream_email_user_ids,
|
||||
wildcard_mention_user_ids=wildcard_mention_user_ids,
|
||||
muted_sender_user_ids=muted_sender_user_ids,
|
||||
um_eligible_user_ids=um_eligible_user_ids,
|
||||
long_term_idle_user_ids=long_term_idle_user_ids,
|
||||
default_bot_user_ids=default_bot_user_ids,
|
||||
|
@ -1813,6 +1816,7 @@ def build_message_send_dict(
|
|||
online_push_user_ids=info["online_push_user_ids"],
|
||||
stream_push_user_ids=info["stream_push_user_ids"],
|
||||
stream_email_user_ids=info["stream_email_user_ids"],
|
||||
muted_sender_user_ids=info["muted_sender_user_ids"],
|
||||
um_eligible_user_ids=info["um_eligible_user_ids"],
|
||||
long_term_idle_user_ids=info["long_term_idle_user_ids"],
|
||||
default_bot_user_ids=info["default_bot_user_ids"],
|
||||
|
@ -1862,7 +1866,7 @@ def do_send_messages(
|
|||
mentioned_user_ids = send_request.message.mentions_user_ids
|
||||
|
||||
# Extend the set with users who have muted the sender.
|
||||
mark_as_read_for_users = get_muting_users(send_request.message.sender_id)
|
||||
mark_as_read_for_users = send_request.muted_sender_user_ids
|
||||
mark_as_read_for_users.update(mark_as_read)
|
||||
|
||||
user_messages = create_user_messages(
|
||||
|
|
|
@ -98,6 +98,7 @@ class SendMessageRequest:
|
|||
online_push_user_ids: Set[int]
|
||||
stream_push_user_ids: Set[int]
|
||||
stream_email_user_ids: Set[int]
|
||||
muted_sender_user_ids: Set[int]
|
||||
um_eligible_user_ids: Set[int]
|
||||
long_term_idle_user_ids: Set[int]
|
||||
default_bot_user_ids: Set[int]
|
||||
|
|
|
@ -19,6 +19,7 @@ from zerver.lib.actions import (
|
|||
do_deactivate_user,
|
||||
do_delete_user,
|
||||
do_invite_users,
|
||||
do_mute_user,
|
||||
do_reactivate_user,
|
||||
do_set_realm_property,
|
||||
get_emails_from_user_ids,
|
||||
|
@ -1518,6 +1519,7 @@ class RecipientInfoTest(ZulipTestCase):
|
|||
stream_push_user_ids=set(),
|
||||
stream_email_user_ids=set(),
|
||||
wildcard_mention_user_ids=set(),
|
||||
muted_sender_user_ids=set(),
|
||||
um_eligible_user_ids=all_user_ids,
|
||||
long_term_idle_user_ids=set(),
|
||||
default_bot_user_ids=set(),
|
||||
|
@ -1573,7 +1575,7 @@ class RecipientInfoTest(ZulipTestCase):
|
|||
)
|
||||
self.assertEqual(info["stream_push_user_ids"], {hamlet.id})
|
||||
|
||||
# Now mute Hamlet to omit him from stream_push_user_ids.
|
||||
# Now have Hamlet mute the topic to omit him from stream_push_user_ids.
|
||||
add_topic_mute(
|
||||
user_profile=hamlet,
|
||||
stream_id=stream.id,
|
||||
|
@ -1603,6 +1605,18 @@ class RecipientInfoTest(ZulipTestCase):
|
|||
# wildcard notifications, it should just be Othello here.
|
||||
self.assertEqual(info["wildcard_mention_user_ids"], {othello.id})
|
||||
|
||||
# If Hamlet mutes Cordelia, he should be in `muted_sender_user_ids` for a message
|
||||
# sent by Cordelia.
|
||||
do_mute_user(hamlet, cordelia)
|
||||
info = get_recipient_info(
|
||||
realm_id=realm.id,
|
||||
recipient=recipient,
|
||||
sender_id=cordelia.id,
|
||||
stream_topic=stream_topic,
|
||||
possible_wildcard_mention=True,
|
||||
)
|
||||
self.assertTrue(hamlet.id in info["muted_sender_user_ids"])
|
||||
|
||||
sub = get_subscription(stream_name, othello)
|
||||
sub.wildcard_mentions_notify = False
|
||||
sub.save()
|
||||
|
|
Loading…
Reference in New Issue