mention: Replace 'wildcards' with 'stream_wildcards'.

This prep commit replaces the 'wildcard' keyword in the codebase
with 'stream_wildcard' at some places for better readability, as
we plan to introduce 'topic_wildcards' as a part of the
'@topic mention' project.

Currently, 'wildcards = ["all", "everyone", "stream"]' which is an
alias to mention everyone in the stream, hence better renamed as
'stream_wildcards'.

Eventually, we will have:
'stream_wildcard' as an alias to mention everyone in the stream.
'topic_wildcard' as an alias to mention everyone in the topic.
'wildcard' refers to 'stream_wildcard' and 'topic_wildcard' as a whole.
This commit is contained in:
Prakhar Pratyush 2023-06-03 20:21:38 +05:30 committed by Tim Abbott
parent d80779435a
commit 179d5cb37d
28 changed files with 444 additions and 320 deletions

View File

@ -29,9 +29,9 @@
{% trans %}You are receiving this because you were personally mentioned.{% endtrans %}<br /> {% trans %}You are receiving this because you were personally mentioned.{% endtrans %}<br />
{% elif mentioned_user_group_name %} {% elif mentioned_user_group_name %}
{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}<br /> {% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}<br />
{% elif followed_topic_wildcard_mentioned %} {% elif stream_wildcard_mentioned_in_followed_topic %}
{% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %}<br /> {% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %}<br />
{% elif wildcard_mentioned %} {% elif stream_wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}<br /> {% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}<br />
{% elif followed_topic_email_notify %} {% elif followed_topic_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %}<br /> {% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %}<br />

View File

@ -25,9 +25,9 @@ See {{ alert_notif_url }} for more details.
{% trans %}You are receiving this because you were personally mentioned.{% endtrans %} {% trans %}You are receiving this because you were personally mentioned.{% endtrans %}
{% elif mentioned_user_group_name %} {% elif mentioned_user_group_name %}
{% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %} {% trans %}You are receiving this because @{{ mentioned_user_group_name }} was mentioned.{% endtrans %}
{% elif followed_topic_wildcard_mentioned %} {% elif stream_wildcard_mentioned_in_followed_topic %}
{% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %} {% trans %}You are receiving this because you have wildcard mention notifications enabled for topics you follow.{% endtrans %}
{% elif wildcard_mentioned %} {% elif stream_wildcard_mentioned %}
{% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %} {% trans %}You are receiving this because everyone was mentioned in #{{ stream_name }}.{% endtrans %}
{% elif followed_topic_email_notify %} {% elif followed_topic_email_notify %}
{% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %} {% trans %}You are receiving this because you have email notifications enabled for topics you follow.{% endtrans %}

View File

