zephyr: Remove Zephyr mirroring support.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2025-09-12 13:32:21 -07:00
committed by Tim Abbott
parent fb13de4e10
commit 40a022dcc3
94 changed files with 121 additions and 2067 deletions

View File

@@ -295,12 +295,9 @@ def process_new_human_user(
)
realm = user_profile.realm
mit_beta_user = realm.is_zephyr_mirror_realm
# mit_beta_users don't have a referred_by field
if (
not mit_beta_user
and prereg_user is not None
prereg_user is not None
and prereg_user.referred_by is not None
and prereg_user.referred_by.is_active
and prereg_user.notify_referrer_on_join

View File

@@ -37,7 +37,6 @@ from zerver.lib.exceptions import (
StreamWithIDDoesNotExistError,
TopicsNotAllowedError,
TopicWildcardMentionNotAllowedError,
ZephyrMessageAlreadySentError,
)
from zerver.lib.markdown import MessageRenderingResult, render_message_markdown
from zerver.lib.markdown import version as markdown_version
@@ -844,7 +843,7 @@ def get_active_presence_idle_user_ids(
UserPresence table.
"""
if realm.presence_disabled:
if realm.presence_disabled: # nocoverage
return []
user_ids = set()
@@ -1269,35 +1268,6 @@ def do_send_messages(
return sent_message_results
def already_sent_mirrored_message_id(message: Message) -> int | None:
if message.recipient.type == Recipient.DIRECT_MESSAGE_GROUP:
# For group direct messages, we use a 10-second window because
# the timestamps aren't guaranteed to actually match between
# two copies of the same message.
time_window = timedelta(seconds=10)
else:
time_window = timedelta(seconds=0)
messages = Message.objects.filter(
# Uses index: zerver_message_realm_recipient_subject for
# channel messages or zerver_message_realm_sender_recipient for
# DMs
realm_id=message.realm_id,
sender=message.sender,
recipient=message.recipient,
subject=message.topic_name(),
is_channel_message=message.is_channel_message,
content=message.content,
sending_client=message.sending_client,
date_sent__gte=message.date_sent - time_window,
date_sent__lte=message.date_sent + time_window,
)
if messages.exists():
return messages[0].id
return None
def extract_stream_indicator(s: str) -> str | int:
# Users can pass stream name as either an id or a name,
# and if they choose to pass a name, they may JSON encode
@@ -1440,23 +1410,20 @@ def check_send_message(
read_by_sender: bool = False,
) -> SentMessageResult:
addressee = Addressee.legacy_build(sender, recipient_type_name, message_to, topic_name)
try:
message = check_message(
sender,
client,
addressee,
message_content,
realm,
forged,
forged_timestamp,
forwarder_user_profile,
local_id,
sender_queue_id,
widget_content,
skip_stream_access_check=skip_stream_access_check,
)
except ZephyrMessageAlreadySentError as e:
return SentMessageResult(message_id=e.message_id)
message = check_message(
sender,
client,
addressee,
message_content,
realm,
forged,
forged_timestamp,
forwarder_user_profile,
local_id,
sender_queue_id,
widget_content,
skip_stream_access_check=skip_stream_access_check,
)
return do_send_messages([message], mark_as_read=[sender.id] if read_by_sender else [])[0]
@@ -1467,7 +1434,7 @@ def send_rate_limited_pm_notification_to_bot_owner(
Sends a direct message error notification to a bot's owner if one
hasn't already been sent in the last 5 minutes.
"""
if sender.realm.is_zephyr_mirror_realm or sender.realm.deactivated:
if sender.realm.deactivated:
return
if not sender.is_bot or sender.bot_owner is None:
@@ -1799,7 +1766,6 @@ def check_message(
elif addressee.is_private():
user_profiles = addressee.user_profiles()
mirror_message = client.name in [
"zephyr_mirror",
"irc_mirror",
"jabber_mirror",
"JabberMirror",
@@ -1851,11 +1817,6 @@ def check_message(
# We render messages later in the process.
assert message.rendered_content is None
if client.name == "zephyr_mirror":
id = already_sent_mirrored_message_id(message)
if id is not None:
raise ZephyrMessageAlreadySentError(id)
widget_content_dict = None
if widget_content is not None:
try:

View File

@@ -422,10 +422,7 @@ def send_subscription_add_events(
for sub_info in sub_info_list:
stream = sub_info.stream
if stream.id not in stream_subscribers_dict:
if stream.is_in_zephyr_realm and not stream.invite_only:
subscribers = []
else:
subscribers = list(subscriber_dict[stream.id])
subscribers = list(subscriber_dict[stream.id])
stream_subscribers_dict[stream.id] = subscribers
streams = [sub_info.stream for sub_info in sub_info_list]
@@ -602,9 +599,7 @@ def send_peer_subscriber_events(
stream_id for stream_id in altered_user_dict if stream_dict[stream_id].invite_only
]
public_stream_ids = [
stream_id
for stream_id in altered_user_dict
if not stream_dict[stream_id].invite_only and not stream_dict[stream_id].is_in_zephyr_realm
stream_id for stream_id in altered_user_dict if not stream_dict[stream_id].invite_only
]
web_public_stream_ids = [
stream_id for stream_id in public_stream_ids if stream_dict[stream_id].is_web_public

View File

@@ -82,9 +82,6 @@ from zerver.tornado.django_api import send_event_on_commit
def do_delete_user(user_profile: UserProfile, *, acting_user: UserProfile | None) -> None:
if user_profile.realm.is_zephyr_mirror_realm:
raise AssertionError("Deleting zephyr mirror users is not supported")
do_deactivate_user(user_profile, acting_user=acting_user)
to_resubscribe_recipient_ids = set(
@@ -187,9 +184,6 @@ def do_delete_user_preserving_messages(user_profile: UserProfile) -> None:
space of user IDs that contain actual users.
"""
if user_profile.realm.is_zephyr_mirror_realm:
raise AssertionError("Deleting zephyr mirror users is not supported")
do_deactivate_user(user_profile, acting_user=None)
user_id = user_profile.id
@@ -520,16 +514,6 @@ def do_deactivate_user(
do_deactivate_user(profile, _cascade=False, acting_user=acting_user)
with transaction.atomic(savepoint=False):
if user_profile.realm.is_zephyr_mirror_realm: # nocoverage
# For zephyr mirror users, we need to make them a mirror dummy
# again; otherwise, other users won't get the correct behavior
# when trying to send messages to this person inside Zulip.
#
# Ideally, we need to also ensure their zephyr mirroring bot
# isn't running, but that's a separate issue.
user_profile.is_mirror_dummy = True
user_profile.save(update_fields=["is_mirror_dummy"])
change_user_is_active(user_profile, False)
clear_scheduled_emails([user_profile.id])