actions: Rename *topic local variables to *topic_name.

This is preparatory work towards adding a Topic model.
We plan to use the local variable name as 'topic' for
the Topic model objects.

Currently, we use *topic as the local variable name for
topic names.

We rename local variables of the form *topic to *topic_name
so that we don't need to think about type collisions in
individual code paths where we might want to talk about both
Topic objects and strings for the topic name.
This commit is contained in:
Prakhar Pratyush 2024-01-13 14:25:16 +05:30 committed by Tim Abbott
parent 7e1d0adb6e
commit 1eef052bd1
16 changed files with 103 additions and 99 deletions

View File

@ -319,7 +319,7 @@ def do_create_realm(
support_link=support_url, support_link=support_url,
type=organization_type, type=organization_type,
) )
topic = "new organizations" topic_name = "new organizations"
try: try:
signups_stream = get_signups_stream(admin_realm) signups_stream = get_signups_stream(admin_realm)
@ -327,7 +327,7 @@ def do_create_realm(
internal_send_stream_message( internal_send_stream_message(
sender, sender,
signups_stream, signups_stream,
topic, topic_name,
message, message,
) )
except Stream.DoesNotExist: # nocoverage except Stream.DoesNotExist: # nocoverage

View File

@ -123,8 +123,8 @@ def maybe_send_resolve_topic_notifications(
*, *,
user_profile: UserProfile, user_profile: UserProfile,
stream: Stream, stream: Stream,
old_topic: str, old_topic_name: str,
new_topic: str, new_topic_name: str,
changed_messages: List[Message], changed_messages: List[Message],
) -> Optional[int]: ) -> Optional[int]:
"""Returns resolved_topic_message_id if resolve topic notifications were in fact sent.""" """Returns resolved_topic_message_id if resolve topic notifications were in fact sent."""
@ -132,12 +132,12 @@ def maybe_send_resolve_topic_notifications(
# #
# This logic is designed to treat removing a weird "✔ ✔✔ " # This logic is designed to treat removing a weird "✔ ✔✔ "
# prefix as unresolving the topic. # prefix as unresolving the topic.
topic_resolved: bool = new_topic.startswith(RESOLVED_TOPIC_PREFIX) and not old_topic.startswith( topic_resolved: bool = new_topic_name.startswith(
RESOLVED_TOPIC_PREFIX RESOLVED_TOPIC_PREFIX
) ) and not old_topic_name.startswith(RESOLVED_TOPIC_PREFIX)
topic_unresolved: bool = old_topic.startswith( topic_unresolved: bool = old_topic_name.startswith(
RESOLVED_TOPIC_PREFIX RESOLVED_TOPIC_PREFIX
) and not new_topic.startswith(RESOLVED_TOPIC_PREFIX) ) and not new_topic_name.startswith(RESOLVED_TOPIC_PREFIX)
if not topic_resolved and not topic_unresolved: if not topic_resolved and not topic_unresolved:
# If there's some other weird topic that does not toggle the # If there's some other weird topic that does not toggle the
@ -174,7 +174,7 @@ def maybe_send_resolve_topic_notifications(
resolved_topic_message_id = internal_send_stream_message( resolved_topic_message_id = internal_send_stream_message(
sender, sender,
stream, stream,
new_topic, new_topic_name,
notification_string.format( notification_string.format(
user=user_mention, user=user_mention,
), ),
@ -188,10 +188,10 @@ def send_message_moved_breadcrumbs(
target_message: Message, target_message: Message,
user_profile: UserProfile, user_profile: UserProfile,
old_stream: Stream, old_stream: Stream,
old_topic: str, old_topic_name: str,
old_thread_notification_string: Optional[StrPromise], old_thread_notification_string: Optional[StrPromise],
new_stream: Stream, new_stream: Stream,
new_topic: Optional[str], new_topic_name: Optional[str],
new_thread_notification_string: Optional[StrPromise], new_thread_notification_string: Optional[StrPromise],
changed_messages_count: int, changed_messages_count: int,
) -> None: ) -> None:
@ -200,17 +200,17 @@ def send_message_moved_breadcrumbs(
# happened. # happened.
sender = get_system_bot(settings.NOTIFICATION_BOT, old_stream.realm_id) sender = get_system_bot(settings.NOTIFICATION_BOT, old_stream.realm_id)
if new_topic is None: if new_topic_name is None:
new_topic = old_topic new_topic_name = old_topic_name
user_mention = silent_mention_syntax_for_user(user_profile) user_mention = silent_mention_syntax_for_user(user_profile)
old_topic_link = f"#**{old_stream.name}>{old_topic}**" old_topic_link = f"#**{old_stream.name}>{old_topic_name}**"
new_topic_link = f"#**{new_stream.name}>{new_topic}**" new_topic_link = f"#**{new_stream.name}>{new_topic_name}**"
message = { message = {
"id": target_message.id, "id": target_message.id,
"stream_id": new_stream.id, "stream_id": new_stream.id,
"display_recipient": new_stream.name, "display_recipient": new_stream.name,
"topic": new_topic, "topic": new_topic_name,
} }
moved_message_link = near_stream_message_url(target_message.realm, message) moved_message_link = near_stream_message_url(target_message.realm, message)
@ -219,7 +219,7 @@ def send_message_moved_breadcrumbs(
internal_send_stream_message( internal_send_stream_message(
sender, sender,
new_stream, new_stream,
new_topic, new_topic_name,
new_thread_notification_string.format( new_thread_notification_string.format(
message_link=moved_message_link, message_link=moved_message_link,
old_location=old_topic_link, old_location=old_topic_link,
@ -234,7 +234,7 @@ def send_message_moved_breadcrumbs(
internal_send_stream_message( internal_send_stream_message(
sender, sender,
old_stream, old_stream,
old_topic, old_topic_name,
old_thread_notification_string.format( old_thread_notification_string.format(
user=user_mention, user=user_mention,
new_location=new_topic_link, new_location=new_topic_link,
@ -619,11 +619,11 @@ def do_update_message(
assert orig_topic_name is not None assert orig_topic_name is not None
target_stream: Stream = new_stream if new_stream is not None else stream_being_edited target_stream: Stream = new_stream if new_stream is not None else stream_being_edited
target_topic: str = topic_name if topic_name is not None else orig_topic_name target_topic_name: str = topic_name if topic_name is not None else orig_topic_name
assert target_stream.recipient_id is not None assert target_stream.recipient_id is not None
target_topic_has_messages = messages_for_topic( target_topic_has_messages = messages_for_topic(
realm.id, target_stream.recipient_id, target_topic realm.id, target_stream.recipient_id, target_topic_name
).exists() ).exists()
if propagate_mode in ["change_later", "change_all"]: if propagate_mode in ["change_later", "change_all"]:
@ -837,7 +837,7 @@ def do_update_message(
if moved_all_visible_messages: if moved_all_visible_messages:
assert stream_being_edited is not None assert stream_being_edited is not None
assert target_stream is not None assert target_stream is not None
assert target_topic is not None assert target_topic_name is not None
stream_inaccessible_to_user_profiles: List[UserProfile] = [] stream_inaccessible_to_user_profiles: List[UserProfile] = []
orig_topic_user_profile_to_visibility_policy: Dict[UserProfile, int] = {} orig_topic_user_profile_to_visibility_policy: Dict[UserProfile, int] = {}
@ -853,7 +853,7 @@ def do_update_message(
] = user_topic.visibility_policy ] = user_topic.visibility_policy
for user_topic in get_users_with_user_topic_visibility_policy( for user_topic in get_users_with_user_topic_visibility_policy(
target_stream.id, target_topic target_stream.id, target_topic_name
): ):
target_topic_user_profile_to_visibility_policy[ target_topic_user_profile_to_visibility_policy[
user_topic.user_profile user_topic.user_profile
@ -950,7 +950,7 @@ def do_update_message(
bulk_do_set_user_topic_visibility_policy( bulk_do_set_user_topic_visibility_policy(
user_profiles, user_profiles,
target_stream, target_stream,
target_topic, target_topic_name,
visibility_policy=new_visibility_policy, visibility_policy=new_visibility_policy,
) )
else: else:
@ -965,7 +965,7 @@ def do_update_message(
bulk_do_set_user_topic_visibility_policy( bulk_do_set_user_topic_visibility_policy(
user_profiles, user_profiles,
target_stream, target_stream,
target_topic, target_topic_name,
visibility_policy=new_visibility_policy, visibility_policy=new_visibility_policy,
) )
@ -985,8 +985,8 @@ def do_update_message(
resolved_topic_message_id = maybe_send_resolve_topic_notifications( resolved_topic_message_id = maybe_send_resolve_topic_notifications(
user_profile=user_profile, user_profile=user_profile,
stream=stream_to_send_resolve_topic_notification, stream=stream_to_send_resolve_topic_notification,
old_topic=orig_topic_name, old_topic_name=orig_topic_name,
new_topic=topic_name, new_topic_name=topic_name,
changed_messages=changed_messages, changed_messages=changed_messages,
) )
@ -1035,7 +1035,7 @@ def do_update_message(
stream_for_new_topic = new_stream if new_stream is not None else stream_being_edited stream_for_new_topic = new_stream if new_stream is not None else stream_being_edited
assert stream_for_new_topic.recipient_id is not None assert stream_for_new_topic.recipient_id is not None
new_topic = topic_name if topic_name is not None else orig_topic_name new_topic_name = topic_name if topic_name is not None else orig_topic_name
changed_message_ids = [changed_message.id for changed_message in changed_messages] changed_message_ids = [changed_message.id for changed_message in changed_messages]
@ -1054,7 +1054,7 @@ def do_update_message(
# it reuses existing logic, which is good for keeping it # it reuses existing logic, which is good for keeping it
# correct as we maintain the codebase. # correct as we maintain the codebase.
preexisting_topic_messages = messages_for_topic( preexisting_topic_messages = messages_for_topic(
realm.id, stream_for_new_topic.recipient_id, new_topic realm.id, stream_for_new_topic.recipient_id, new_topic_name
).exclude(id__in=[*changed_message_ids, resolved_topic_message_id]) ).exclude(id__in=[*changed_message_ids, resolved_topic_message_id])
visible_preexisting_messages = bulk_access_messages( visible_preexisting_messages = bulk_access_messages(

View File

@ -969,7 +969,7 @@ def do_send_messages(
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=sender, user_profile=sender,
stream=send_request.stream, stream=send_request.stream,
topic=send_request.message.topic_name(), topic_name=send_request.message.topic_name(),
visibility_policy=new_visibility_policy, visibility_policy=new_visibility_policy,
) )
send_request.automatic_new_visibility_policy = new_visibility_policy send_request.automatic_new_visibility_policy = new_visibility_policy
@ -1011,7 +1011,7 @@ def do_send_messages(
bulk_do_set_user_topic_visibility_policy( bulk_do_set_user_topic_visibility_policy(
user_profiles=to_follow_users, user_profiles=to_follow_users,
stream=send_request.stream, stream=send_request.stream,
topic=send_request.message.topic_name(), topic_name=send_request.message.topic_name(),
visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED, visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
) )
@ -1327,13 +1327,13 @@ def check_send_stream_message(
sender: UserProfile, sender: UserProfile,
client: Client, client: Client,
stream_name: str, stream_name: str,
topic: str, topic_name: str,
body: str, body: str,
*, *,
realm: Optional[Realm] = None, realm: Optional[Realm] = None,
read_by_sender: bool = False, read_by_sender: bool = False,
) -> int: ) -> int:
addressee = Addressee.for_stream_name(stream_name, topic) addressee = Addressee.for_stream_name(stream_name, topic_name)
message = check_message(sender, client, addressee, body, realm) message = check_message(sender, client, addressee, body, realm)
sent_message_result = do_send_messages( sent_message_result = do_send_messages(
[message], mark_as_read=[sender.id] if read_by_sender else [] [message], mark_as_read=[sender.id] if read_by_sender else []
@ -1345,11 +1345,11 @@ def check_send_stream_message_by_id(
sender: UserProfile, sender: UserProfile,
client: Client, client: Client,
stream_id: int, stream_id: int,
topic: str, topic_name: str,
body: str, body: str,
realm: Optional[Realm] = None, realm: Optional[Realm] = None,
) -> int: ) -> int:
addressee = Addressee.for_stream_id(stream_id, topic) addressee = Addressee.for_stream_id(stream_id, topic_name)
message = check_message(sender, client, addressee, body, realm) message = check_message(sender, client, addressee, body, realm)
sent_message_result = do_send_messages([message])[0] sent_message_result = do_send_messages([message])[0]
return sent_message_result.message_id return sent_message_result.message_id
@ -1638,7 +1638,7 @@ def check_message(
recipients_for_user_creation_events = None recipients_for_user_creation_events = None
if addressee.is_stream(): if addressee.is_stream():
topic_name = addressee.topic() topic_name = addressee.topic_name()
topic_name = truncate_topic(topic_name) topic_name = truncate_topic(topic_name)
stream_name = addressee.stream_name() stream_name = addressee.stream_name()
@ -1840,7 +1840,7 @@ def _internal_prep_message(
def internal_prep_stream_message( def internal_prep_stream_message(
sender: UserProfile, sender: UserProfile,
stream: Stream, stream: Stream,
topic: str, topic_name: str,
content: str, content: str,
*, *,
email_gateway: bool = False, email_gateway: bool = False,
@ -1850,7 +1850,7 @@ def internal_prep_stream_message(
See _internal_prep_message for details of how this works. See _internal_prep_message for details of how this works.
""" """
realm = stream.realm realm = stream.realm
addressee = Addressee.for_stream(stream, topic) addressee = Addressee.for_stream(stream, topic_name)
return _internal_prep_message( return _internal_prep_message(
realm=realm, realm=realm,
@ -1866,13 +1866,13 @@ def internal_prep_stream_message_by_name(
realm: Realm, realm: Realm,
sender: UserProfile, sender: UserProfile,
stream_name: str, stream_name: str,
topic: str, topic_name: str,
content: str, content: str,
) -> Optional[SendMessageRequest]: ) -> Optional[SendMessageRequest]:
""" """
See _internal_prep_message for details of how this works. See _internal_prep_message for details of how this works.
""" """
addressee = Addressee.for_stream_name(stream_name, topic) addressee = Addressee.for_stream_name(stream_name, topic_name)
return _internal_prep_message( return _internal_prep_message(
realm=realm, realm=realm,
@ -1931,7 +1931,7 @@ def internal_send_private_message(
def internal_send_stream_message( def internal_send_stream_message(
sender: UserProfile, sender: UserProfile,
stream: Stream, stream: Stream,
topic: str, topic_name: str,
content: str, content: str,
*, *,
email_gateway: bool = False, email_gateway: bool = False,
@ -1940,7 +1940,7 @@ def internal_send_stream_message(
message = internal_prep_stream_message( message = internal_prep_stream_message(
sender, sender,
stream, stream,
topic, topic_name,
content, content,
email_gateway=email_gateway, email_gateway=email_gateway,
limit_unread_user_ids=limit_unread_user_ids, limit_unread_user_ids=limit_unread_user_ids,
@ -1957,14 +1957,14 @@ def internal_send_stream_message_by_name(
realm: Realm, realm: Realm,
sender: UserProfile, sender: UserProfile,
stream_name: str, stream_name: str,
topic: str, topic_name: str,
content: str, content: str,
) -> Optional[int]: ) -> Optional[int]:
message = internal_prep_stream_message_by_name( message = internal_prep_stream_message_by_name(
realm, realm,
sender, sender,
stream_name, stream_name,
topic, topic_name,
content, content,
) )

View File

@ -112,7 +112,7 @@ def do_add_reaction(
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=user_profile, user_profile=user_profile,
stream=stream, stream=stream,
topic=message.topic_name(), topic_name=message.topic_name(),
visibility_policy=new_visibility_policy, visibility_policy=new_visibility_policy,
) )

View File

@ -174,11 +174,11 @@ def edit_scheduled_message(
# Update topic name if changed. # Update topic name if changed.
if topic_name is not None: if topic_name is not None:
updated_topic = topic_name updated_topic_name = topic_name
else: else:
# This will be ignored in Addressee.legacy_build if type # This will be ignored in Addressee.legacy_build if type
# is being changed from stream to direct. # is being changed from stream to direct.
updated_topic = scheduled_message_object.topic_name() updated_topic_name = scheduled_message_object.topic_name()
# Update message content if changed. # Update message content if changed.
if message_content is not None: if message_content is not None:
@ -188,7 +188,7 @@ def edit_scheduled_message(
# Check message again. # Check message again.
addressee = Addressee.legacy_build( addressee = Addressee.legacy_build(
sender, updated_recipient_type_name, updated_recipient, updated_topic sender, updated_recipient_type_name, updated_recipient, updated_topic_name
) )
send_request = check_message( send_request = check_message(
sender, sender,

View File

@ -311,7 +311,7 @@ def do_unarchive_stream(
internal_send_stream_message( internal_send_stream_message(
sender, sender,
stream, stream,
str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
_("Stream {stream_name} un-archived.").format(stream_name=new_name), _("Stream {stream_name} un-archived.").format(stream_name=new_name),
) )
@ -1184,7 +1184,7 @@ def send_change_stream_permission_notification(
new_policy=new_policy_name, new_policy=new_policy_name,
) )
internal_send_stream_message( internal_send_stream_message(
sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), notification_string sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), notification_string
) )
@ -1361,7 +1361,7 @@ def send_change_stream_post_policy_notification(
new_policy=Stream.POST_POLICIES[new_post_policy], new_policy=Stream.POST_POLICIES[new_post_policy],
) )
internal_send_stream_message( internal_send_stream_message(
sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), notification_string sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), notification_string
) )
@ -1465,7 +1465,7 @@ def do_rename_stream(stream: Stream, new_name: str, user_profile: UserProfile) -
internal_send_stream_message( internal_send_stream_message(
sender, sender,
stream, stream,
str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
_("{user_name} renamed stream {old_stream_name} to {new_stream_name}.").format( _("{user_name} renamed stream {old_stream_name} to {new_stream_name}.").format(
user_name=silent_mention_syntax_for_user(user_profile), user_name=silent_mention_syntax_for_user(user_profile),
old_stream_name=f"**{old_name}**", old_stream_name=f"**{old_name}**",
@ -1499,7 +1499,7 @@ def send_change_stream_description_notification(
) )
internal_send_stream_message( internal_send_stream_message(
sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), notification_string sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), notification_string
) )
@ -1583,7 +1583,7 @@ def send_change_stream_message_retention_days_notification(
summary_line=summary_line, summary_line=summary_line,
) )
internal_send_stream_message( internal_send_stream_message(
sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), notification_string sender, stream, str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME), notification_string
) )

View File

@ -78,7 +78,7 @@ def do_add_submessage(
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=sender, user_profile=sender,
stream=stream, stream=stream,
topic=submessage.message.topic_name(), topic_name=submessage.message.topic_name(),
visibility_policy=new_visibility_policy, visibility_policy=new_visibility_policy,
) )

View File

@ -66,7 +66,7 @@ def check_send_typing_notification(sender: UserProfile, user_ids: List[int], ope
def do_send_stream_typing_notification( def do_send_stream_typing_notification(
sender: UserProfile, operator: str, stream: Stream, topic: str sender: UserProfile, operator: str, stream: Stream, topic_name: str
) -> None: ) -> None:
sender_dict = {"user_id": sender.id, "email": sender.email} sender_dict = {"user_id": sender.id, "email": sender.email}
@ -76,7 +76,7 @@ def do_send_stream_typing_notification(
op=operator, op=operator,
sender=sender_dict, sender=sender_dict,
stream_id=stream.id, stream_id=stream.id,
topic=topic, topic=topic_name,
) )
# We don't notify long_term_idle subscribers. # We don't notify long_term_idle subscribers.

View File

@ -15,7 +15,7 @@ from zerver.tornado.django_api import send_event
def bulk_do_set_user_topic_visibility_policy( def bulk_do_set_user_topic_visibility_policy(
user_profiles: List[UserProfile], user_profiles: List[UserProfile],
stream: Stream, stream: Stream,
topic: str, topic_name: str,
*, *,
visibility_policy: int, visibility_policy: int,
last_updated: Optional[datetime] = None, last_updated: Optional[datetime] = None,
@ -27,7 +27,7 @@ def bulk_do_set_user_topic_visibility_policy(
user_profiles_with_changed_user_topic_rows = bulk_set_user_topic_visibility_policy_in_database( user_profiles_with_changed_user_topic_rows = bulk_set_user_topic_visibility_policy_in_database(
user_profiles, user_profiles,
stream.id, stream.id,
topic, topic_name,
visibility_policy=visibility_policy, visibility_policy=visibility_policy,
recipient_id=stream.recipient_id, recipient_id=stream.recipient_id,
last_updated=last_updated, last_updated=last_updated,
@ -52,7 +52,7 @@ def bulk_do_set_user_topic_visibility_policy(
user_topic_event: Dict[str, Any] = { user_topic_event: Dict[str, Any] = {
"type": "user_topic", "type": "user_topic",
"stream_id": stream.id, "stream_id": stream.id,
"topic_name": topic, "topic_name": topic_name,
"last_updated": datetime_to_timestamp(last_updated), "last_updated": datetime_to_timestamp(last_updated),
"visibility_policy": visibility_policy, "visibility_policy": visibility_policy,
} }
@ -63,7 +63,7 @@ def bulk_do_set_user_topic_visibility_policy(
def do_set_user_topic_visibility_policy( def do_set_user_topic_visibility_policy(
user_profile: UserProfile, user_profile: UserProfile,
stream: Stream, stream: Stream,
topic: str, topic_name: str,
*, *,
visibility_policy: int, visibility_policy: int,
last_updated: Optional[datetime] = None, last_updated: Optional[datetime] = None,
@ -75,7 +75,7 @@ def do_set_user_topic_visibility_policy(
bulk_do_set_user_topic_visibility_policy( bulk_do_set_user_topic_visibility_policy(
[user_profile], [user_profile],
stream, stream,
topic, topic_name,
visibility_policy=visibility_policy, visibility_policy=visibility_policy,
last_updated=last_updated, last_updated=last_updated,
skip_muted_topics_event=skip_muted_topics_event, skip_muted_topics_event=skip_muted_topics_event,

View File

@ -52,17 +52,17 @@ class Addressee:
stream: Optional[Stream] = None, stream: Optional[Stream] = None,
stream_name: Optional[str] = None, stream_name: Optional[str] = None,
stream_id: Optional[int] = None, stream_id: Optional[int] = None,
topic: Optional[str] = None, topic_name: Optional[str] = None,
) -> None: ) -> None:
assert msg_type in ["stream", "private"] assert msg_type in ["stream", "private"]
if msg_type == "stream" and topic is None: if msg_type == "stream" and topic_name is None:
raise JsonableError(_("Missing topic")) raise JsonableError(_("Missing topic"))
self._msg_type = msg_type self._msg_type = msg_type
self._user_profiles = user_profiles self._user_profiles = user_profiles
self._stream = stream self._stream = stream
self._stream_name = stream_name self._stream_name = stream_name
self._stream_id = stream_id self._stream_id = stream_id
self._topic = topic self._topic_name = topic_name
def is_stream(self) -> bool: def is_stream(self) -> bool:
return self._msg_type == "stream" return self._msg_type == "stream"
@ -87,10 +87,10 @@ class Addressee:
assert self.is_stream() assert self.is_stream()
return self._stream_id return self._stream_id
def topic(self) -> str: def topic_name(self) -> str:
assert self.is_stream() assert self.is_stream()
assert self._topic is not None assert self._topic_name is not None
return self._topic return self._topic_name
@staticmethod @staticmethod
def legacy_build( def legacy_build(
@ -143,33 +143,33 @@ class Addressee:
raise JsonableError(_("Invalid message type")) raise JsonableError(_("Invalid message type"))
@staticmethod @staticmethod
def for_stream(stream: Stream, topic: str) -> "Addressee": def for_stream(stream: Stream, topic_name: str) -> "Addressee":
topic = topic.strip() topic_name = topic_name.strip()
check_stream_topic(topic) check_stream_topic(topic_name)
return Addressee( return Addressee(
msg_type="stream", msg_type="stream",
stream=stream, stream=stream,
topic=topic, topic_name=topic_name,
) )
@staticmethod @staticmethod
def for_stream_name(stream_name: str, topic: str) -> "Addressee": def for_stream_name(stream_name: str, topic_name: str) -> "Addressee":
topic = topic.strip() topic_name = topic_name.strip()
check_stream_topic(topic) check_stream_topic(topic_name)
return Addressee( return Addressee(
msg_type="stream", msg_type="stream",
stream_name=stream_name, stream_name=stream_name,
topic=topic, topic_name=topic_name,
) )
@staticmethod @staticmethod
def for_stream_id(stream_id: int, topic: str) -> "Addressee": def for_stream_id(stream_id: int, topic_name: str) -> "Addressee":
topic = topic.strip() topic_name = topic_name.strip()
check_stream_topic(topic) check_stream_topic(topic_name)
return Addressee( return Addressee(
msg_type="stream", msg_type="stream",
stream_id=stream_id, stream_id=stream_id,
topic=topic, topic_name=topic_name,
) )
@staticmethod @staticmethod

View File

@ -1129,7 +1129,7 @@ Output:
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic=topic_name, topic_name=topic_name,
body=content, body=content,
realm=recipient_realm, realm=recipient_realm,
read_by_sender=read_by_sender, read_by_sender=read_by_sender,

View File

@ -334,7 +334,7 @@ class Realm(models.Model): # type: ignore[django-manager-missing] # django-stub
DEFAULT_NOTIFICATION_STREAM_NAME = "general" DEFAULT_NOTIFICATION_STREAM_NAME = "general"
INITIAL_PRIVATE_STREAM_NAME = "core team" INITIAL_PRIVATE_STREAM_NAME = "core team"
STREAM_EVENTS_NOTIFICATION_TOPIC = gettext_lazy("stream events") STREAM_EVENTS_NOTIFICATION_TOPIC_NAME = gettext_lazy("stream events")
notifications_stream = models.ForeignKey( notifications_stream = models.ForeignKey(
"Stream", "Stream",
related_name="+", related_name="+",

View File

@ -2113,7 +2113,7 @@ class EditMessageTest(EditMessageTestCase):
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=hamlet, user_profile=hamlet,
stream=get_stream(stream_name, cordelia.realm), stream=get_stream(stream_name, cordelia.realm),
topic="test", topic_name="test",
visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED, visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
) )
message_id = self.send_stream_message(hamlet, stream_name, "Hello everyone") message_id = self.send_stream_message(hamlet, stream_name, "Hello everyone")
@ -2171,7 +2171,7 @@ class EditMessageTest(EditMessageTestCase):
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=hamlet, user_profile=hamlet,
stream=get_stream(stream_name, cordelia.realm), stream=get_stream(stream_name, cordelia.realm),
topic="test", topic_name="test",
visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED, visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
) )
message_id = self.send_stream_message(hamlet, stream_name, "Hello everyone") message_id = self.send_stream_message(hamlet, stream_name, "Hello everyone")

View File

@ -415,7 +415,7 @@ class EditMessageSideEffectsTest(ZulipTestCase):
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=cordelia, user_profile=cordelia,
stream=get_stream("Scotland", cordelia.realm), stream=get_stream("Scotland", cordelia.realm),
topic="test", topic_name="test",
visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED, visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
) )
@ -465,7 +465,7 @@ class EditMessageSideEffectsTest(ZulipTestCase):
do_set_user_topic_visibility_policy( do_set_user_topic_visibility_policy(
user_profile=cordelia, user_profile=cordelia,
stream=get_stream("Scotland", cordelia.realm), stream=get_stream("Scotland", cordelia.realm),
topic="test", topic_name="test",
visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED, visibility_policy=UserTopic.VisibilityPolicy.FOLLOWED,
) )

View File

@ -1588,7 +1588,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic=topic_name, topic_name=topic_name,
body=content, body=content,
) )
@ -1608,7 +1608,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="new topic", topic_name="new topic",
body=content, body=content,
) )
@ -1628,7 +1628,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="topic 2", topic_name="topic 2",
body=content, body=content,
) )
# If the topic is already FOLLOWED, there will be an increase in the query # If the topic is already FOLLOWED, there will be an increase in the query
@ -1639,7 +1639,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="topic 2", topic_name="topic 2",
body=content, body=content,
) )
@ -1664,7 +1664,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="topic 2", topic_name="topic 2",
body="@**" + user.full_name + "**", body="@**" + user.full_name + "**",
) )
# If the topic is already FOLLOWED, there will be an increase in the query # If the topic is already FOLLOWED, there will be an increase in the query
@ -1677,7 +1677,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="topic 2", topic_name="topic 2",
body="@**" + user.full_name + "**", body="@**" + user.full_name + "**",
) )
@ -1687,7 +1687,7 @@ class StreamMessagesTest(ZulipTestCase):
sender=sender, sender=sender,
client=sending_client, client=sending_client,
stream_name=stream_name, stream_name=stream_name,
topic="topic 2", topic_name="topic 2",
body="@**all**", body="@**all**",
) )
@ -2537,7 +2537,7 @@ class InternalPrepTest(ZulipTestCase):
with self.assertLogs(level="ERROR") as m: with self.assertLogs(level="ERROR") as m:
internal_send_stream_message( internal_send_stream_message(
sender=cordelia, sender=cordelia,
topic="whatever", topic_name="whatever",
content=bad_content, content=bad_content,
stream=stream, stream=stream,
) )
@ -2554,7 +2554,7 @@ class InternalPrepTest(ZulipTestCase):
realm=realm, realm=realm,
sender=cordelia, sender=cordelia,
stream_name=stream.name, stream_name=stream.name,
topic="whatever", topic_name="whatever",
content=bad_content, content=bad_content,
) )
@ -2598,11 +2598,15 @@ class InternalPrepTest(ZulipTestCase):
realm = get_realm("zulip") realm = get_realm("zulip")
sender = self.example_user("cordelia") sender = self.example_user("cordelia")
stream_name = "test_stream" stream_name = "test_stream"
topic = "whatever" topic_name = "whatever"
content = "hello" content = "hello"
internal_prep_stream_message_by_name( internal_prep_stream_message_by_name(
realm=realm, sender=sender, stream_name=stream_name, topic=topic, content=content realm=realm,
sender=sender,
stream_name=stream_name,
topic_name=topic_name,
content=content,
) )
# This would throw an error if the stream # This would throw an error if the stream

View File

@ -773,7 +773,7 @@ def send_messages_for_new_subscribers(
content = _("{user_name} created the following streams: {stream_str}.") content = _("{user_name} created the following streams: {stream_str}.")
else: else:
content = _("{user_name} created a new stream {stream_str}.") content = _("{user_name} created a new stream {stream_str}.")
topic = _("new streams") topic_name = _("new streams")
content = content.format( content = content.format(
user_name=silent_mention_syntax_for_user(user_profile), user_name=silent_mention_syntax_for_user(user_profile),
@ -786,7 +786,7 @@ def send_messages_for_new_subscribers(
internal_prep_stream_message( internal_prep_stream_message(
sender=sender, sender=sender,
stream=notifications_stream, stream=notifications_stream,
topic=topic, topic_name=topic_name,
content=content, content=content,
), ),
) )
@ -803,7 +803,7 @@ def send_messages_for_new_subscribers(
internal_prep_stream_message( internal_prep_stream_message(
sender=sender, sender=sender,
stream=stream, stream=stream,
topic=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC), topic_name=str(Realm.STREAM_EVENTS_NOTIFICATION_TOPIC_NAME),
content=_( content=_(
"**{policy}** stream created by {user_name}. **Description:**" "**{policy}** stream created by {user_name}. **Description:**"
).format( ).format(