@ -258,7 +258,7 @@ def get_mentions_for_message_updates(message_id: int) -> Set[int]:
def update_user_message_flags( def update_user_message_flags(
rendering_result: MessageRenderingResult, ums: Iterable[UserMessage] rendering_result: MessageRenderingResult, ums: Iterable[UserMessage]
) -> None: ) -> None:
wildcard = rendering_result.mentions_wildcard wildcard = rendering_result.mentions_stream_wildcard
mentioned_ids = rendering_result.mentions_user_ids mentioned_ids = rendering_result.mentions_user_ids
ids_with_alert_words = rendering_result.user_ids_with_alert_words ids_with_alert_words = rendering_result.user_ids_with_alert_words
changed_ums: Set[UserMessage] = set() changed_ums: Set[UserMessage] = set()
@ -466,7 +466,7 @@ def do_update_message(
recipient=target_message.recipient, recipient=target_message.recipient,
sender_id=target_message.sender_id, sender_id=target_message.sender_id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=mention_data.message_has_wildcards(), possible_stream_wildcard_mention=mention_data.message_has_stream_wildcards(),
) )
event["online_push_user_ids"] = list(info.online_push_user_ids) event["online_push_user_ids"] = list(info.online_push_user_ids)
@ -480,14 +480,14 @@ def do_update_message(
event["prior_mention_user_ids"] = list(prior_mention_user_ids) event["prior_mention_user_ids"] = list(prior_mention_user_ids)
event["presence_idle_user_ids"] = filter_presence_idle_user_ids(info.active_user_ids) event["presence_idle_user_ids"] = filter_presence_idle_user_ids(info.active_user_ids)
event["all_bot_user_ids"] = list(info.all_bot_user_ids) event["all_bot_user_ids"] = list(info.all_bot_user_ids)
if rendering_result.mentions_wildcard: if rendering_result.mentions_stream_wildcard:
event["wildcard_mention_user_ids"] = list(info.wildcard_mention_user_ids) event["stream_wildcard_mention_user_ids"] = list(info.stream_wildcard_mention_user_ids)
event["followed_topic_wildcard_mention_user_ids"] = list( event["stream_wildcard_mention_in_followed_topic_user_ids"] = list(
info.followed_topic_wildcard_mention_user_ids info.stream_wildcard_mention_in_followed_topic_user_ids
) )
else: else:
event["wildcard_mention_user_ids"] = [] event["stream_wildcard_mention_user_ids"] = []
event["followed_topic_wildcard_mention_user_ids"] = [] event["stream_wildcard_mention_in_followed_topic_user_ids"] = []
do_update_mobile_push_notification( do_update_mobile_push_notification(
target_message, target_message,
@ -1248,7 +1248,7 @@ def check_update_message(
) )
links_for_embed |= rendering_result.links_for_preview links_for_embed |= rendering_result.links_for_preview
if message.is_stream_message() and rendering_result.mentions_wildcard: if message.is_stream_message() and rendering_result.mentions_stream_wildcard:
stream = access_stream_by_id(user_profile, message.recipient.type_id)[0] stream = access_stream_by_id(user_profile, message.recipient.type_id)[0]
if not wildcard_mention_allowed(message.sender, stream): if not wildcard_mention_allowed(message.sender, stream):
raise JsonableError( raise JsonableError(

View File

@ -166,10 +166,10 @@ class RecipientInfoResult:
pm_mention_push_disabled_user_ids: Set[int] pm_mention_push_disabled_user_ids: Set[int]
stream_email_user_ids: Set[int] stream_email_user_ids: Set[int]
stream_push_user_ids: Set[int] stream_push_user_ids: Set[int]
wildcard_mention_user_ids: Set[int] stream_wildcard_mention_user_ids: Set[int]
followed_topic_email_user_ids: Set[int] followed_topic_email_user_ids: Set[int]
followed_topic_push_user_ids: Set[int] followed_topic_push_user_ids: Set[int]
followed_topic_wildcard_mention_user_ids: Set[int] stream_wildcard_mention_in_followed_topic_user_ids: Set[int]
muted_sender_user_ids: Set[int] muted_sender_user_ids: Set[int]
um_eligible_user_ids: Set[int] um_eligible_user_ids: Set[int]
long_term_idle_user_ids: Set[int] long_term_idle_user_ids: Set[int]
@ -195,14 +195,14 @@ def get_recipient_info(
sender_id: int, sender_id: int,
stream_topic: Optional[StreamTopicTarget], stream_topic: Optional[StreamTopicTarget],
possibly_mentioned_user_ids: AbstractSet[int] = set(), possibly_mentioned_user_ids: AbstractSet[int] = set(),
possible_wildcard_mention: bool = True, possible_stream_wildcard_mention: bool = True,
) -> RecipientInfoResult: ) -> RecipientInfoResult:
stream_push_user_ids: Set[int] = set() stream_push_user_ids: Set[int] = set()
stream_email_user_ids: Set[int] = set() stream_email_user_ids: Set[int] = set()
wildcard_mention_user_ids: Set[int] = set() stream_wildcard_mention_user_ids: Set[int] = set()
followed_topic_push_user_ids: Set[int] = set() followed_topic_push_user_ids: Set[int] = set()
followed_topic_email_user_ids: Set[int] = set() followed_topic_email_user_ids: Set[int] = set()
followed_topic_wildcard_mention_user_ids: Set[int] = set() stream_wildcard_mention_in_followed_topic_user_ids: Set[int] = set()
muted_sender_user_ids: Set[int] = get_muting_users(sender_id) muted_sender_user_ids: Set[int] = get_muting_users(sender_id)
if recipient.type == Recipient.PERSONAL: if recipient.type == Recipient.PERSONAL:
@ -222,7 +222,7 @@ def get_recipient_info(
realm_id=realm_id, realm_id=realm_id,
stream_id=stream_topic.stream_id, stream_id=stream_topic.stream_id,
topic_name=stream_topic.topic_name, topic_name=stream_topic.topic_name,
possible_wildcard_mention=possible_wildcard_mention, possible_stream_wildcard_mention=possible_stream_wildcard_mention,
possibly_mentioned_user_ids=possibly_mentioned_user_ids, possibly_mentioned_user_ids=possibly_mentioned_user_ids,
) )
.annotate( .annotate(
@ -293,14 +293,14 @@ def get_recipient_info(
) )
followed_topic_push_user_ids = followed_topic_notification_recipients("push_notifications") followed_topic_push_user_ids = followed_topic_notification_recipients("push_notifications")
if possible_wildcard_mention: if possible_stream_wildcard_mention:
# We calculate `wildcard_mention_user_ids` and `followed_topic_wildcard_mention_user_ids` # We calculate `stream_wildcard_mention_user_ids` and `followed_topic_wildcard_mention_user_ids`
# only if there's a possible wildcard mention in the message. This is important so as # only if there's a possible stream wildcard mention in the message. This is important so as
# to avoid unnecessarily sending huge user ID lists with thousands of elements to the # to avoid unnecessarily sending huge user ID lists with thousands of elements to the
# event queue (which can happen because these settings are `True` by default for new users.) # event queue (which can happen because these settings are `True` by default for new users.)
wildcard_mention_user_ids = notification_recipients("wildcard_mentions_notify") stream_wildcard_mention_user_ids = notification_recipients("wildcard_mentions_notify")
followed_topic_wildcard_mention_user_ids = followed_topic_notification_recipients( stream_wildcard_mention_in_followed_topic_user_ids = (
"wildcard_mentions_notify" followed_topic_notification_recipients("wildcard_mentions_notify")
) )
elif recipient.type == Recipient.HUDDLE: elif recipient.type == Recipient.HUDDLE:
@ -418,10 +418,10 @@ def get_recipient_info(
pm_mention_push_disabled_user_ids=pm_mention_push_disabled_user_ids, pm_mention_push_disabled_user_ids=pm_mention_push_disabled_user_ids,
stream_push_user_ids=stream_push_user_ids, stream_push_user_ids=stream_push_user_ids,
stream_email_user_ids=stream_email_user_ids, stream_email_user_ids=stream_email_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids, stream_wildcard_mention_user_ids=stream_wildcard_mention_user_ids,
followed_topic_push_user_ids=followed_topic_push_user_ids, followed_topic_push_user_ids=followed_topic_push_user_ids,
followed_topic_email_user_ids=followed_topic_email_user_ids, followed_topic_email_user_ids=followed_topic_email_user_ids,
followed_topic_wildcard_mention_user_ids=followed_topic_wildcard_mention_user_ids, stream_wildcard_mention_in_followed_topic_user_ids=stream_wildcard_mention_in_followed_topic_user_ids,
muted_sender_user_ids=muted_sender_user_ids, muted_sender_user_ids=muted_sender_user_ids,
um_eligible_user_ids=um_eligible_user_ids, um_eligible_user_ids=um_eligible_user_ids,
long_term_idle_user_ids=long_term_idle_user_ids, long_term_idle_user_ids=long_term_idle_user_ids,
@ -541,7 +541,7 @@ def build_message_send_dict(
sender_id=message.sender_id, sender_id=message.sender_id,
stream_topic=stream_topic, stream_topic=stream_topic,
possibly_mentioned_user_ids=mention_data.get_user_ids(), possibly_mentioned_user_ids=mention_data.get_user_ids(),
possible_wildcard_mention=mention_data.message_has_wildcards(), possible_stream_wildcard_mention=mention_data.message_has_stream_wildcards(),
) )
# Render our message_dicts. # Render our message_dicts.
@ -570,16 +570,18 @@ def build_message_send_dict(
members = mention_data.get_group_members(group_id) members = mention_data.get_group_members(group_id)
rendering_result.mentions_user_ids.update(members) rendering_result.mentions_user_ids.update(members)
# Only send data to Tornado about wildcard mentions if message # Only send data to Tornado about stream wildcard mentions if message
# rendering determined the message had an actual wildcard # rendering determined the message had an actual stream wildcard
# mention in it (and not e.g. wildcard mention syntax inside a # mention in it (and not e.g. stream wildcard mention syntax inside a
# code block). # code block).
if rendering_result.mentions_wildcard: if rendering_result.mentions_stream_wildcard:
wildcard_mention_user_ids = info.wildcard_mention_user_ids stream_wildcard_mention_user_ids = info.stream_wildcard_mention_user_ids
followed_topic_wildcard_mention_user_ids = info.followed_topic_wildcard_mention_user_ids stream_wildcard_mention_in_followed_topic_user_ids = (
info.stream_wildcard_mention_in_followed_topic_user_ids
)
else: else:
wildcard_mention_user_ids = set() stream_wildcard_mention_user_ids = set()
followed_topic_wildcard_mention_user_ids = set() stream_wildcard_mention_in_followed_topic_user_ids = set()
""" """
Once we have the actual list of mentioned ids from message Once we have the actual list of mentioned ids from message
@ -615,8 +617,8 @@ def build_message_send_dict(
default_bot_user_ids=info.default_bot_user_ids, default_bot_user_ids=info.default_bot_user_ids,
service_bot_tuples=info.service_bot_tuples, service_bot_tuples=info.service_bot_tuples,
all_bot_user_ids=info.all_bot_user_ids, all_bot_user_ids=info.all_bot_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids, stream_wildcard_mention_user_ids=stream_wildcard_mention_user_ids,
followed_topic_wildcard_mention_user_ids=followed_topic_wildcard_mention_user_ids, stream_wildcard_mention_in_followed_topic_user_ids=stream_wildcard_mention_in_followed_topic_user_ids,
links_for_embed=links_for_embed, links_for_embed=links_for_embed,
widget_content=widget_content_dict, widget_content=widget_content_dict,
limit_unread_user_ids=limit_unread_user_ids, limit_unread_user_ids=limit_unread_user_ids,
@ -647,7 +649,7 @@ def create_user_messages(
is_stream_message = message.is_stream_message() is_stream_message = message.is_stream_message()
base_flags = 0 base_flags = 0
if rendering_result.mentions_wildcard: if rendering_result.mentions_stream_wildcard:
base_flags |= UserMessage.flags.wildcard_mentioned base_flags |= UserMessage.flags.wildcard_mentioned
if message.recipient.type in [Recipient.HUDDLE, Recipient.PERSONAL]: if message.recipient.type in [Recipient.HUDDLE, Recipient.PERSONAL]:
base_flags |= UserMessage.flags.is_private base_flags |= UserMessage.flags.is_private
@ -912,10 +914,10 @@ def do_send_messages(
pm_mention_email_disabled_user_ids=send_request.pm_mention_email_disabled_user_ids, pm_mention_email_disabled_user_ids=send_request.pm_mention_email_disabled_user_ids,
stream_push_user_ids=send_request.stream_push_user_ids, stream_push_user_ids=send_request.stream_push_user_ids,
stream_email_user_ids=send_request.stream_email_user_ids, stream_email_user_ids=send_request.stream_email_user_ids,
wildcard_mention_user_ids=send_request.wildcard_mention_user_ids, stream_wildcard_mention_user_ids=send_request.stream_wildcard_mention_user_ids,
followed_topic_push_user_ids=send_request.followed_topic_push_user_ids, followed_topic_push_user_ids=send_request.followed_topic_push_user_ids,
followed_topic_email_user_ids=send_request.followed_topic_email_user_ids, followed_topic_email_user_ids=send_request.followed_topic_email_user_ids,
followed_topic_wildcard_mention_user_ids=send_request.followed_topic_wildcard_mention_user_ids, stream_wildcard_mention_in_followed_topic_user_ids=send_request.stream_wildcard_mention_in_followed_topic_user_ids,
muted_sender_user_ids=send_request.muted_sender_user_ids, muted_sender_user_ids=send_request.muted_sender_user_ids,
all_bot_user_ids=send_request.all_bot_user_ids, all_bot_user_ids=send_request.all_bot_user_ids,
) )
@ -940,11 +942,11 @@ def do_send_messages(
), ),
stream_push_user_ids=list(send_request.stream_push_user_ids), stream_push_user_ids=list(send_request.stream_push_user_ids),
stream_email_user_ids=list(send_request.stream_email_user_ids), stream_email_user_ids=list(send_request.stream_email_user_ids),
wildcard_mention_user_ids=list(send_request.wildcard_mention_user_ids), stream_wildcard_mention_user_ids=list(send_request.stream_wildcard_mention_user_ids),
followed_topic_push_user_ids=list(send_request.followed_topic_push_user_ids), followed_topic_push_user_ids=list(send_request.followed_topic_push_user_ids),
followed_topic_email_user_ids=list(send_request.followed_topic_email_user_ids), followed_topic_email_user_ids=list(send_request.followed_topic_email_user_ids),
followed_topic_wildcard_mention_user_ids=list( stream_wildcard_mention_in_followed_topic_user_ids=list(
send_request.followed_topic_wildcard_mention_user_ids send_request.stream_wildcard_mention_in_followed_topic_user_ids
), ),
muted_sender_user_ids=list(send_request.muted_sender_user_ids), muted_sender_user_ids=list(send_request.muted_sender_user_ids),
all_bot_user_ids=list(send_request.all_bot_user_ids), all_bot_user_ids=list(send_request.all_bot_user_ids),
@ -1481,7 +1483,7 @@ def check_message(
if ( if (
stream is not None stream is not None
and message_send_dict.rendering_result.mentions_wildcard and message_send_dict.rendering_result.mentions_stream_wildcard
and not wildcard_mention_allowed(sender, stream) and not wildcard_mention_allowed(sender, stream)
): ):
raise JsonableError( raise JsonableError(

View File

@ -456,13 +456,14 @@ def do_send_missedmessage_events_reply_in_zulip(
context.update( context.update(
mention="mentioned" in unique_triggers mention="mentioned" in unique_triggers
or "wildcard_mentioned" in unique_triggers or "stream_wildcard_mentioned" in unique_triggers
or "followed_topic_wildcard_mentioned" in unique_triggers, or "stream_wildcard_mentioned_in_followed_topic" in unique_triggers,
personal_mentioned=personal_mentioned, personal_mentioned=personal_mentioned,
wildcard_mentioned="wildcard_mentioned" in unique_triggers, stream_wildcard_mentioned="stream_wildcard_mentioned" in unique_triggers,
stream_email_notify="stream_email_notify" in unique_triggers, stream_email_notify="stream_email_notify" in unique_triggers,
followed_topic_email_notify="followed_topic_email_notify" in unique_triggers, followed_topic_email_notify="followed_topic_email_notify" in unique_triggers,
followed_topic_wildcard_mentioned="followed_topic_wildcard_mentioned" in unique_triggers, stream_wildcard_mentioned_in_followed_topic="stream_wildcard_mentioned_in_followed_topic"
in unique_triggers,
mentioned_user_group_name=mentioned_user_group_name, mentioned_user_group_name=mentioned_user_group_name,
) )
@ -525,8 +526,9 @@ def do_send_missedmessage_events_reply_in_zulip(
m["message"].sender m["message"].sender
for m in missed_messages for m in missed_messages
if m["trigger"] == NotificationTriggers.MENTION if m["trigger"] == NotificationTriggers.MENTION
or m["trigger"] == NotificationTriggers.WILDCARD_MENTION or m["trigger"] == NotificationTriggers.STREAM_WILDCARD_MENTION
or m["trigger"] == NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION or m["trigger"]
== NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
} }
) )
message = missed_messages[0]["message"] message = missed_messages[0]["message"]

View File

@ -113,7 +113,7 @@ class LinkInfo(TypedDict):
@dataclass @dataclass
class MessageRenderingResult: class MessageRenderingResult:
rendered_content: str rendered_content: str
mentions_wildcard: bool mentions_stream_wildcard: bool
mentions_user_ids: Set[int] mentions_user_ids: Set[int]
mentions_user_group_ids: Set[int] mentions_user_group_ids: Set[int]
alert_words: Set[str] alert_words: Set[str]
@ -1776,7 +1776,7 @@ class UserMentionPattern(CompiledInlineProcessor):
silent = m.group("silent") == "_" silent = m.group("silent") == "_"
db_data: Optional[DbData] = self.zmd.zulip_db_data db_data: Optional[DbData] = self.zmd.zulip_db_data
if db_data is not None: if db_data is not None:
wildcard = mention.user_mention_matches_wildcard(name) stream_wildcard = mention.user_mention_matches_stream_wildcard(name)
# For @**|id** and @**name|id** mention syntaxes. # For @**|id** and @**name|id** mention syntaxes.
id_syntax_match = re.match(r"(?P<full_name>.+)?\|(?P<user_id>\d+)$", name) id_syntax_match = re.match(r"(?P<full_name>.+)?\|(?P<user_id>\d+)$", name)
@ -1795,9 +1795,9 @@ class UserMentionPattern(CompiledInlineProcessor):
# For @**name** syntax. # For @**name** syntax.
user = db_data.mention_data.get_user_by_name(name) user = db_data.mention_data.get_user_by_name(name)
if wildcard: if stream_wildcard:
if not silent: if not silent:
self.zmd.zulip_rendering_result.mentions_wildcard = True self.zmd.zulip_rendering_result.mentions_stream_wildcard = True
user_id = "*" user_id = "*"
elif user is not None: elif user is not None:
assert isinstance(user, FullNameInfo) assert isinstance(user, FullNameInfo)
@ -2491,7 +2491,7 @@ def do_convert(
# Filters such as UserMentionPattern need a message. # Filters such as UserMentionPattern need a message.
rendering_result: MessageRenderingResult = MessageRenderingResult( rendering_result: MessageRenderingResult = MessageRenderingResult(
rendered_content="", rendered_content="",
mentions_wildcard=False, mentions_stream_wildcard=False,
mentions_user_ids=set(), mentions_user_ids=set(),
mentions_user_group_ids=set(), mentions_user_group_ids=set(),
alert_words=set(), alert_words=set(),

View File

@ -18,7 +18,7 @@ USER_GROUP_MENTIONS_RE = re.compile(
rf"{BEFORE_MENTION_ALLOWED_REGEX}@(?P<silent>_?)(\*(?P<match>[^\*]+)\*)" rf"{BEFORE_MENTION_ALLOWED_REGEX}@(?P<silent>_?)(\*(?P<match>[^\*]+)\*)"
) )
wildcards = frozenset(["all", "everyone", "stream"]) stream_wildcards = frozenset(["all", "everyone", "stream"])
@dataclass @dataclass
@ -46,13 +46,13 @@ class UserFilter:
@dataclass @dataclass
class MentionText: class MentionText:
text: Optional[str] text: Optional[str]
is_wildcard: bool is_stream_wildcard: bool
@dataclass @dataclass
class PossibleMentions: class PossibleMentions:
mention_texts: Set[str] mention_texts: Set[str]
message_has_wildcards: bool message_has_stream_wildcards: bool
class MentionBackend: class MentionBackend:
@ -147,29 +147,31 @@ class MentionBackend:
return result return result
def user_mention_matches_wildcard(mention: str) -> bool: def user_mention_matches_stream_wildcard(mention: str) -> bool:
return mention in wildcards return mention in stream_wildcards
def extract_mention_text(m: Match[str]) -> MentionText: def extract_mention_text(m: Match[str]) -> MentionText:
text = m.group("match") text = m.group("match")
if text in wildcards: if text in stream_wildcards:
return MentionText(text=None, is_wildcard=True) return MentionText(text=None, is_stream_wildcard=True)
return MentionText(text=text, is_wildcard=False) return MentionText(text=text, is_stream_wildcard=False)
def possible_mentions(content: str) -> PossibleMentions: def possible_mentions(content: str) -> PossibleMentions:
# mention texts can either be names, or an extended name|id syntax. # mention texts can either be names, or an extended name|id syntax.
texts = set() texts = set()
message_has_wildcards = False message_has_stream_wildcards = False
for m in MENTIONS_RE.finditer(content): for m in MENTIONS_RE.finditer(content):
mention_text = extract_mention_text(m) mention_text = extract_mention_text(m)
text = mention_text.text text = mention_text.text
if text: if text:
texts.add(text) texts.add(text)
if mention_text.is_wildcard: if mention_text.is_stream_wildcard:
message_has_wildcards = True message_has_stream_wildcards = True
return PossibleMentions(mention_texts=texts, message_has_wildcards=message_has_wildcards) return PossibleMentions(
mention_texts=texts, message_has_stream_wildcards=message_has_stream_wildcards
)
def possible_user_group_mentions(content: str) -> Set[str]: def possible_user_group_mentions(content: str) -> Set[str]:
@ -213,10 +215,10 @@ class MentionData:
self.full_name_info = {row.full_name.lower(): row for row in possible_mentions_info} self.full_name_info = {row.full_name.lower(): row for row in possible_mentions_info}
self.user_id_info = {row.id: row for row in possible_mentions_info} self.user_id_info = {row.id: row for row in possible_mentions_info}
self.init_user_group_data(realm_id=realm_id, content=content) self.init_user_group_data(realm_id=realm_id, content=content)
self.has_wildcards = mentions.message_has_wildcards self.has_stream_wildcards = mentions.message_has_stream_wildcards
def message_has_wildcards(self) -> bool: def message_has_stream_wildcards(self) -> bool:
return self.has_wildcards return self.has_stream_wildcards
def init_user_group_data(self, realm_id: int, content: str) -> None: def init_user_group_data(self, realm_id: int, content: str) -> None:
self.user_group_name_info: Dict[str, UserGroup] = {} self.user_group_name_info: Dict[str, UserGroup] = {}

View File

@ -168,9 +168,9 @@ class SendMessageRequest:
default_bot_user_ids: Set[int] default_bot_user_ids: Set[int]
service_bot_tuples: List[Tuple[int, int]] service_bot_tuples: List[Tuple[int, int]]
all_bot_user_ids: Set[int] all_bot_user_ids: Set[int]
wildcard_mention_user_ids: Set[int] stream_wildcard_mention_user_ids: Set[int]
# IDs of users who have followed the topic the message is being sent to, and have the followed topic wildcard mentions notify setting ON. # IDs of users who have followed the topic the message (having stream wildcard) is being sent to, and have the followed topic wildcard mentions notify setting ON.
followed_topic_wildcard_mention_user_ids: Set[int] stream_wildcard_mention_in_followed_topic_user_ids: Set[int]
links_for_embed: Set[str] links_for_embed: Set[str]
widget_content: Optional[Dict[str, Any]] widget_content: Optional[Dict[str, Any]]
submessages: List[Dict[str, Any]] = field(default_factory=list) submessages: List[Dict[str, Any]] = field(default_factory=list)

View File

@ -15,14 +15,14 @@ class UserMessageNotificationsData:
pm_push_notify: bool pm_push_notify: bool
mention_email_notify: bool mention_email_notify: bool
mention_push_notify: bool mention_push_notify: bool
wildcard_mention_email_notify: bool stream_wildcard_mention_email_notify: bool
wildcard_mention_push_notify: bool stream_wildcard_mention_push_notify: bool
stream_push_notify: bool stream_push_notify: bool
stream_email_notify: bool stream_email_notify: bool
followed_topic_push_notify: bool followed_topic_push_notify: bool
followed_topic_email_notify: bool followed_topic_email_notify: bool
followed_topic_wildcard_mention_push_notify: bool stream_wildcard_mention_in_followed_topic_push_notify: bool
followed_topic_wildcard_mention_email_notify: bool stream_wildcard_mention_in_followed_topic_email_notify: bool
sender_is_muted: bool sender_is_muted: bool
disable_external_notifications: bool disable_external_notifications: bool
@ -57,10 +57,10 @@ class UserMessageNotificationsData:
pm_mention_email_disabled_user_ids: Set[int], pm_mention_email_disabled_user_ids: Set[int],
stream_push_user_ids: Set[int], stream_push_user_ids: Set[int],
stream_email_user_ids: Set[int], stream_email_user_ids: Set[int],
wildcard_mention_user_ids: Set[int], stream_wildcard_mention_user_ids: Set[int],
followed_topic_push_user_ids: Set[int], followed_topic_push_user_ids: Set[int],
followed_topic_email_user_ids: Set[int], followed_topic_email_user_ids: Set[int],
followed_topic_wildcard_mention_user_ids: Set[int], stream_wildcard_mention_in_followed_topic_user_ids: Set[int],
muted_sender_user_ids: Set[int], muted_sender_user_ids: Set[int],
all_bot_user_ids: Set[int], all_bot_user_ids: Set[int],
) -> "UserMessageNotificationsData": ) -> "UserMessageNotificationsData":
@ -70,35 +70,35 @@ class UserMessageNotificationsData:
user_id=user_id, user_id=user_id,
pm_email_notify=False, pm_email_notify=False,
mention_email_notify=False, mention_email_notify=False,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
pm_push_notify=False, pm_push_notify=False,
mention_push_notify=False, mention_push_notify=False,
wildcard_mention_push_notify=False, stream_wildcard_mention_push_notify=False,
online_push_enabled=False, online_push_enabled=False,
stream_push_notify=False, stream_push_notify=False,
stream_email_notify=False, stream_email_notify=False,
followed_topic_push_notify=False, followed_topic_push_notify=False,
followed_topic_email_notify=False, followed_topic_email_notify=False,
followed_topic_wildcard_mention_push_notify=False, stream_wildcard_mention_in_followed_topic_push_notify=False,
followed_topic_wildcard_mention_email_notify=False, stream_wildcard_mention_in_followed_topic_email_notify=False,
sender_is_muted=False, sender_is_muted=False,
disable_external_notifications=False, disable_external_notifications=False,
) )
# `wildcard_mention_user_ids` are those user IDs for whom wildcard mentions should # `stream_wildcard_mention_user_ids` are those user IDs for whom stream wildcard
# obey notification settings of personal mentions. Hence, it isn't an independent # mentions should obey notification settings of personal mentions. Hence, it isn't an
# notification setting and acts as a wrapper. # independent notification setting and acts as a wrapper.
pm_email_notify = user_id not in pm_mention_email_disabled_user_ids and private_message pm_email_notify = user_id not in pm_mention_email_disabled_user_ids and private_message
mention_email_notify = ( mention_email_notify = (
user_id not in pm_mention_email_disabled_user_ids and "mentioned" in flags user_id not in pm_mention_email_disabled_user_ids and "mentioned" in flags
) )
wildcard_mention_email_notify = ( stream_wildcard_mention_email_notify = (
user_id in wildcard_mention_user_ids user_id in stream_wildcard_mention_user_ids
and user_id not in pm_mention_email_disabled_user_ids and user_id not in pm_mention_email_disabled_user_ids
and "wildcard_mentioned" in flags and "wildcard_mentioned" in flags
) )
followed_topic_wildcard_mention_email_notify = ( stream_wildcard_mention_in_followed_topic_email_notify = (
user_id in followed_topic_wildcard_mention_user_ids user_id in stream_wildcard_mention_in_followed_topic_user_ids
and user_id not in pm_mention_email_disabled_user_ids and user_id not in pm_mention_email_disabled_user_ids
and "wildcard_mentioned" in flags and "wildcard_mentioned" in flags
) )
@ -107,13 +107,13 @@ class UserMessageNotificationsData:
mention_push_notify = ( mention_push_notify = (
user_id not in pm_mention_push_disabled_user_ids and "mentioned" in flags user_id not in pm_mention_push_disabled_user_ids and "mentioned" in flags
) )
wildcard_mention_push_notify = ( stream_wildcard_mention_push_notify = (
user_id in wildcard_mention_user_ids user_id in stream_wildcard_mention_user_ids
and user_id not in pm_mention_push_disabled_user_ids and user_id not in pm_mention_push_disabled_user_ids
and "wildcard_mentioned" in flags and "wildcard_mentioned" in flags
) )
followed_topic_wildcard_mention_push_notify = ( stream_wildcard_mention_in_followed_topic_push_notify = (
user_id in followed_topic_wildcard_mention_user_ids user_id in stream_wildcard_mention_in_followed_topic_user_ids
and user_id not in pm_mention_push_disabled_user_ids and user_id not in pm_mention_push_disabled_user_ids
and "wildcard_mentioned" in flags and "wildcard_mentioned" in flags
) )
@ -121,17 +121,17 @@ class UserMessageNotificationsData:
user_id=user_id, user_id=user_id,
pm_email_notify=pm_email_notify, pm_email_notify=pm_email_notify,
mention_email_notify=mention_email_notify, mention_email_notify=mention_email_notify,
wildcard_mention_email_notify=wildcard_mention_email_notify, stream_wildcard_mention_email_notify=stream_wildcard_mention_email_notify,
pm_push_notify=pm_push_notify, pm_push_notify=pm_push_notify,
mention_push_notify=mention_push_notify, mention_push_notify=mention_push_notify,
wildcard_mention_push_notify=wildcard_mention_push_notify, stream_wildcard_mention_push_notify=stream_wildcard_mention_push_notify,
online_push_enabled=(user_id in online_push_user_ids), online_push_enabled=(user_id in online_push_user_ids),
stream_push_notify=(user_id in stream_push_user_ids), stream_push_notify=(user_id in stream_push_user_ids),
stream_email_notify=(user_id in stream_email_user_ids), stream_email_notify=(user_id in stream_email_user_ids),
followed_topic_push_notify=(user_id in followed_topic_push_user_ids), followed_topic_push_notify=(user_id in followed_topic_push_user_ids),
followed_topic_email_notify=(user_id in followed_topic_email_user_ids), followed_topic_email_notify=(user_id in followed_topic_email_user_ids),
followed_topic_wildcard_mention_push_notify=followed_topic_wildcard_mention_push_notify, stream_wildcard_mention_in_followed_topic_push_notify=stream_wildcard_mention_in_followed_topic_push_notify,
followed_topic_wildcard_mention_email_notify=followed_topic_wildcard_mention_email_notify, stream_wildcard_mention_in_followed_topic_email_notify=stream_wildcard_mention_in_followed_topic_email_notify,
sender_is_muted=(user_id in muted_sender_user_ids), sender_is_muted=(user_id in muted_sender_user_ids),
disable_external_notifications=disable_external_notifications, disable_external_notifications=disable_external_notifications,
) )
@ -177,10 +177,10 @@ class UserMessageNotificationsData:
return NotificationTriggers.PRIVATE_MESSAGE return NotificationTriggers.PRIVATE_MESSAGE
elif self.mention_push_notify: elif self.mention_push_notify:
return NotificationTriggers.MENTION return NotificationTriggers.MENTION
elif self.followed_topic_wildcard_mention_push_notify: elif self.stream_wildcard_mention_in_followed_topic_push_notify:
return NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION return NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
elif self.wildcard_mention_push_notify: elif self.stream_wildcard_mention_push_notify:
return NotificationTriggers.WILDCARD_MENTION return NotificationTriggers.STREAM_WILDCARD_MENTION
elif self.followed_topic_push_notify: elif self.followed_topic_push_notify:
return NotificationTriggers.FOLLOWED_TOPIC_PUSH return NotificationTriggers.FOLLOWED_TOPIC_PUSH
elif self.stream_push_notify: elif self.stream_push_notify:
@ -205,10 +205,10 @@ class UserMessageNotificationsData:
return NotificationTriggers.PRIVATE_MESSAGE return NotificationTriggers.PRIVATE_MESSAGE
elif self.mention_email_notify: elif self.mention_email_notify:
return NotificationTriggers.MENTION return NotificationTriggers.MENTION
elif self.followed_topic_wildcard_mention_email_notify: elif self.stream_wildcard_mention_in_followed_topic_email_notify:
return NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION return NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
elif self.wildcard_mention_email_notify: elif self.stream_wildcard_mention_email_notify:
return NotificationTriggers.WILDCARD_MENTION return NotificationTriggers.STREAM_WILDCARD_MENTION
elif self.followed_topic_email_notify: elif self.followed_topic_email_notify:
return NotificationTriggers.FOLLOWED_TOPIC_EMAIL return NotificationTriggers.FOLLOWED_TOPIC_EMAIL
elif self.stream_email_notify: elif self.stream_email_notify:

View File

@ -674,10 +674,10 @@ def get_gcm_alert(
return f"{sender_str} mentioned @{mentioned_user_group_name} in #{display_recipient}" return f"{sender_str} mentioned @{mentioned_user_group_name} in #{display_recipient}"
elif ( elif (
message.is_stream_message() message.is_stream_message()
and trigger == NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION and trigger == NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
): ):
return "TODO" return "TODO"
elif message.is_stream_message() and trigger == NotificationTriggers.WILDCARD_MENTION: elif message.is_stream_message() and trigger == NotificationTriggers.STREAM_WILDCARD_MENTION:
return f"{sender_str} mentioned everyone in #{display_recipient}" return f"{sender_str} mentioned everyone in #{display_recipient}"
else: else:
assert message.is_stream_message() and trigger == NotificationTriggers.STREAM_PUSH assert message.is_stream_message() and trigger == NotificationTriggers.STREAM_PUSH
@ -842,9 +842,9 @@ def get_apns_alert_subtitle(
) )
else: else:
return _("{full_name} mentioned you:").format(full_name=message.sender.full_name) return _("{full_name} mentioned you:").format(full_name=message.sender.full_name)
elif trigger == NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION: elif trigger == NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC:
return _("TODO") return _("TODO")
elif trigger == NotificationTriggers.WILDCARD_MENTION: elif trigger == NotificationTriggers.STREAM_WILDCARD_MENTION:
return _("{full_name} mentioned everyone:").format(full_name=message.sender.full_name) return _("{full_name} mentioned everyone:").format(full_name=message.sender.full_name)
elif message.recipient.type == Recipient.PERSONAL: elif message.recipient.type == Recipient.PERSONAL:
return "" return ""

View File

@ -407,7 +407,7 @@ def soft_reactivate_if_personal_notification(
return to Zulip. As a result, it makes sense to optimistically return to Zulip. As a result, it makes sense to optimistically
soft-reactivate that user, to give them a good return experience. soft-reactivate that user, to give them a good return experience.
It's important that we do nothing for wildcard or group mentions, It's important that we do nothing for stream wildcard or group mentions,
because soft-reactivating an entire realm would be very expensive because soft-reactivating an entire realm would be very expensive
(and we can't easily check the group's size). The caller is (and we can't easily check the group's size). The caller is
responsible for passing a mentioned_user_group_name that is None responsible for passing a mentioned_user_group_name that is None

View File

@ -306,7 +306,7 @@ def get_subscriptions_for_send_message(
realm_id: int, realm_id: int,
stream_id: int, stream_id: int,
topic_name: str, topic_name: str,
possible_wildcard_mention: bool, possible_stream_wildcard_mention: bool,
possibly_mentioned_user_ids: AbstractSet[int], possibly_mentioned_user_ids: AbstractSet[int],
) -> QuerySet[Subscription]: ) -> QuerySet[Subscription]:
"""This function optimizes an important use case for large """This function optimizes an important use case for large
@ -342,7 +342,7 @@ def get_subscriptions_for_send_message(
include_deactivated_users=False, include_deactivated_users=False,
) )
if possible_wildcard_mention: if possible_stream_wildcard_mention:
return query return query
query = query.filter( query = query.filter(

View File

@ -1719,17 +1719,21 @@ Output:
pm_push_notify=kwargs.get("pm_push_notify", False), pm_push_notify=kwargs.get("pm_push_notify", False),
mention_email_notify=kwargs.get("mention_email_notify", False), mention_email_notify=kwargs.get("mention_email_notify", False),
mention_push_notify=kwargs.get("mention_push_notify", False), mention_push_notify=kwargs.get("mention_push_notify", False),
wildcard_mention_email_notify=kwargs.get("wildcard_mention_email_notify", False), stream_wildcard_mention_email_notify=kwargs.get(
wildcard_mention_push_notify=kwargs.get("wildcard_mention_push_notify", False), "stream_wildcard_mention_email_notify", False
),
stream_wildcard_mention_push_notify=kwargs.get(
"stream_wildcard_mention_push_notify", False
),
stream_email_notify=kwargs.get("stream_email_notify", False), stream_email_notify=kwargs.get("stream_email_notify", False),
stream_push_notify=kwargs.get("stream_push_notify", False), stream_push_notify=kwargs.get("stream_push_notify", False),
followed_topic_email_notify=kwargs.get("followed_topic_email_notify", False), followed_topic_email_notify=kwargs.get("followed_topic_email_notify", False),
followed_topic_push_notify=kwargs.get("followed_topic_push_notify", False), followed_topic_push_notify=kwargs.get("followed_topic_push_notify", False),
followed_topic_wildcard_mention_email_notify=kwargs.get( stream_wildcard_mention_in_followed_topic_email_notify=kwargs.get(
"followed_topic_wildcard_mention_email_notify", False "stream_wildcard_mention_in_followed_topic_email_notify", False
), ),
followed_topic_wildcard_mention_push_notify=kwargs.get( stream_wildcard_mention_in_followed_topic_push_notify=kwargs.get(
"followed_topic_wildcard_mention_push_notify", False "stream_wildcard_mention_in_followed_topic_push_notify", False
), ),
sender_is_muted=kwargs.get("sender_is_muted", False), sender_is_muted=kwargs.get("sender_is_muted", False),
disable_external_notifications=kwargs.get("disable_external_notifications", False), disable_external_notifications=kwargs.get("disable_external_notifications", False),

View File

@ -26,12 +26,12 @@ class Migration(migrations.Migration):
choices=[ choices=[
("private_message", "Private message"), ("private_message", "Private message"),
("mentioned", "Mention"), ("mentioned", "Mention"),
("wildcard_mentioned", "Wildcard mention"), ("stream_wildcard_mentioned", "Stream wildcard mention"),
("stream_email_notify", "Stream notifications enabled"), ("stream_email_notify", "Stream notifications enabled"),
("followed_topic_email_notify", "Followed topic notifications enabled"), ("followed_topic_email_notify", "Followed topic notifications enabled"),
( (
"followed_topic_wildcard_mentioned", "stream_wildcard_mentioned_in_followed_topic",
"Followed topic wildcard mention", "Stream wildcard mention in followed topic",
), ),
] ]
), ),

View File

@ -0,0 +1,36 @@
# Generated by Django 4.2.1 on 2023-06-20 12:07
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("zerver", "0456_alter_usergroup_can_mention_group"),
]
operations = [
migrations.RunSQL(
"""
UPDATE zerver_scheduledmessagenotificationemail
SET trigger = 'stream_wildcard_mentioned'
WHERE trigger = 'wildcard_mentioned';
""",
reverse_sql="""
UPDATE zerver_scheduledmessagenotificationemail
SET trigger = 'wildcard_mentioned'
WHERE trigger = 'stream_wildcard_mentioned';
""",
),
migrations.RunSQL(
"""
UPDATE zerver_scheduledmessagenotificationemail
SET trigger = 'stream_wildcard_mentioned_in_followed_topic'
WHERE trigger = 'followed_topic_wildcard_mentioned';
""",
reverse_sql="""
UPDATE zerver_scheduledmessagenotificationemail
SET trigger = 'followed_topic_wildcard_mentioned'
WHERE trigger = 'stream_wildcard_mentioned_in_followed_topic';
""",
),
]

View File

@ -4303,12 +4303,12 @@ class NotificationTriggers:
# "private_message" is for 1:1 direct messages as well as huddles # "private_message" is for 1:1 direct messages as well as huddles
PRIVATE_MESSAGE = "private_message" PRIVATE_MESSAGE = "private_message"
MENTION = "mentioned" MENTION = "mentioned"
WILDCARD_MENTION = "wildcard_mentioned" STREAM_WILDCARD_MENTION = "stream_wildcard_mentioned"
STREAM_PUSH = "stream_push_notify" STREAM_PUSH = "stream_push_notify"
STREAM_EMAIL = "stream_email_notify" STREAM_EMAIL = "stream_email_notify"
FOLLOWED_TOPIC_PUSH = "followed_topic_push_notify" FOLLOWED_TOPIC_PUSH = "followed_topic_push_notify"
FOLLOWED_TOPIC_EMAIL = "followed_topic_email_notify" FOLLOWED_TOPIC_EMAIL = "followed_topic_email_notify"
FOLLOWED_TOPIC_WILDCARD_MENTION = "followed_topic_wildcard_mentioned" STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC = "stream_wildcard_mentioned_in_followed_topic"
class ScheduledMessageNotificationEmail(models.Model): class ScheduledMessageNotificationEmail(models.Model):
@ -4324,10 +4324,13 @@ class ScheduledMessageNotificationEmail(models.Model):
EMAIL_NOTIFICATION_TRIGGER_CHOICES = [ EMAIL_NOTIFICATION_TRIGGER_CHOICES = [
(NotificationTriggers.PRIVATE_MESSAGE, "Private message"), (NotificationTriggers.PRIVATE_MESSAGE, "Private message"),
(NotificationTriggers.MENTION, "Mention"), (NotificationTriggers.MENTION, "Mention"),
(NotificationTriggers.WILDCARD_MENTION, "Wildcard mention"), (NotificationTriggers.STREAM_WILDCARD_MENTION, "Stream wildcard mention"),
(NotificationTriggers.STREAM_EMAIL, "Stream notifications enabled"), (NotificationTriggers.STREAM_EMAIL, "Stream notifications enabled"),
(NotificationTriggers.FOLLOWED_TOPIC_EMAIL, "Followed topic notifications enabled"), (NotificationTriggers.FOLLOWED_TOPIC_EMAIL, "Followed topic notifications enabled"),
(NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION, "Followed topic wildcard mention"), (
NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC,
"Stream wildcard mention in followed topic",
),
] ]
trigger = models.TextField(choices=EMAIL_NOTIFICATION_TRIGGER_CHOICES) trigger = models.TextField(choices=EMAIL_NOTIFICATION_TRIGGER_CHOICES)

View File

@ -691,7 +691,7 @@ class TestMissedMessages(ZulipTestCase):
trigger="mentioned", trigger="mentioned",
) )
def _extra_context_in_missed_stream_messages_followed_topic_wildcard_mention( def _extra_context_in_missed_stream_messages_stream_wildcard_mention_in_followed_topic(
self, send_as_user: bool, show_message_content: bool = True self, send_as_user: bool, show_message_content: bool = True
) -> None: ) -> None:
for i in range(1, 6): for i in range(1, 6):
@ -729,10 +729,10 @@ class TestMissedMessages(ZulipTestCase):
send_as_user, send_as_user,
show_message_content=show_message_content, show_message_content=show_message_content,
verify_body_does_not_include=verify_body_does_not_include, verify_body_does_not_include=verify_body_does_not_include,
trigger="followed_topic_wildcard_mentioned", trigger="stream_wildcard_mentioned_in_followed_topic",
) )
def _extra_context_in_missed_stream_messages_wildcard_mention( def _extra_context_in_missed_stream_messages_stream_wildcard_mention(
self, send_as_user: bool, show_message_content: bool = True self, send_as_user: bool, show_message_content: bool = True
) -> None: ) -> None:
for i in range(1, 6): for i in range(1, 6):
@ -771,7 +771,7 @@ class TestMissedMessages(ZulipTestCase):
send_as_user, send_as_user,
show_message_content=show_message_content, show_message_content=show_message_content,
verify_body_does_not_include=verify_body_does_not_include, verify_body_does_not_include=verify_body_does_not_include,
trigger="wildcard_mentioned", trigger="stream_wildcard_mentioned",
) )
def _extra_context_in_missed_stream_messages_email_notify(self, send_as_user: bool) -> None: def _extra_context_in_missed_stream_messages_email_notify(self, send_as_user: bool) -> None:
@ -1102,7 +1102,7 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include: for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body)) self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_user_group_over_followed_topic_wildcard_mention_priority(self) -> None: def test_user_group_over_stream_wildcard_mention_in_followed_topic_priority(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
othello = self.example_user("othello") othello = self.example_user("othello")
@ -1111,7 +1111,7 @@ class TestMissedMessages(ZulipTestCase):
get_realm("zulip"), "hamlet_and_cordelia", [hamlet, cordelia], acting_user=None get_realm("zulip"), "hamlet_and_cordelia", [hamlet, cordelia], acting_user=None
) )
followed_topic_wildcard_mentioned_message_id = self.send_stream_message( stream_wildcard_mentioned_in_followed_topic_message_id = self.send_stream_message(
othello, "Denmark", "@**all**" othello, "Denmark", "@**all**"
) )
user_group_mentioned_message_id = self.send_stream_message( user_group_mentioned_message_id = self.send_stream_message(
@ -1122,8 +1122,8 @@ class TestMissedMessages(ZulipTestCase):
hamlet.id, hamlet.id,
[ [
{ {
"message_id": followed_topic_wildcard_mentioned_message_id, "message_id": stream_wildcard_mentioned_in_followed_topic_message_id,
"trigger": "followed_topic_wildcard_mentioned", "trigger": "stream_wildcard_mentioned_in_followed_topic",
"mentioned_user_group_id": None, "mentioned_user_group_id": None,
}, },
{ {
@ -1142,12 +1142,14 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include: for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body)) self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_followed_topic_wildcard_over_wildcard_mention_priority(self) -> None: def test_stream_wildcard_in_followed_topic_over_stream_wildcard_mention_priority(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
othello = self.example_user("othello") othello = self.example_user("othello")
wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**") stream_wildcard_mentioned_message_id = self.send_stream_message(
followed_topic_wildcard_mentioned_message_id = self.send_stream_message( othello, "Denmark", "@**all**"
)
stream_wildcard_mentioned_in_followed_topic_message_id = self.send_stream_message(
othello, "Denmark", "@**all**" othello, "Denmark", "@**all**"
) )
@ -1155,13 +1157,13 @@ class TestMissedMessages(ZulipTestCase):
hamlet.id, hamlet.id,
[ [
{ {
"message_id": wildcard_mentioned_message_id, "message_id": stream_wildcard_mentioned_message_id,
"trigger": "wildcard_mentioned", "trigger": "stream_wildcard_mentioned",
"mentioned_user_group_id": None, "mentioned_user_group_id": None,
}, },
{ {
"message_id": followed_topic_wildcard_mentioned_message_id, "message_id": stream_wildcard_mentioned_in_followed_topic_message_id,
"trigger": "followed_topic_wildcard_mentioned", "trigger": "stream_wildcard_mentioned_in_followed_topic",
"mentioned_user_group_id": None, "mentioned_user_group_id": None,
}, },
], ],
@ -1175,12 +1177,14 @@ class TestMissedMessages(ZulipTestCase):
for text in expected_email_include: for text in expected_email_include:
self.assertIn(text, self.normalize_string(mail.outbox[0].body)) self.assertIn(text, self.normalize_string(mail.outbox[0].body))
def test_wildcard_mention_over_followed_topic_notify_priority(self) -> None: def test_stream_wildcard_mention_over_followed_topic_notify_priority(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
othello = self.example_user("othello") othello = self.example_user("othello")
followed_topic_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1") followed_topic_mentioned_message_id = self.send_stream_message(othello, "Denmark", "1")
wildcard_mentioned_message_id = self.send_stream_message(othello, "Denmark", "@**all**") stream_wildcard_mentioned_message_id = self.send_stream_message(
othello, "Denmark", "@**all**"
)
handle_missedmessage_emails( handle_missedmessage_emails(
hamlet.id, hamlet.id,
@ -1191,8 +1195,8 @@ class TestMissedMessages(ZulipTestCase):
"mentioned_user_group_id": None, "mentioned_user_group_id": None,
}, },
{ {
"message_id": wildcard_mentioned_message_id, "message_id": stream_wildcard_mentioned_message_id,
"trigger": "wildcard_mentioned", "trigger": "stream_wildcard_mentioned",
"mentioned_user_group_id": None, "mentioned_user_group_id": None,
}, },
], ],
@ -1322,11 +1326,11 @@ class TestMissedMessages(ZulipTestCase):
) )
self._extra_context_in_missed_stream_messages_mention(False, show_message_content=False) self._extra_context_in_missed_stream_messages_mention(False, show_message_content=False)
mail.outbox = [] mail.outbox = []
self._extra_context_in_missed_stream_messages_followed_topic_wildcard_mention( self._extra_context_in_missed_stream_messages_stream_wildcard_mention_in_followed_topic(
False, show_message_content=False False, show_message_content=False
) )
mail.outbox = [] mail.outbox = []
self._extra_context_in_missed_stream_messages_wildcard_mention( self._extra_context_in_missed_stream_messages_stream_wildcard_mention(
False, show_message_content=False False, show_message_content=False
) )
mail.outbox = [] mail.outbox = []
@ -1344,20 +1348,26 @@ class TestMissedMessages(ZulipTestCase):
self._extra_context_in_missed_stream_messages_mention(False) self._extra_context_in_missed_stream_messages_mention(False)
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True) @override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
def test_extra_context_in_missed_stream_messages_as_user_followed_topic_wildcard( def test_extra_context_in_missed_stream_messages_as_user_stream_wildcard_in_followed_topic(
self, self,
) -> None: ) -> None:
self._extra_context_in_missed_stream_messages_followed_topic_wildcard_mention(True) self._extra_context_in_missed_stream_messages_stream_wildcard_mention_in_followed_topic(
True
)
def test_extra_context_in_missed_stream_messages_followed_topic_wildcard(self) -> None: def test_extra_context_in_missed_stream_messages_stream_wildcard_in_followed_topic(
self._extra_context_in_missed_stream_messages_followed_topic_wildcard_mention(False) self,
) -> None:
self._extra_context_in_missed_stream_messages_stream_wildcard_mention_in_followed_topic(
False
)
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True) @override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
def test_extra_context_in_missed_stream_messages_as_user_wildcard(self) -> None: def test_extra_context_in_missed_stream_messages_as_user_stream_wildcard(self) -> None:
self._extra_context_in_missed_stream_messages_wildcard_mention(True) self._extra_context_in_missed_stream_messages_stream_wildcard_mention(True)
def test_extra_context_in_missed_stream_messages_wildcard(self) -> None: def test_extra_context_in_missed_stream_messages_stream_wildcard(self) -> None:
self._extra_context_in_missed_stream_messages_wildcard_mention(False) self._extra_context_in_missed_stream_messages_stream_wildcard_mention(False)
@override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True) @override_settings(SEND_MISSED_MESSAGE_EMAILS_AS_USER=True)
def test_extra_context_in_missed_stream_messages_as_user_two_senders(self) -> None: def test_extra_context_in_missed_stream_messages_as_user_two_senders(self) -> None:
@ -1945,7 +1955,7 @@ class TestMissedMessages(ZulipTestCase):
[{"message_id": personal_message_id, "trigger": "private_message"}], [{"message_id": personal_message_id, "trigger": "private_message"}],
) )
# Followed Topic wildcard mention should NOT soft reactivate the user # Stream wildcard mention in followed topic should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True): with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True):
mention = "@**all**" mention = "@**all**"
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention) stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention)
@ -1954,19 +1964,24 @@ class TestMissedMessages(ZulipTestCase):
[ [
{ {
"message_id": stream_mentioned_message_id, "message_id": stream_mentioned_message_id,
"trigger": "followed_topic_wildcard_mentioned", "trigger": "stream_wildcard_mentioned_in_followed_topic",
} }
], ],
) )
# Wildcard mention should NOT soft reactivate the user # Stream Wildcard mention should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True): with self.soft_deactivate_and_check_long_term_idle(hamlet, expected=True):
# Soft reactivate the user by sending a personal message # Soft reactivate the user by sending a personal message
mention = "@**all**" mention = "@**all**"
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention) stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention)
handle_missedmessage_emails( handle_missedmessage_emails(
hamlet.id, hamlet.id,
[{"message_id": stream_mentioned_message_id, "trigger": "wildcard_mentioned"}], [
{
"message_id": stream_mentioned_message_id,
"trigger": "stream_wildcard_mentioned",
}
],
) )
# Group mention should NOT soft reactivate the user # Group mention should NOT soft reactivate the user

View File

@ -298,8 +298,8 @@ class MissedMessageHookTest(ZulipTestCase):
already_notified={"email_notified": True, "push_notified": False}, already_notified={"email_notified": True, "push_notified": False},
) )
def test_wildcard_mention(self) -> None: def test_stream_wildcard_mention(self) -> None:
# By default, wildcard mentions should send notifications, just like regular mentions # By default, stream wildcard mentions should send notifications, just like regular mentions
msg_id = self.send_stream_message(self.iago, "Denmark", content="@**all** what's up?") msg_id = self.send_stream_message(self.iago, "Denmark", content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue: with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(self.user_profile.id, self.client_descriptor, True) missedmessage_hook(self.user_profile.id, self.client_descriptor, True)
@ -310,13 +310,13 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
already_notified={"email_notified": True, "push_notified": True}, already_notified={"email_notified": True, "push_notified": True},
) )
def test_wildcard_mention_in_muted_stream(self) -> None: def test_stream_wildcard_mention_in_muted_stream(self) -> None:
# Wildcard mentions in muted streams don't notify. # stream wildcard mentions in muted streams don't notify.
self.change_subscription_properties({"is_muted": True}) self.change_subscription_properties({"is_muted": True})
msg_id = self.send_stream_message(self.iago, "Denmark", content="@**all** what's up?") msg_id = self.send_stream_message(self.iago, "Denmark", content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue: with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
@ -326,15 +326,15 @@ class MissedMessageHookTest(ZulipTestCase):
self.assert_maybe_enqueue_notifications_call_args( self.assert_maybe_enqueue_notifications_call_args(
args_dict=args_dict, args_dict=args_dict,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
wildcard_mention_push_notify=False, stream_wildcard_mention_push_notify=False,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
already_notified={"email_notified": False, "push_notified": False}, already_notified={"email_notified": False, "push_notified": False},
) )
def test_wildcard_mention_in_muted_topic(self) -> None: def test_stream_wildcard_mention_in_muted_topic(self) -> None:
# Wildcard mentions in muted streams don't notify. # stream wildcard mentions in muted topics don't notify.
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
self.user_profile, self.user_profile,
get_stream("Denmark", self.user_profile.realm), get_stream("Denmark", self.user_profile.realm),
@ -351,8 +351,8 @@ class MissedMessageHookTest(ZulipTestCase):
self.assert_maybe_enqueue_notifications_call_args( self.assert_maybe_enqueue_notifications_call_args(
args_dict=args_dict, args_dict=args_dict,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
wildcard_mention_push_notify=False, stream_wildcard_mention_push_notify=False,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
already_notified={"email_notified": False, "push_notified": False}, already_notified={"email_notified": False, "push_notified": False},
@ -373,12 +373,14 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
wildcard_mention_push_notify=False, stream_wildcard_mention_push_notify=False,
already_notified={"email_notified": False, "push_notified": False}, already_notified={"email_notified": False, "push_notified": False},
) )
def test_wildcard_mentions_notify_stream_specific_setting(self) -> None: def test_wildcard_mentions_notify_stream_specific_setting(
self,
) -> None:
# If wildcard_mentions_notify=True for a stream and False for a user, we treat the user # If wildcard_mentions_notify=True for a stream and False for a user, we treat the user
# as mentioned for that stream. # as mentioned for that stream.
do_change_user_setting( do_change_user_setting(
@ -395,8 +397,8 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
already_notified={"email_notified": True, "push_notified": True}, already_notified={"email_notified": True, "push_notified": True},
) )
@ -423,8 +425,8 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
already_notified={"email_notified": False, "push_notified": True}, already_notified={"email_notified": False, "push_notified": True},
) )
@ -444,8 +446,8 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
wildcard_mention_email_notify=False, stream_wildcard_mention_email_notify=False,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
already_notified={"email_notified": False, "push_notified": True}, already_notified={"email_notified": False, "push_notified": True},
) )
@ -840,7 +842,7 @@ class MissedMessageHookTest(ZulipTestCase):
already_notified={"email_notified": True, "push_notified": False}, already_notified={"email_notified": True, "push_notified": False},
) )
def test_followed_topic_wildcard_mention_notify(self) -> None: def test_stream_wildcard_mention_in_followed_topic_notify(self) -> None:
do_change_user_setting( do_change_user_setting(
self.user_profile, "wildcard_mentions_notify", False, acting_user=None self.user_profile, "wildcard_mentions_notify", False, acting_user=None
) )
@ -870,13 +872,13 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
followed_topic_wildcard_mention_email_notify=True, stream_wildcard_mention_in_followed_topic_email_notify=True,
followed_topic_wildcard_mention_push_notify=True, stream_wildcard_mention_in_followed_topic_push_notify=True,
already_notified={"email_notified": True, "push_notified": True}, already_notified={"email_notified": True, "push_notified": True},
) )
def test_followed_topic_wildcard_mention_in_muted_stream(self) -> None: def test_stream_wildcard_mention_in_followed_topic_muted_stream(self) -> None:
# By default, wildcard mentions in a followed topic with muted stream DO notify. # By default, stream wildcard mentions in a followed topic with muted stream DO notify.
do_change_user_setting( do_change_user_setting(
self.user_profile, "wildcard_mentions_notify", False, acting_user=None self.user_profile, "wildcard_mentions_notify", False, acting_user=None
) )
@ -906,8 +908,8 @@ class MissedMessageHookTest(ZulipTestCase):
args_dict=args_dict, args_dict=args_dict,
message_id=msg_id, message_id=msg_id,
user_id=self.user_profile.id, user_id=self.user_profile.id,
followed_topic_wildcard_mention_email_notify=True, stream_wildcard_mention_in_followed_topic_email_notify=True,
followed_topic_wildcard_mention_push_notify=True, stream_wildcard_mention_in_followed_topic_push_notify=True,
already_notified={"email_notified": True, "push_notified": True}, already_notified={"email_notified": True, "push_notified": True},
) )
@ -1407,7 +1409,7 @@ class SchemaMigrationsTests(ZulipTestCase):
online_push_user_ids=[hamlet.id, cordelia.id], online_push_user_ids=[hamlet.id, cordelia.id],
stream_push_user_ids=[cordelia.id], stream_push_user_ids=[cordelia.id],
stream_email_user_ids=[hamlet.id], stream_email_user_ids=[hamlet.id],
wildcard_mention_user_ids=[cordelia.id], stream_wildcard_mention_user_ids=[cordelia.id],
muted_sender_user_ids=[], muted_sender_user_ids=[],
) )
with mock.patch("zerver.tornado.event_queue.process_message_event") as m: with mock.patch("zerver.tornado.event_queue.process_message_event") as m:

View File

@ -456,7 +456,7 @@ class NormalActionsTest(BaseAction):
lambda: self.send_stream_message(self.example_user("cordelia"), "Verona", content), lambda: self.send_stream_message(self.example_user("cordelia"), "Verona", content),
) )
def test_wildcard_mentioned_send_message_events(self) -> None: def test_stream_wildcard_mentioned_send_message_events(self) -> None:
for i in range(3): for i in range(3):
content = "mentioning... @**all** hello " + str(i) content = "mentioning... @**all** hello " + str(i)
self.verify_action( self.verify_action(

View File

@ -277,10 +277,10 @@ class MarkdownMiscTest(ZulipTestCase):
assert user is not None assert user is not None
self.assertEqual(user.full_name, hamlet.full_name) self.assertEqual(user.full_name, hamlet.full_name)
self.assertFalse(mention_data.message_has_wildcards()) self.assertFalse(mention_data.message_has_stream_wildcards())
content = "@**King Hamlet** @**Cordelia, lear's daughter** @**all**" content = "@**King Hamlet** @**Cordelia, lear's daughter** @**all**"
mention_data = MentionData(mention_backend, content) mention_data = MentionData(mention_backend, content)
self.assertTrue(mention_data.message_has_wildcards()) self.assertTrue(mention_data.message_has_stream_wildcards())
def test_invalid_katex_path(self) -> None: def test_invalid_katex_path(self) -> None:
with self.settings(DEPLOY_ROOT="/nonexistent"): with self.settings(DEPLOY_ROOT="/nonexistent"):
@ -1817,7 +1817,7 @@ class MarkdownTest(ZulipTestCase):
rendering_result.rendered_content, rendering_result.rendered_content,
'<p><span class="user-mention" data-user-id="*">@all</span> test</p>', '<p><span class="user-mention" data-user-id="*">@all</span> test</p>',
) )
self.assertTrue(rendering_result.mentions_wildcard) self.assertTrue(rendering_result.mentions_stream_wildcard)
def test_mention_everyone(self) -> None: def test_mention_everyone(self) -> None:
user_profile = self.example_user("othello") user_profile = self.example_user("othello")
@ -1829,7 +1829,7 @@ class MarkdownTest(ZulipTestCase):
rendering_result.rendered_content, rendering_result.rendered_content,
'<p><span class="user-mention" data-user-id="*">@everyone</span> test</p>', '<p><span class="user-mention" data-user-id="*">@everyone</span> test</p>',
) )
self.assertTrue(rendering_result.mentions_wildcard) self.assertTrue(rendering_result.mentions_stream_wildcard)
def test_mention_stream(self) -> None: def test_mention_stream(self) -> None:
user_profile = self.example_user("othello") user_profile = self.example_user("othello")
@ -1841,7 +1841,7 @@ class MarkdownTest(ZulipTestCase):
rendering_result.rendered_content, rendering_result.rendered_content,
'<p><span class="user-mention" data-user-id="*">@stream</span> test</p>', '<p><span class="user-mention" data-user-id="*">@stream</span> test</p>',
) )
self.assertTrue(rendering_result.mentions_wildcard) self.assertTrue(rendering_result.mentions_stream_wildcard)
def test_mention_at_wildcard(self) -> None: def test_mention_at_wildcard(self) -> None:
user_profile = self.example_user("othello") user_profile = self.example_user("othello")
@ -1850,7 +1850,7 @@ class MarkdownTest(ZulipTestCase):
content = "@all test" content = "@all test"
rendering_result = render_markdown(msg, content) rendering_result = render_markdown(msg, content)
self.assertEqual(rendering_result.rendered_content, "<p>@all test</p>") self.assertEqual(rendering_result.rendered_content, "<p>@all test</p>")
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
self.assertEqual(rendering_result.mentions_user_ids, set()) self.assertEqual(rendering_result.mentions_user_ids, set())
def test_mention_at_everyone(self) -> None: def test_mention_at_everyone(self) -> None:
@ -1860,7 +1860,7 @@ class MarkdownTest(ZulipTestCase):
content = "@everyone test" content = "@everyone test"
rendering_result = render_markdown(msg, content) rendering_result = render_markdown(msg, content)
self.assertEqual(rendering_result.rendered_content, "<p>@everyone test</p>") self.assertEqual(rendering_result.rendered_content, "<p>@everyone test</p>")
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
self.assertEqual(rendering_result.mentions_user_ids, set()) self.assertEqual(rendering_result.mentions_user_ids, set())
def test_mention_word_starting_with_at_wildcard(self) -> None: def test_mention_word_starting_with_at_wildcard(self) -> None:
@ -1870,7 +1870,7 @@ class MarkdownTest(ZulipTestCase):
content = "test @alleycat.com test" content = "test @alleycat.com test"
rendering_result = render_markdown(msg, content) rendering_result = render_markdown(msg, content)
self.assertEqual(rendering_result.rendered_content, "<p>test @alleycat.com test</p>") self.assertEqual(rendering_result.rendered_content, "<p>test @alleycat.com test</p>")
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
self.assertEqual(rendering_result.mentions_user_ids, set()) self.assertEqual(rendering_result.mentions_user_ids, set())
def test_mention_at_normal_user(self) -> None: def test_mention_at_normal_user(self) -> None:
@ -1880,7 +1880,7 @@ class MarkdownTest(ZulipTestCase):
content = "@aaron test" content = "@aaron test"
rendering_result = render_markdown(msg, content) rendering_result = render_markdown(msg, content)
self.assertEqual(rendering_result.rendered_content, "<p>@aaron test</p>") self.assertEqual(rendering_result.rendered_content, "<p>@aaron test</p>")
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
self.assertEqual(rendering_result.mentions_user_ids, set()) self.assertEqual(rendering_result.mentions_user_ids, set())
def test_mention_single(self) -> None: def test_mention_single(self) -> None:
@ -1965,7 +1965,7 @@ class MarkdownTest(ZulipTestCase):
rendering_result.rendered_content, rendering_result.rendered_content,
f'<p><span class="user-mention silent" data-user-id="*">{wildcard}</span></p>', f'<p><span class="user-mention silent" data-user-id="*">{wildcard}</span></p>',
) )
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
def test_mention_invalid_followed_by_valid(self) -> None: def test_mention_invalid_followed_by_valid(self) -> None:
sender_user_profile = self.example_user("othello") sender_user_profile = self.example_user("othello")
@ -2030,10 +2030,14 @@ class MarkdownTest(ZulipTestCase):
self.assertEqual(rendering_result.mentions_user_ids, set()) self.assertEqual(rendering_result.mentions_user_ids, set())
def test_possible_mentions(self) -> None: def test_possible_mentions(self) -> None:
def assert_mentions(content: str, names: Set[str], has_wildcards: bool = False) -> None: def assert_mentions(
content: str, names: Set[str], has_stream_wildcards: bool = False
) -> None:
self.assertEqual( self.assertEqual(
possible_mentions(content), possible_mentions(content),
PossibleMentions(mention_texts=names, message_has_wildcards=has_wildcards), PossibleMentions(
mention_texts=names, message_has_stream_wildcards=has_stream_wildcards
),
) )
aaron = self.example_user("aaron") aaron = self.example_user("aaron")
@ -2127,7 +2131,7 @@ class MarkdownTest(ZulipTestCase):
) )
rendering_result = render_markdown(message, content) rendering_result = render_markdown(message, content)
self.assertEqual(rendering_result.rendered_content, expected) self.assertEqual(rendering_result.rendered_content, expected)
self.assertFalse(rendering_result.mentions_wildcard) self.assertFalse(rendering_result.mentions_stream_wildcard)
wildcards = ["all", "everyone", "stream"] wildcards = ["all", "everyone", "stream"]
for wildcard in wildcards: for wildcard in wildcards:

View File

@ -2039,7 +2039,9 @@ class EditMessageTest(EditMessageTestCase):
) )
@mock.patch("zerver.actions.message_edit.send_event") @mock.patch("zerver.actions.message_edit.send_event")
def test_followed_topic_wildcard_mention(self, mock_send_event: mock.MagicMock) -> None: def test_stream_wildcard_mention_in_followed_topic(
self, mock_send_event: mock.MagicMock
) -> None:
stream_name = "Macbeth" stream_name = "Macbeth"
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
@ -2072,14 +2074,16 @@ class EditMessageTest(EditMessageTestCase):
self.assert_json_success(result) self.assert_json_success(result)
# Extract the send_event call where event type is 'update_message'. # Extract the send_event call where event type is 'update_message'.
# Here we assert 'followed_topic_wildcard_mention_user_ids' # Here we assert 'stream_wildcard_mention_in_followed_topic_user_ids'
# has been set properly. # has been set properly.
called = False called = False
for call_args in mock_send_event.call_args_list: for call_args in mock_send_event.call_args_list:
(arg_realm, arg_event, arg_notified_users) = call_args[0] (arg_realm, arg_event, arg_notified_users) = call_args[0]
if arg_event["type"] == "update_message": if arg_event["type"] == "update_message":
self.assertEqual(arg_event["type"], "update_message") self.assertEqual(arg_event["type"], "update_message")
self.assertEqual(arg_event["followed_topic_wildcard_mention_user_ids"], [hamlet.id]) self.assertEqual(
arg_event["stream_wildcard_mention_in_followed_topic_user_ids"], [hamlet.id]
)
self.assertEqual( self.assertEqual(
sorted(arg_notified_users, key=itemgetter("id")), users_to_be_notified sorted(arg_notified_users, key=itemgetter("id")), users_to_be_notified
) )
@ -2087,7 +2091,7 @@ class EditMessageTest(EditMessageTestCase):
self.assertTrue(called) self.assertTrue(called)
@mock.patch("zerver.actions.message_edit.send_event") @mock.patch("zerver.actions.message_edit.send_event")
def test_wildcard_mention(self, mock_send_event: mock.MagicMock) -> None: def test_stream_wildcard_mention(self, mock_send_event: mock.MagicMock) -> None:
stream_name = "Macbeth" stream_name = "Macbeth"
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
@ -2113,20 +2117,22 @@ class EditMessageTest(EditMessageTestCase):
self.assert_json_success(result) self.assert_json_success(result)
# Extract the send_event call where event type is 'update_message'. # Extract the send_event call where event type is 'update_message'.
# Here we assert wildcard_mention_user_ids has been set properly. # Here we assert 'stream_wildcard_mention_user_ids' has been set properly.
called = False called = False
for call_args in mock_send_event.call_args_list: for call_args in mock_send_event.call_args_list:
(arg_realm, arg_event, arg_notified_users) = call_args[0] (arg_realm, arg_event, arg_notified_users) = call_args[0]
if arg_event["type"] == "update_message": if arg_event["type"] == "update_message":
self.assertEqual(arg_event["type"], "update_message") self.assertEqual(arg_event["type"], "update_message")
self.assertEqual(arg_event["wildcard_mention_user_ids"], [cordelia.id, hamlet.id]) self.assertEqual(
arg_event["stream_wildcard_mention_user_ids"], [cordelia.id, hamlet.id]
)
self.assertEqual( self.assertEqual(
sorted(arg_notified_users, key=itemgetter("id")), users_to_be_notified sorted(arg_notified_users, key=itemgetter("id")), users_to_be_notified
) )
called = True called = True
self.assertTrue(called) self.assertTrue(called)
def test_wildcard_mention_restrictions_when_editing(self) -> None: def test_stream_wildcard_mention_restrictions_when_editing(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
shiva = self.example_user("shiva") shiva = self.example_user("shiva")
self.login("cordelia") self.login("cordelia")

View File

@ -398,7 +398,7 @@ class EditMessageSideEffectsTest(ZulipTestCase):
# actual content of these messages.) # actual content of these messages.)
self.assert_length(info["queue_messages"], 2) self.assert_length(info["queue_messages"], 2)
def test_updates_with_followed_topic_wildcard_mention(self) -> None: def test_updates_with_stream_wildcard_mention_in_followed_topic(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
self.subscribe(cordelia, "Scotland") self.subscribe(cordelia, "Scotland")
@ -435,8 +435,8 @@ class EditMessageSideEffectsTest(ZulipTestCase):
user_id=cordelia.id, user_id=cordelia.id,
acting_user_id=hamlet.id, acting_user_id=hamlet.id,
message_id=message_id, message_id=message_id,
followed_topic_wildcard_mention_email_notify=True, stream_wildcard_mention_in_followed_topic_email_notify=True,
followed_topic_wildcard_mention_push_notify=True, stream_wildcard_mention_in_followed_topic_push_notify=True,
already_notified={}, already_notified={},
) )
self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs) self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs)
@ -444,7 +444,7 @@ class EditMessageSideEffectsTest(ZulipTestCase):
# messages will get enqueued. # messages will get enqueued.
self.assert_length(info["queue_messages"], 2) self.assert_length(info["queue_messages"], 2)
def test_updates_with_wildcard_mention(self) -> None: def test_updates_with_stream_wildcard_mention(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")
@ -466,8 +466,8 @@ class EditMessageSideEffectsTest(ZulipTestCase):
user_id=cordelia.id, user_id=cordelia.id,
acting_user_id=hamlet.id, acting_user_id=hamlet.id,
message_id=message_id, message_id=message_id,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
already_notified={}, already_notified={},
) )
self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs) self.assertEqual(info["enqueue_kwargs"], expected_enqueue_kwargs)

View File

@ -1624,11 +1624,11 @@ class StreamMessagesTest(ZulipTestCase):
self.assertEqual(user_message.message.content, content) self.assertEqual(user_message.message.content, content)
self.assertTrue(user_message.flags.mentioned) self.assertTrue(user_message.flags.mentioned)
def send_and_verify_wildcard_mention_message( def send_and_verify_stream_wildcard_mention_message(
self, sender_name: str, test_fails: bool = False, sub_count: int = 16 self, sender_name: str, test_fails: bool = False, sub_count: int = 16
) -> None: ) -> None:
sender = self.example_user(sender_name) sender = self.example_user(sender_name)
content = "@**all** test wildcard mention" content = "@**all** test stream wildcard mention"
with mock.patch("zerver.lib.message.num_subscribers_for_stream_id", return_value=sub_count): with mock.patch("zerver.lib.message.num_subscribers_for_stream_id", return_value=sub_count):
if not test_fails: if not test_fails:
msg_id = self.send_stream_message(sender, "test_stream", content) msg_id = self.send_stream_message(sender, "test_stream", content)
@ -1642,7 +1642,7 @@ class StreamMessagesTest(ZulipTestCase):
): ):
self.send_stream_message(sender, "test_stream", content) self.send_stream_message(sender, "test_stream", content)
def test_wildcard_mention_restrictions(self) -> None: def test_stream_wildcard_mention_restrictions(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")
iago = self.example_user("iago") iago = self.example_user("iago")
polonius = self.example_user("polonius") polonius = self.example_user("polonius")
@ -1661,7 +1661,7 @@ class StreamMessagesTest(ZulipTestCase):
Realm.WILDCARD_MENTION_POLICY_EVERYONE, Realm.WILDCARD_MENTION_POLICY_EVERYONE,
acting_user=None, acting_user=None,
) )
self.send_and_verify_wildcard_mention_message("polonius") self.send_and_verify_stream_wildcard_mention_message("polonius")
do_set_realm_property( do_set_realm_property(
realm, realm,
@ -1669,10 +1669,10 @@ class StreamMessagesTest(ZulipTestCase):
Realm.WILDCARD_MENTION_POLICY_MEMBERS, Realm.WILDCARD_MENTION_POLICY_MEMBERS,
acting_user=None, acting_user=None,
) )
self.send_and_verify_wildcard_mention_message("polonius", test_fails=True) self.send_and_verify_stream_wildcard_mention_message("polonius", test_fails=True)
# There is no restriction on small streams. # There is no restriction on small streams.
self.send_and_verify_wildcard_mention_message("polonius", sub_count=10) self.send_and_verify_stream_wildcard_mention_message("polonius", sub_count=10)
self.send_and_verify_wildcard_mention_message("cordelia") self.send_and_verify_stream_wildcard_mention_message("cordelia")
do_set_realm_property( do_set_realm_property(
realm, realm,
@ -1687,15 +1687,15 @@ class StreamMessagesTest(ZulipTestCase):
shiva.save() shiva.save()
cordelia.date_joined = timezone_now() cordelia.date_joined = timezone_now()
cordelia.save() cordelia.save()
self.send_and_verify_wildcard_mention_message("cordelia", test_fails=True) self.send_and_verify_stream_wildcard_mention_message("cordelia", test_fails=True)
self.send_and_verify_wildcard_mention_message("cordelia", sub_count=10) self.send_and_verify_stream_wildcard_mention_message("cordelia", sub_count=10)
# Administrators and moderators can use wildcard mentions even if they are new. # Administrators and moderators can use wildcard mentions even if they are new.
self.send_and_verify_wildcard_mention_message("iago") self.send_and_verify_stream_wildcard_mention_message("iago")
self.send_and_verify_wildcard_mention_message("shiva") self.send_and_verify_stream_wildcard_mention_message("shiva")
cordelia.date_joined = timezone_now() - datetime.timedelta(days=11) cordelia.date_joined = timezone_now() - datetime.timedelta(days=11)
cordelia.save() cordelia.save()
self.send_and_verify_wildcard_mention_message("cordelia") self.send_and_verify_stream_wildcard_mention_message("cordelia")
do_set_realm_property( do_set_realm_property(
realm, realm,
@ -1703,25 +1703,25 @@ class StreamMessagesTest(ZulipTestCase):
Realm.WILDCARD_MENTION_POLICY_MODERATORS, Realm.WILDCARD_MENTION_POLICY_MODERATORS,
acting_user=None, acting_user=None,
) )
self.send_and_verify_wildcard_mention_message("cordelia", test_fails=True) self.send_and_verify_stream_wildcard_mention_message("cordelia", test_fails=True)
self.send_and_verify_wildcard_mention_message("cordelia", sub_count=10) self.send_and_verify_stream_wildcard_mention_message("cordelia", sub_count=10)
self.send_and_verify_wildcard_mention_message("shiva") self.send_and_verify_stream_wildcard_mention_message("shiva")
cordelia.date_joined = timezone_now() cordelia.date_joined = timezone_now()
cordelia.save() cordelia.save()
do_set_realm_property( do_set_realm_property(
realm, "wildcard_mention_policy", Realm.WILDCARD_MENTION_POLICY_ADMINS, acting_user=None realm, "wildcard_mention_policy", Realm.WILDCARD_MENTION_POLICY_ADMINS, acting_user=None
) )
self.send_and_verify_wildcard_mention_message("shiva", test_fails=True) self.send_and_verify_stream_wildcard_mention_message("shiva", test_fails=True)
# There is no restriction on small streams. # There is no restriction on small streams.
self.send_and_verify_wildcard_mention_message("shiva", sub_count=10) self.send_and_verify_stream_wildcard_mention_message("shiva", sub_count=10)
self.send_and_verify_wildcard_mention_message("iago") self.send_and_verify_stream_wildcard_mention_message("iago")
do_set_realm_property( do_set_realm_property(
realm, "wildcard_mention_policy", Realm.WILDCARD_MENTION_POLICY_NOBODY, acting_user=None realm, "wildcard_mention_policy", Realm.WILDCARD_MENTION_POLICY_NOBODY, acting_user=None
) )
self.send_and_verify_wildcard_mention_message("iago", test_fails=True) self.send_and_verify_stream_wildcard_mention_message("iago", test_fails=True)
self.send_and_verify_wildcard_mention_message("iago", sub_count=10) self.send_and_verify_stream_wildcard_mention_message("iago", sub_count=10)
def test_invalid_wildcard_mention_policy(self) -> None: def test_invalid_wildcard_mention_policy(self) -> None:
cordelia = self.example_user("cordelia") cordelia = self.example_user("cordelia")

View File

@ -40,13 +40,13 @@ class TestNotificationData(ZulipTestCase):
) )
self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
# Wildcard mention # Stream Wildcard mention
user_data = self.create_user_notifications_data_object( user_data = self.create_user_notifications_data_object(
user_id=user_id, wildcard_mention_push_notify=True user_id=user_id, stream_wildcard_mention_push_notify=True
) )
self.assertEqual( self.assertEqual(
user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True),
"wildcard_mentioned", "stream_wildcard_mentioned",
) )
self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
@ -70,13 +70,13 @@ class TestNotificationData(ZulipTestCase):
) )
self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
# Followed Topic wildcard mention # Stream wildcard mention in followed topic
user_data = self.create_user_notifications_data_object( user_data = self.create_user_notifications_data_object(
user_id=user_id, followed_topic_wildcard_mention_push_notify=True user_id=user_id, stream_wildcard_mention_in_followed_topic_push_notify=True
) )
self.assertEqual( self.assertEqual(
user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True),
"followed_topic_wildcard_mentioned", "stream_wildcard_mentioned_in_followed_topic",
) )
self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_push_notifiable(acting_user_id=acting_user_id, idle=True))
@ -108,8 +108,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
) )
self.assertEqual( self.assertEqual(
user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True),
@ -124,8 +124,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
) )
self.assertEqual( self.assertEqual(
user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_push_notification_trigger(acting_user_id=acting_user_id, idle=True),
@ -140,8 +140,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
disable_external_notifications=True, disable_external_notifications=True,
) )
self.assertEqual( self.assertEqual(
@ -182,13 +182,13 @@ class TestNotificationData(ZulipTestCase):
) )
self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
# Wildcard mention # Stream Wildcard mention
user_data = self.create_user_notifications_data_object( user_data = self.create_user_notifications_data_object(
user_id=user_id, wildcard_mention_email_notify=True user_id=user_id, stream_wildcard_mention_email_notify=True
) )
self.assertEqual( self.assertEqual(
user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True),
"wildcard_mentioned", "stream_wildcard_mentioned",
) )
self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
@ -212,13 +212,13 @@ class TestNotificationData(ZulipTestCase):
) )
self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
# Followed Topic wildcard mention # Stream wildcard mention in followed topic
user_data = self.create_user_notifications_data_object( user_data = self.create_user_notifications_data_object(
user_id=user_id, followed_topic_wildcard_mention_email_notify=True user_id=user_id, stream_wildcard_mention_in_followed_topic_email_notify=True
) )
self.assertEqual( self.assertEqual(
user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True),
"followed_topic_wildcard_mentioned", "stream_wildcard_mentioned_in_followed_topic",
) )
self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True)) self.assertTrue(user_data.is_email_notifiable(acting_user_id=acting_user_id, idle=True))
@ -241,8 +241,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
) )
self.assertEqual( self.assertEqual(
user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True),
@ -257,8 +257,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
) )
self.assertEqual( self.assertEqual(
user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True), user_data.get_email_notification_trigger(acting_user_id=acting_user_id, idle=True),
@ -273,8 +273,8 @@ class TestNotificationData(ZulipTestCase):
pm_email_notify=True, pm_email_notify=True,
mention_push_notify=True, mention_push_notify=True,
mention_email_notify=True, mention_email_notify=True,
wildcard_mention_push_notify=True, stream_wildcard_mention_push_notify=True,
wildcard_mention_email_notify=True, stream_wildcard_mention_email_notify=True,
disable_external_notifications=True, disable_external_notifications=True,
) )
self.assertEqual( self.assertEqual(
@ -306,10 +306,10 @@ class TestNotificationData(ZulipTestCase):
muted_sender_user_ids=set(), muted_sender_user_ids=set(),
stream_email_user_ids=set(), stream_email_user_ids=set(),
stream_push_user_ids=set(), stream_push_user_ids=set(),
wildcard_mention_user_ids=set(), stream_wildcard_mention_user_ids=set(),
followed_topic_email_user_ids=set(), followed_topic_email_user_ids=set(),
followed_topic_push_user_ids=set(), followed_topic_push_user_ids=set(),
followed_topic_wildcard_mention_user_ids=set(), stream_wildcard_mention_in_followed_topic_user_ids=set(),
) )
self.assertEqual(user_data.is_notifiable(acting_user_id=1000, idle=True), notifiable) self.assertEqual(user_data.is_notifiable(acting_user_id=1000, idle=True), notifiable)

View File

@ -1675,7 +1675,7 @@ class HandlePushNotificationTest(PushNotificationTest):
{"message_id": personal_message_id, "trigger": "private_message"}, {"message_id": personal_message_id, "trigger": "private_message"},
) )
# Followed Topic wildcard mention should NOT soft reactivate the user # Stream wildcard mention in followed topic should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True): with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True):
mention = "@**all**" mention = "@**all**"
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention) stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention)
@ -1683,18 +1683,18 @@ class HandlePushNotificationTest(PushNotificationTest):
self.user_profile.id, self.user_profile.id,
{ {
"message_id": stream_mentioned_message_id, "message_id": stream_mentioned_message_id,
"trigger": "followed_topic_wildcard_mentioned", "trigger": "stream_wildcard_mentioned_in_followed_topic",
}, },
) )
# Wildcard mention should NOT soft reactivate the user # Stream Wildcard mention should NOT soft reactivate the user
with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True): with self.soft_deactivate_and_check_long_term_idle(self.user_profile, expected=True):
# Soft reactivate the user by sending a personal message # Soft reactivate the user by sending a personal message
mention = "@**all**" mention = "@**all**"
stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention) stream_mentioned_message_id = self.send_stream_message(othello, "Denmark", mention)
handle_push_notification( handle_push_notification(
self.user_profile.id, self.user_profile.id,
{"message_id": stream_mentioned_message_id, "trigger": "wildcard_mentioned"}, {"message_id": stream_mentioned_message_id, "trigger": "stream_wildcard_mentioned"},
) )
# Group mention should NOT soft reactivate the user # Group mention should NOT soft reactivate the user
@ -2070,12 +2070,12 @@ class TestGetAPNsPayload(PushNotificationTest):
} }
self.assertDictEqual(payload, expected) self.assertDictEqual(payload, expected)
def test_get_message_payload_apns_followed_topic_wildcard_mention(self) -> None: def test_get_message_payload_apns_stream_wildcard_mention_in_followed_topic(self) -> None:
user_profile = self.example_user("othello") user_profile = self.example_user("othello")
stream = Stream.objects.filter(name="Verona").get() stream = Stream.objects.filter(name="Verona").get()
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id) message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
payload = get_message_payload_apns( payload = get_message_payload_apns(
user_profile, message, NotificationTriggers.FOLLOWED_TOPIC_WILDCARD_MENTION user_profile, message, NotificationTriggers.STREAM_WILDCARD_MENTION_IN_FOLLOWED_TOPIC
) )
expected = { expected = {
"alert": { "alert": {
@ -2108,7 +2108,7 @@ class TestGetAPNsPayload(PushNotificationTest):
stream = Stream.objects.filter(name="Verona").get() stream = Stream.objects.filter(name="Verona").get()
message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id) message = self.get_message(Recipient.STREAM, stream.id, stream.realm_id)
payload = get_message_payload_apns( payload = get_message_payload_apns(
user_profile, message, NotificationTriggers.WILDCARD_MENTION user_profile, message, NotificationTriggers.STREAM_WILDCARD_MENTION
) )
expected = { expected = {
"alert": { "alert": {
@ -2243,12 +2243,14 @@ class TestGetGCMPayload(PushNotificationTest):
mentioned_user_group_name="mobile_team", mentioned_user_group_name="mobile_team",
) )
def test_get_message_payload_gcm_followed_topic_wildcard_mention(self) -> None: def test_get_message_payload_gcm_stream_wildcard_mention_in_followed_topic(self) -> None:
self._test_get_message_payload_gcm_mentions("followed_topic_wildcard_mentioned", "TODO")
def test_get_message_payload_gcm_wildcard_mention(self) -> None:
self._test_get_message_payload_gcm_mentions( self._test_get_message_payload_gcm_mentions(
"wildcard_mentioned", "King Hamlet mentioned everyone in #Verona" "stream_wildcard_mentioned_in_followed_topic", "TODO"
)
def test_get_message_payload_gcm_stream_wildcard_mention(self) -> None:
self._test_get_message_payload_gcm_mentions(
"stream_wildcard_mentioned", "King Hamlet mentioned everyone in #Verona"
) )
def test_get_message_payload_gcm_private_message(self) -> None: def test_get_message_payload_gcm_private_message(self) -> None:

View File

@ -623,7 +623,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
def assert_num_possible_users( def assert_num_possible_users(
expected_count: int, expected_count: int,
*, *,
possible_wildcard_mention: bool = False, possible_stream_wildcard_mention: bool = False,
possibly_mentioned_user_ids: AbstractSet[int] = set(), possibly_mentioned_user_ids: AbstractSet[int] = set(),
) -> None: ) -> None:
self.assertEqual( self.assertEqual(
@ -632,7 +632,7 @@ class SoftDeactivationMessageTest(ZulipTestCase):
realm_id=realm_id, realm_id=realm_id,
stream_id=stream_id, stream_id=stream_id,
topic_name=topic_name, topic_name=topic_name,
possible_wildcard_mention=possible_wildcard_mention, possible_stream_wildcard_mention=possible_stream_wildcard_mention,
possibly_mentioned_user_ids=possibly_mentioned_user_ids, possibly_mentioned_user_ids=possibly_mentioned_user_ids,
) )
), ),
@ -642,12 +642,12 @@ class SoftDeactivationMessageTest(ZulipTestCase):
def assert_stream_message_sent_to_idle_user( def assert_stream_message_sent_to_idle_user(
content: str, content: str,
*, *,
possible_wildcard_mention: bool = False, possible_stream_wildcard_mention: bool = False,
possibly_mentioned_user_ids: AbstractSet[int] = set(), possibly_mentioned_user_ids: AbstractSet[int] = set(),
) -> None: ) -> None:
assert_num_possible_users( assert_num_possible_users(
expected_count=3, expected_count=3,
possible_wildcard_mention=possible_wildcard_mention, possible_stream_wildcard_mention=possible_stream_wildcard_mention,
possibly_mentioned_user_ids=possibly_mentioned_user_ids, possibly_mentioned_user_ids=possibly_mentioned_user_ids,
) )
general_user_msg_count = len(get_user_messages(cordelia)) general_user_msg_count = len(get_user_messages(cordelia))
@ -756,15 +756,15 @@ class SoftDeactivationMessageTest(ZulipTestCase):
assert_stream_message_not_sent_to_idle_user("Test @**Cordelia, Lear's daughter** mention") assert_stream_message_not_sent_to_idle_user("Test @**Cordelia, Lear's daughter** mention")
# Test UserMessage row is created while user is deactivated if # Test UserMessage row is created while user is deactivated if
# there is a wildcard mention such as @all or @everyone # there is a stream wildcard mention such as @all or @everyone
assert_stream_message_sent_to_idle_user( assert_stream_message_sent_to_idle_user(
"Test @**all** mention", possible_wildcard_mention=True "Test @**all** mention", possible_stream_wildcard_mention=True
) )
assert_stream_message_sent_to_idle_user( assert_stream_message_sent_to_idle_user(
"Test @**everyone** mention", possible_wildcard_mention=True "Test @**everyone** mention", possible_stream_wildcard_mention=True
) )
assert_stream_message_sent_to_idle_user( assert_stream_message_sent_to_idle_user(
"Test @**stream** mention", possible_wildcard_mention=True "Test @**stream** mention", possible_stream_wildcard_mention=True
) )
assert_stream_message_not_sent_to_idle_user("Test @**bogus** mention") assert_stream_message_not_sent_to_idle_user("Test @**bogus** mention")

View File

@ -1755,7 +1755,7 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=False, possible_stream_wildcard_mention=False,
) )
all_user_ids = {hamlet.id, cordelia.id, othello.id} all_user_ids = {hamlet.id, cordelia.id, othello.id}
@ -1767,10 +1767,10 @@ class RecipientInfoTest(ZulipTestCase):
pm_mention_push_disabled_user_ids=set(), pm_mention_push_disabled_user_ids=set(),
stream_push_user_ids=set(), stream_push_user_ids=set(),
stream_email_user_ids=set(), stream_email_user_ids=set(),
wildcard_mention_user_ids=set(), stream_wildcard_mention_user_ids=set(),
followed_topic_push_user_ids=set(), followed_topic_push_user_ids=set(),
followed_topic_email_user_ids=set(), followed_topic_email_user_ids=set(),
followed_topic_wildcard_mention_user_ids=set(), stream_wildcard_mention_in_followed_topic_user_ids=set(),
muted_sender_user_ids=set(), muted_sender_user_ids=set(),
um_eligible_user_ids=all_user_ids, um_eligible_user_ids=all_user_ids,
long_term_idle_user_ids=set(), long_term_idle_user_ids=set(),
@ -1789,7 +1789,7 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=False, possible_stream_wildcard_mention=False,
) )
self.assertEqual(info.pm_mention_email_disabled_user_ids, {hamlet.id}) self.assertEqual(info.pm_mention_email_disabled_user_ids, {hamlet.id})
self.assertEqual(info.pm_mention_push_disabled_user_ids, {hamlet.id}) self.assertEqual(info.pm_mention_push_disabled_user_ids, {hamlet.id})
@ -1806,19 +1806,19 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=False, possible_stream_wildcard_mention=False,
) )
self.assertEqual(info.stream_push_user_ids, {hamlet.id}) self.assertEqual(info.stream_push_user_ids, {hamlet.id})
self.assertEqual(info.wildcard_mention_user_ids, set()) self.assertEqual(info.stream_wildcard_mention_user_ids, set())
info = get_recipient_info( info = get_recipient_info(
realm_id=realm.id, realm_id=realm.id,
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=True, possible_stream_wildcard_mention=True,
) )
self.assertEqual(info.wildcard_mention_user_ids, {hamlet.id, othello.id}) self.assertEqual(info.stream_wildcard_mention_user_ids, {hamlet.id, othello.id})
sub = get_subscription(stream_name, hamlet) sub = get_subscription(stream_name, hamlet)
sub.push_notifications = False sub.push_notifications = False
@ -1884,22 +1884,22 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=False, possible_stream_wildcard_mention=False,
) )
self.assertEqual(info.stream_push_user_ids, set()) self.assertEqual(info.stream_push_user_ids, set())
self.assertEqual(info.wildcard_mention_user_ids, set()) self.assertEqual(info.stream_wildcard_mention_user_ids, set())
info = get_recipient_info( info = get_recipient_info(
realm_id=realm.id, realm_id=realm.id,
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=True, possible_stream_wildcard_mention=True,
) )
self.assertEqual(info.stream_push_user_ids, set()) self.assertEqual(info.stream_push_user_ids, set())
# Since Hamlet has muted the stream and Cordelia has disabled # Since Hamlet has muted the stream and Cordelia has disabled
# wildcard notifications, it should just be Othello here. # wildcard notifications, it should just be Othello here.
self.assertEqual(info.wildcard_mention_user_ids, {othello.id}) self.assertEqual(info.stream_wildcard_mention_user_ids, {othello.id})
# If Hamlet mutes Cordelia, he should be in `muted_sender_user_ids` for a message # If Hamlet mutes Cordelia, he should be in `muted_sender_user_ids` for a message
# sent by Cordelia. # sent by Cordelia.
@ -1909,7 +1909,7 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=cordelia.id, sender_id=cordelia.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=True, possible_stream_wildcard_mention=True,
) )
self.assertTrue(hamlet.id in info.muted_sender_user_ids) self.assertTrue(hamlet.id in info.muted_sender_user_ids)
@ -1922,11 +1922,11 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=True, possible_stream_wildcard_mention=True,
) )
self.assertEqual(info.stream_push_user_ids, set()) self.assertEqual(info.stream_push_user_ids, set())
# Verify that stream-level wildcard_mentions_notify=False works correctly. # Verify that stream-level wildcard_mentions_notify=False works correctly.
self.assertEqual(info.wildcard_mention_user_ids, set()) self.assertEqual(info.stream_wildcard_mention_user_ids, set())
# Verify that True works as expected as well # Verify that True works as expected as well
sub = get_subscription(stream_name, othello) sub = get_subscription(stream_name, othello)
@ -1938,10 +1938,10 @@ class RecipientInfoTest(ZulipTestCase):
recipient=recipient, recipient=recipient,
sender_id=hamlet.id, sender_id=hamlet.id,
stream_topic=stream_topic, stream_topic=stream_topic,
possible_wildcard_mention=True, possible_stream_wildcard_mention=True,
) )
self.assertEqual(info.stream_push_user_ids, set()) self.assertEqual(info.stream_push_user_ids, set())
self.assertEqual(info.wildcard_mention_user_ids, {othello.id}) self.assertEqual(info.stream_wildcard_mention_user_ids, {othello.id})
# Add a service bot. # Add a service bot.
service_bot = do_create_user( service_bot = do_create_user(
@ -2005,7 +2005,7 @@ class RecipientInfoTest(ZulipTestCase):
) )
self.assertEqual(info.followed_topic_email_user_ids, {hamlet.id}) self.assertEqual(info.followed_topic_email_user_ids, {hamlet.id})
self.assertEqual(info.followed_topic_push_user_ids, {hamlet.id}) self.assertEqual(info.followed_topic_push_user_ids, {hamlet.id})
self.assertEqual(info.followed_topic_wildcard_mention_user_ids, {hamlet.id}) self.assertEqual(info.stream_wildcard_mention_in_followed_topic_user_ids, {hamlet.id})
# Omit Hamlet from followed_topic_email_user_ids # Omit Hamlet from followed_topic_email_user_ids
do_change_user_setting( do_change_user_setting(
@ -2021,7 +2021,7 @@ class RecipientInfoTest(ZulipTestCase):
False, False,
acting_user=None, acting_user=None,
) )
# Omit Hamlet from followed_topic_wildcard_mention_user_ids # Omit Hamlet from stream_wildcard_mention_in_followed_topic_user_ids
do_change_user_setting( do_change_user_setting(
hamlet, hamlet,
"enable_followed_topic_wildcard_mentions_notify", "enable_followed_topic_wildcard_mentions_notify",
@ -2037,7 +2037,7 @@ class RecipientInfoTest(ZulipTestCase):
) )
self.assertEqual(info.followed_topic_email_user_ids, set()) self.assertEqual(info.followed_topic_email_user_ids, set())
self.assertEqual(info.followed_topic_push_user_ids, set()) self.assertEqual(info.followed_topic_push_user_ids, set())
self.assertEqual(info.followed_topic_wildcard_mention_user_ids, set()) self.assertEqual(info.stream_wildcard_mention_in_followed_topic_user_ids, set())
def test_get_recipient_info_invalid_recipient_type(self) -> None: def test_get_recipient_info_invalid_recipient_type(self) -> None:
hamlet = self.example_user("hamlet") hamlet = self.example_user("hamlet")

View File

@ -774,6 +774,30 @@ def missedmessage_hook(
internal_data = event.get("internal_data", {}) internal_data = event.get("internal_data", {})
sender_id = event["message"]["sender_id"] sender_id = event["message"]["sender_id"]
# TODO/compatibility: Translation code for the rename of
# `wildcard_mention_push_notify` to `stream_wildcard_mention_push_notify`.
# Remove this when one can no longer directly upgrade from 7.x to main.
stream_wildcard_mention_push_notify = False
if "stream_wildcard_mention_push_notify" in internal_data:
stream_wildcard_mention_push_notify = internal_data.get(
"stream_wildcard_mention_push_notify"
)
elif "wildcard_mention_push_notify" in internal_data:
stream_wildcard_mention_push_notify = internal_data.get("wildcard_mention_push_notify")
# TODO/compatibility: Translation code for the rename of
# `wildcard_mention_email_notify` to `stream_wildcard_mention_email_notify`.
# Remove this when one can no longer directly upgrade from 7.x to main.
stream_wildcard_mention_email_notify = False
if "stream_wildcard_mention_email_notify" in internal_data:
stream_wildcard_mention_email_notify = internal_data.get(
"stream_wildcard_mention_email_notify"
)
elif "wildcard_mention_email_notify" in internal_data:
stream_wildcard_mention_email_notify = internal_data.get(
"wildcard_mention_email_notify"
)
user_notifications_data = UserMessageNotificationsData( user_notifications_data = UserMessageNotificationsData(
user_id=user_profile_id, user_id=user_profile_id,
sender_is_muted=internal_data.get("sender_is_muted", False), sender_is_muted=internal_data.get("sender_is_muted", False),
@ -781,17 +805,17 @@ def missedmessage_hook(
pm_email_notify=internal_data.get("pm_email_notify", False), pm_email_notify=internal_data.get("pm_email_notify", False),
mention_push_notify=internal_data.get("mention_push_notify", False), mention_push_notify=internal_data.get("mention_push_notify", False),
mention_email_notify=internal_data.get("mention_email_notify", False), mention_email_notify=internal_data.get("mention_email_notify", False),
wildcard_mention_push_notify=internal_data.get("wildcard_mention_push_notify", False), stream_wildcard_mention_push_notify=stream_wildcard_mention_push_notify,
wildcard_mention_email_notify=internal_data.get("wildcard_mention_email_notify", False), stream_wildcard_mention_email_notify=stream_wildcard_mention_email_notify,
stream_push_notify=internal_data.get("stream_push_notify", False), stream_push_notify=internal_data.get("stream_push_notify", False),
stream_email_notify=internal_data.get("stream_email_notify", False), stream_email_notify=internal_data.get("stream_email_notify", False),
followed_topic_push_notify=internal_data.get("followed_topic_push_notify", False), followed_topic_push_notify=internal_data.get("followed_topic_push_notify", False),
followed_topic_email_notify=internal_data.get("followed_topic_email_notify", False), followed_topic_email_notify=internal_data.get("followed_topic_email_notify", False),
followed_topic_wildcard_mention_push_notify=internal_data.get( stream_wildcard_mention_in_followed_topic_push_notify=internal_data.get(
"followed_topic_wildcard_mention_push_notify", False "stream_wildcard_mention_in_followed_topic_push_notify", False
), ),
followed_topic_wildcard_mention_email_notify=internal_data.get( stream_wildcard_mention_in_followed_topic_email_notify=internal_data.get(
"followed_topic_wildcard_mention_email_notify", False "stream_wildcard_mention_in_followed_topic_email_notify", False
), ),
# Since one is by definition idle, we don't need to check online_push_enabled # Since one is by definition idle, we don't need to check online_push_enabled
online_push_enabled=False, online_push_enabled=False,
@ -945,11 +969,22 @@ def process_message_event(
) )
stream_push_user_ids = set(event_template.get("stream_push_user_ids", [])) stream_push_user_ids = set(event_template.get("stream_push_user_ids", []))
stream_email_user_ids = set(event_template.get("stream_email_user_ids", [])) stream_email_user_ids = set(event_template.get("stream_email_user_ids", []))
wildcard_mention_user_ids = set(event_template.get("wildcard_mention_user_ids", []))
# TODO/compatibility: Translation code for the rename of
# `wildcard_mention_user_ids` to `stream_wildcard_mention_user_ids`.
# Remove this when one can no longer directly upgrade from 7.x to main.
stream_wildcard_mention_user_ids = set()
if "stream_wildcard_mention_user_ids" in event_template:
stream_wildcard_mention_user_ids = set(
event_template.get("stream_wildcard_mention_user_ids", [])
)
elif "wildcard_mention_user_ids" in event_template:
stream_wildcard_mention_user_ids = set(event_template.get("wildcard_mention_user_ids", []))
followed_topic_push_user_ids = set(event_template.get("followed_topic_push_user_ids", [])) followed_topic_push_user_ids = set(event_template.get("followed_topic_push_user_ids", []))
followed_topic_email_user_ids = set(event_template.get("followed_topic_email_user_ids", [])) followed_topic_email_user_ids = set(event_template.get("followed_topic_email_user_ids", []))
followed_topic_wildcard_mention_user_ids = set( stream_wildcard_mention_in_followed_topic_user_ids = set(
event_template.get("followed_topic_wildcard_mention_user_ids", []) event_template.get("stream_wildcard_mention_in_followed_topic_user_ids", [])
) )
muted_sender_user_ids = set(event_template.get("muted_sender_user_ids", [])) muted_sender_user_ids = set(event_template.get("muted_sender_user_ids", []))
all_bot_user_ids = set(event_template.get("all_bot_user_ids", [])) all_bot_user_ids = set(event_template.get("all_bot_user_ids", []))
@ -1000,10 +1035,10 @@ def process_message_event(
pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids, pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids,
stream_push_user_ids=stream_push_user_ids, stream_push_user_ids=stream_push_user_ids,
stream_email_user_ids=stream_email_user_ids, stream_email_user_ids=stream_email_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids, stream_wildcard_mention_user_ids=stream_wildcard_mention_user_ids,
followed_topic_push_user_ids=followed_topic_push_user_ids, followed_topic_push_user_ids=followed_topic_push_user_ids,
followed_topic_email_user_ids=followed_topic_email_user_ids, followed_topic_email_user_ids=followed_topic_email_user_ids,
followed_topic_wildcard_mention_user_ids=followed_topic_wildcard_mention_user_ids, stream_wildcard_mention_in_followed_topic_user_ids=stream_wildcard_mention_in_followed_topic_user_ids,
muted_sender_user_ids=muted_sender_user_ids, muted_sender_user_ids=muted_sender_user_ids,
all_bot_user_ids=all_bot_user_ids, all_bot_user_ids=all_bot_user_ids,
) )
@ -1154,11 +1189,22 @@ def process_message_update_event(
) )
stream_push_user_ids = set(event_template.pop("stream_push_user_ids", [])) stream_push_user_ids = set(event_template.pop("stream_push_user_ids", []))
stream_email_user_ids = set(event_template.pop("stream_email_user_ids", [])) stream_email_user_ids = set(event_template.pop("stream_email_user_ids", []))
wildcard_mention_user_ids = set(event_template.pop("wildcard_mention_user_ids", []))
# TODO/compatibility: Translation code for the rename of
# `wildcard_mention_user_ids` to `stream_wildcard_mention_user_ids`.
# Remove this when one can no longer directly upgrade from 7.x to main.
stream_wildcard_mention_user_ids = set()
if "stream_wildcard_mention_user_ids" in event_template:
stream_wildcard_mention_user_ids = set(
event_template.pop("stream_wildcard_mention_user_ids")
)
elif "wildcard_mention_user_ids" in event_template:
stream_wildcard_mention_user_ids = set(event_template.pop("wildcard_mention_user_ids"))
followed_topic_push_user_ids = set(event_template.pop("followed_topic_push_user_ids", [])) followed_topic_push_user_ids = set(event_template.pop("followed_topic_push_user_ids", []))
followed_topic_email_user_ids = set(event_template.pop("followed_topic_email_user_ids", [])) followed_topic_email_user_ids = set(event_template.pop("followed_topic_email_user_ids", []))
followed_topic_wildcard_mention_user_ids = set( stream_wildcard_mention_in_followed_topic_user_ids = set(
event_template.pop("followed_topic_wildcard_mention_user_ids", []) event_template.pop("stream_wildcard_mention_in_followed_topic_user_ids", [])
) )
muted_sender_user_ids = set(event_template.pop("muted_sender_user_ids", [])) muted_sender_user_ids = set(event_template.pop("muted_sender_user_ids", []))
all_bot_user_ids = set(event_template.pop("all_bot_user_ids", [])) all_bot_user_ids = set(event_template.pop("all_bot_user_ids", []))
@ -1219,10 +1265,10 @@ def process_message_update_event(
pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids, pm_mention_email_disabled_user_ids=pm_mention_email_disabled_user_ids,
stream_push_user_ids=stream_push_user_ids, stream_push_user_ids=stream_push_user_ids,
stream_email_user_ids=stream_email_user_ids, stream_email_user_ids=stream_email_user_ids,
wildcard_mention_user_ids=wildcard_mention_user_ids, stream_wildcard_mention_user_ids=stream_wildcard_mention_user_ids,
followed_topic_push_user_ids=followed_topic_push_user_ids, followed_topic_push_user_ids=followed_topic_push_user_ids,
followed_topic_email_user_ids=followed_topic_email_user_ids, followed_topic_email_user_ids=followed_topic_email_user_ids,
followed_topic_wildcard_mention_user_ids=followed_topic_wildcard_mention_user_ids, stream_wildcard_mention_in_followed_topic_user_ids=stream_wildcard_mention_in_followed_topic_user_ids,
muted_sender_user_ids=muted_sender_user_ids, muted_sender_user_ids=muted_sender_user_ids,
all_bot_user_ids=all_bot_user_ids, all_bot_user_ids=all_bot_user_ids,
) )
@ -1343,7 +1389,7 @@ def reformat_legacy_send_message_event(
modern_event["online_push_user_ids"] = [] modern_event["online_push_user_ids"] = []
modern_event["stream_push_user_ids"] = [] modern_event["stream_push_user_ids"] = []
modern_event["stream_email_user_ids"] = [] modern_event["stream_email_user_ids"] = []
modern_event["wildcard_mention_user_ids"] = [] modern_event["stream_wildcard_mention_user_ids"] = []
modern_event["muted_sender_user_ids"] = [] modern_event["muted_sender_user_ids"] = []
for user in user_dicts: for user in user_dicts:
@ -1354,7 +1400,7 @@ def reformat_legacy_send_message_event(
if user.pop("stream_email_notify", False): if user.pop("stream_email_notify", False):
modern_event["stream_email_user_ids"].append(user_id) modern_event["stream_email_user_ids"].append(user_id)
if user.pop("wildcard_mention_notify", False): if user.pop("wildcard_mention_notify", False):
modern_event["wildcard_mention_user_ids"].append(user_id) modern_event["stream_wildcard_mention_user_ids"].append(user_id)
if user.pop("sender_is_muted", False): if user.pop("sender_is_muted", False):
modern_event["muted_sender_user_ids"].append(user_id) modern_event["muted_sender_user_ids"].append(user_id)