2017-08-02 05:20:50 +02:00
|
|
|
|
from django.conf import settings
|
Revert "create_user: Use transaction.atomic decorator for do_create_user."
This reverts commit 851d68e0fc364d649175533c286c179cf38f89d6.
That commit widened how long the transaction is open, which made it
much more likely that after the user was created in the transaction,
and the memcached caches were flushed, some other request will fill
the `get_realm_user_dicts` cache with data which did not include the
new user (because it had not been committed yet).
If a user creation request lost this race, the user would, upon first
request to `/`, get a blank page and a Javascript error:
Unknown user_id in get_by_user_id: 12345
...where 12345 was their own user-id. This error would persist until
the cache expired (in 7 days) or something else expunged it.
Reverting this does not prevent the race, as the post_save hook's call
to flush_user_profile is still in a transaction (and has been since
168f241ff0a5), and thus leaves the potential race window open.
However, it much shortens the potential window of opportunity, and is
a reasonable short-term stopgap.
2023-02-18 02:44:51 +01:00
|
|
|
|
from django.db import transaction
|
2020-03-28 10:02:45 +01:00
|
|
|
|
from django.db.models import Count
|
2021-04-16 00:57:30 +02:00
|
|
|
|
from django.utils.translation import gettext as _
|
2022-01-24 11:22:11 +01:00
|
|
|
|
from django.utils.translation import override as override_language
|
2017-08-02 05:20:50 +02:00
|
|
|
|
|
2022-04-14 23:58:15 +02:00
|
|
|
|
from zerver.actions.create_realm import setup_realm_internal_bots
|
2022-04-14 23:50:10 +02:00
|
|
|
|
from zerver.actions.message_send import (
|
2020-06-11 00:54:34 +02:00
|
|
|
|
do_send_messages,
|
|
|
|
|
internal_prep_stream_message_by_name,
|
|
|
|
|
internal_send_private_message,
|
|
|
|
|
)
|
2022-04-14 23:54:01 +02:00
|
|
|
|
from zerver.actions.reactions import do_add_reaction
|
2023-07-14 14:25:57 +02:00
|
|
|
|
from zerver.lib.emoji import get_emoji_data
|
2024-03-23 04:29:56 +01:00
|
|
|
|
from zerver.lib.message import SendMessageRequest, remove_single_newlines
|
2024-06-21 08:05:00 +02:00
|
|
|
|
from zerver.models import Message, OnboardingUserMessage, Realm, UserProfile
|
2023-12-15 01:16:00 +01:00
|
|
|
|
from zerver.models.users import get_system_bot
|
2017-08-02 05:20:50 +02:00
|
|
|
|
|
|
|
|
|
|
2020-03-28 10:02:45 +01:00
|
|
|
|
def missing_any_realm_internal_bots() -> bool:
|
2021-02-12 08:19:30 +01:00
|
|
|
|
bot_emails = [
|
2021-02-12 08:20:45 +01:00
|
|
|
|
bot["email_template"] % (settings.INTERNAL_BOT_DOMAIN,)
|
2021-02-12 08:19:30 +01:00
|
|
|
|
for bot in settings.REALM_INTERNAL_BOTS
|
|
|
|
|
]
|
2020-03-28 10:02:45 +01:00
|
|
|
|
realm_count = Realm.objects.count()
|
2024-07-11 17:04:53 +02:00
|
|
|
|
return UserProfile.objects.filter(email__in=bot_emails).values("email").alias(
|
2023-03-23 21:16:47 +01:00
|
|
|
|
count=Count("id")
|
|
|
|
|
).filter(count=realm_count).count() != len(bot_emails)
|
2020-03-28 10:02:45 +01:00
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
2018-05-23 05:40:28 +02:00
|
|
|
|
def create_if_missing_realm_internal_bots() -> None:
|
|
|
|
|
"""This checks if there is any realm internal bot missing.
|
|
|
|
|
|
|
|
|
|
If that is the case, it creates the missing realm internal bots.
|
|
|
|
|
"""
|
|
|
|
|
if missing_any_realm_internal_bots():
|
|
|
|
|
for realm in Realm.objects.all():
|
|
|
|
|
setup_realm_internal_bots(realm)
|
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
2024-06-27 15:06:09 +02:00
|
|
|
|
def send_initial_direct_message(user: UserProfile) -> int:
|
2023-05-01 18:01:47 +02:00
|
|
|
|
# We adjust the initial Welcome Bot direct message for education organizations.
|
2023-07-22 01:15:10 +02:00
|
|
|
|
education_organization = user.realm.org_type in (
|
|
|
|
|
Realm.ORG_TYPES["education_nonprofit"]["id"],
|
|
|
|
|
Realm.ORG_TYPES["education"]["id"],
|
|
|
|
|
)
|
2021-09-09 06:50:40 +02:00
|
|
|
|
|
2022-01-24 11:22:11 +01:00
|
|
|
|
# We need to override the language in this code path, because it's
|
|
|
|
|
# called from account registration, which is a pre-account API
|
|
|
|
|
# request and thus may not have the user's language context yet.
|
|
|
|
|
with override_language(user.default_language):
|
2023-05-01 18:01:47 +02:00
|
|
|
|
if education_organization:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
getting_started_string = _("""
|
2024-09-26 18:23:32 +02:00
|
|
|
|
To learn more, check out our [using Zulip for a class guide]({getting_started_url})!
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""").format(getting_started_url="/help/using-zulip-for-a-class")
|
2023-05-01 18:01:47 +02:00
|
|
|
|
else:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
getting_started_string = _("""
|
2024-09-26 18:23:32 +02:00
|
|
|
|
To learn more, check out our [getting started guide]({getting_started_url})!
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""").format(getting_started_url="/help/getting-started-with-zulip")
|
2023-05-01 18:01:47 +02:00
|
|
|
|
|
|
|
|
|
organization_setup_string = ""
|
|
|
|
|
# Add extra content on setting up a new organization for administrators.
|
2022-01-24 11:22:11 +01:00
|
|
|
|
if user.is_realm_admin:
|
2023-05-01 18:01:47 +02:00
|
|
|
|
if education_organization:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
organization_setup_string = _("""
|
2024-09-26 18:23:32 +02:00
|
|
|
|
We also have a guide for [setting up Zulip for a class]({organization_setup_url}).
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""").format(organization_setup_url="/help/setting-up-zulip-for-a-class")
|
2023-05-01 18:01:47 +02:00
|
|
|
|
else:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
organization_setup_string = _("""
|
2024-09-26 18:23:32 +02:00
|
|
|
|
We also have a guide for [moving your organization to Zulip]({organization_setup_url}).
|
|
|
|
|
""").format(organization_setup_url="/help/moving-to-zulip")
|
2023-05-01 18:01:47 +02:00
|
|
|
|
|
|
|
|
|
demo_organization_warning_string = ""
|
|
|
|
|
# Add extra content about automatic deletion for demo organization owners.
|
|
|
|
|
if user.is_realm_owner and user.realm.demo_organization_scheduled_deletion_date is not None:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
demo_organization_warning_string = _("""
|
|
|
|
|
Note that this is a [demo organization]({demo_organization_help_url}) and
|
|
|
|
|
will be **automatically deleted** in 30 days.
|
|
|
|
|
""").format(demo_organization_help_url="/help/demo-organizations")
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
2024-06-19 13:47:38 +02:00
|
|
|
|
inform_about_tracked_onboarding_messages_text = ""
|
|
|
|
|
if OnboardingUserMessage.objects.filter(realm_id=user.realm_id).exists():
|
|
|
|
|
inform_about_tracked_onboarding_messages_text = _("""
|
|
|
|
|
I've kicked off some conversations to help you get started. You can find
|
|
|
|
|
them in your [Inbox](/#inbox).
|
|
|
|
|
""")
|
|
|
|
|
|
2024-06-19 12:57:03 +02:00
|
|
|
|
content = _("""
|
2024-06-19 13:47:38 +02:00
|
|
|
|
Hello, and welcome to Zulip!👋 {inform_about_tracked_onboarding_messages_text}
|
2024-06-19 12:57:03 +02:00
|
|
|
|
|
|
|
|
|
{getting_started_text} {organization_setup_text}
|
|
|
|
|
|
|
|
|
|
{demo_organization_text}
|
|
|
|
|
|
|
|
|
|
""").format(
|
2024-06-19 13:47:38 +02:00
|
|
|
|
inform_about_tracked_onboarding_messages_text=inform_about_tracked_onboarding_messages_text,
|
2024-06-19 12:57:03 +02:00
|
|
|
|
getting_started_text=getting_started_string,
|
|
|
|
|
organization_setup_text=organization_setup_string,
|
|
|
|
|
demo_organization_text=demo_organization_warning_string,
|
|
|
|
|
)
|
2020-04-10 16:49:18 +02:00
|
|
|
|
|
2024-06-27 15:06:09 +02:00
|
|
|
|
message_id = internal_send_private_message(
|
2022-10-22 13:25:06 +02:00
|
|
|
|
get_system_bot(settings.WELCOME_BOT, user.realm_id),
|
|
|
|
|
user,
|
2024-06-19 12:57:03 +02:00
|
|
|
|
remove_single_newlines(content),
|
2022-10-22 13:25:06 +02:00
|
|
|
|
# Note: Welcome bot doesn't trigger email/push notifications,
|
|
|
|
|
# as this is intended to be seen contextually in the application.
|
|
|
|
|
disable_external_notifications=True,
|
2021-07-26 17:04:16 +02:00
|
|
|
|
)
|
2024-06-27 15:06:09 +02:00
|
|
|
|
assert message_id is not None
|
|
|
|
|
return message_id
|
2017-08-02 05:20:50 +02:00
|
|
|
|
|
|
|
|
|
|
2021-12-06 19:55:22 +01:00
|
|
|
|
def bot_commands(no_help_command: bool = False) -> str:
|
2021-10-16 10:29:21 +02:00
|
|
|
|
commands = [
|
|
|
|
|
"apps",
|
2021-12-02 08:15:17 +01:00
|
|
|
|
"profile",
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"theme",
|
2024-04-17 15:37:13 +02:00
|
|
|
|
"channels",
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"topics",
|
|
|
|
|
"message formatting",
|
|
|
|
|
"keyboard shortcuts",
|
|
|
|
|
]
|
2021-12-06 19:55:22 +01:00
|
|
|
|
if not no_help_command:
|
2021-10-16 10:29:21 +02:00
|
|
|
|
commands.append("help")
|
2023-09-12 23:19:57 +02:00
|
|
|
|
return ", ".join("`" + command + "`" for command in commands) + "."
|
2021-10-16 10:29:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def select_welcome_bot_response(human_response_lower: str) -> str:
|
|
|
|
|
# Given the raw (pre-markdown-rendering) content for a private
|
|
|
|
|
# message from the user to Welcome Bot, select the appropriate reply.
|
|
|
|
|
if human_response_lower in ["app", "apps"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
|
|
|
|
You can [download](/apps/) the [mobile and desktop apps](/apps/).
|
|
|
|
|
Zulip also works great in a browser.
|
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower == "profile":
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
|
|
|
|
Go to [Profile settings](#settings/profile) to add a [profile picture](/help/change-your-profile-picture)
|
|
|
|
|
and edit your [profile information](/help/edit-your-profile).
|
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower == "theme":
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
2024-07-09 09:00:30 +02:00
|
|
|
|
You can switch between [light and dark theme](/help/dark-theme), [pick your
|
|
|
|
|
favorite emoji set](/help/emoji-and-emoticons#change-your-emoji-set), [change
|
|
|
|
|
your language](/help/change-your-language), and otherwise customize your Zulip
|
|
|
|
|
experience in your [Preferences](#settings/preferences).
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower in ["stream", "streams", "channel", "channels"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
2024-07-09 09:00:30 +02:00
|
|
|
|
Channels organize conversations based on who needs to see them. For example,
|
|
|
|
|
it's common to have a channel for each team in an organization.
|
2024-06-19 12:57:03 +02:00
|
|
|
|
|
|
|
|
|
[Browse and subscribe to channels]({settings_link}).
|
|
|
|
|
""").format(help_link="/help/introduction-to-channels", settings_link="#channels/all")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower in ["topic", "topics"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
2024-07-09 09:00:30 +02:00
|
|
|
|
[Topics](/help/introduction-to-topics) summarize what each conversation in Zulip
|
|
|
|
|
is about. You can read Zulip one topic at a time, seeing each message in
|
|
|
|
|
context, no matter how many other conversations are going on.
|
2024-06-19 12:57:03 +02:00
|
|
|
|
|
2024-07-09 09:00:30 +02:00
|
|
|
|
When you start a conversation, label it with a new topic. For a good topic name,
|
|
|
|
|
think about finishing the sentence: “Hey, can we chat about…?”
|
|
|
|
|
|
|
|
|
|
Check out [Recent conversations](#recent) for a list of topics that are being
|
|
|
|
|
discussed.
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower in ["keyboard", "shortcuts", "keyboard shortcuts"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
|
|
|
|
Zulip's [keyboard shortcuts](#keyboard-shortcuts) let you navigate the app
|
|
|
|
|
quickly and efficiently.
|
|
|
|
|
|
|
|
|
|
Press `?` any time to see a [cheat sheet](#keyboard-shortcuts).
|
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower in ["formatting", "message formatting"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
2024-07-09 09:00:30 +02:00
|
|
|
|
You can **format** *your* `message` using the handy formatting buttons, or by
|
|
|
|
|
typing your formatting with Markdown.
|
2024-06-19 12:57:03 +02:00
|
|
|
|
|
2024-07-09 09:00:30 +02:00
|
|
|
|
Check out the [cheat sheet](#message-formatting) to learn about spoilers, global
|
|
|
|
|
times, and more.
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""")
|
2021-10-16 10:29:21 +02:00
|
|
|
|
elif human_response_lower in ["help", "?"]:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
|
|
|
|
Here are a few messages I understand: {bot_commands}
|
|
|
|
|
|
|
|
|
|
Check out our [Getting started guide](/help/getting-started-with-zulip),
|
|
|
|
|
or browse the [Help center](/help/) to learn more!
|
|
|
|
|
""").format(bot_commands=bot_commands(no_help_command=True))
|
2021-10-16 10:29:21 +02:00
|
|
|
|
else:
|
2024-06-19 12:57:03 +02:00
|
|
|
|
return _("""
|
2024-06-25 01:56:24 +02:00
|
|
|
|
You can chat with me as much as you like! To
|
|
|
|
|
get help, try one of the following messages: {bot_commands}
|
2024-06-19 12:57:03 +02:00
|
|
|
|
""").format(bot_commands=bot_commands())
|
2021-10-16 10:29:21 +02:00
|
|
|
|
|
|
|
|
|
|
2020-11-24 12:31:28 +01:00
|
|
|
|
def send_welcome_bot_response(send_request: SendMessageRequest) -> None:
|
2023-06-19 16:42:11 +02:00
|
|
|
|
"""Given the send_request object for a direct message from the user
|
2021-10-16 10:29:21 +02:00
|
|
|
|
to welcome-bot, trigger the welcome-bot reply."""
|
2023-08-10 06:00:43 +02:00
|
|
|
|
welcome_bot = get_system_bot(settings.WELCOME_BOT, send_request.realm.id)
|
2021-10-16 10:29:21 +02:00
|
|
|
|
human_response_lower = send_request.message.content.lower()
|
2024-06-25 02:31:15 +02:00
|
|
|
|
human_user_recipient_id = send_request.message.sender.recipient_id
|
|
|
|
|
assert human_user_recipient_id is not None
|
2021-10-16 10:29:21 +02:00
|
|
|
|
content = select_welcome_bot_response(human_response_lower)
|
2024-06-25 02:31:15 +02:00
|
|
|
|
realm_id = send_request.realm.id
|
|
|
|
|
commands = bot_commands()
|
|
|
|
|
if (
|
|
|
|
|
commands in content
|
|
|
|
|
and Message.objects.filter(
|
|
|
|
|
realm_id=realm_id,
|
|
|
|
|
sender_id=welcome_bot.id,
|
|
|
|
|
recipient_id=human_user_recipient_id,
|
|
|
|
|
content__icontains=commands,
|
|
|
|
|
).exists()
|
|
|
|
|
# Uses index 'zerver_message_realm_sender_recipient'
|
|
|
|
|
):
|
|
|
|
|
# If the bot has already sent bot commands to this user and
|
|
|
|
|
# if the bot does not understand the current message sent by this user then
|
|
|
|
|
# do not send any message
|
|
|
|
|
return
|
2022-10-22 13:25:06 +02:00
|
|
|
|
|
|
|
|
|
internal_send_private_message(
|
|
|
|
|
welcome_bot,
|
|
|
|
|
send_request.message.sender,
|
2024-06-19 12:57:03 +02:00
|
|
|
|
remove_single_newlines(content),
|
2022-10-22 13:25:06 +02:00
|
|
|
|
# Note: Welcome bot doesn't trigger email/push notifications,
|
|
|
|
|
# as this is intended to be seen contextually in the application.
|
|
|
|
|
disable_external_notifications=True,
|
|
|
|
|
)
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
2020-09-03 20:28:29 +02:00
|
|
|
|
|
2024-10-28 10:16:42 +01:00
|
|
|
|
@transaction.atomic(savepoint=False)
|
2017-11-05 11:15:10 +01:00
|
|
|
|
def send_initial_realm_messages(realm: Realm) -> None:
|
2024-03-26 13:58:30 +01:00
|
|
|
|
# Sends the initial messages for a new organization.
|
|
|
|
|
#
|
|
|
|
|
# Technical note: Each stream created in the realm creation
|
|
|
|
|
# process should have at least one message declared in this
|
|
|
|
|
# function, to enforce the pseudo-invariant that every stream has
|
|
|
|
|
# at least one message.
|
2021-07-26 17:04:16 +02:00
|
|
|
|
welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)
|
2024-03-26 13:58:30 +01:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
# Content is declared here to apply translation properly.
|
|
|
|
|
#
|
|
|
|
|
# remove_single_newlines needs to be called on any multiline
|
|
|
|
|
# strings for them to render properly.
|
|
|
|
|
content1_of_moving_messages_topic_name = (
|
|
|
|
|
_("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
If anything is out of place, it’s easy to [move messages]({move_content_another_topic_help_url}),
|
|
|
|
|
[rename]({rename_topic_help_url}) and [split]({move_content_another_topic_help_url}) topics,
|
|
|
|
|
or even move a topic [to a different channel]({move_content_another_channel_help_url}).
|
|
|
|
|
""")
|
2024-05-13 09:30:12 +02:00
|
|
|
|
).format(
|
|
|
|
|
move_content_another_topic_help_url="/help/move-content-to-another-topic",
|
|
|
|
|
rename_topic_help_url="/help/rename-a-topic",
|
|
|
|
|
move_content_another_channel_help_url="/help/move-content-to-another-channel",
|
|
|
|
|
)
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content2_of_moving_messages_topic_name = _("""
|
2024-05-11 00:18:35 +02:00
|
|
|
|
:point_right: Try moving this message to another topic and back.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
""")
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content1_of_welcome_to_zulip_topic_name = _("""
|
2024-05-11 00:18:35 +02:00
|
|
|
|
Zulip is organized to help you communicate more efficiently. Conversations are
|
|
|
|
|
labeled with topics, which summarize what the conversation is about.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
|
2024-05-11 00:18:35 +02:00
|
|
|
|
For example, this message is in the “{topic_name}” topic in the
|
|
|
|
|
#**{zulip_discussion_channel_name}** channel, as you can see in the left sidebar
|
|
|
|
|
and above.
|
|
|
|
|
""").format(
|
2024-05-13 09:30:12 +02:00
|
|
|
|
zulip_discussion_channel_name=str(Realm.ZULIP_DISCUSSION_CHANNEL_NAME),
|
|
|
|
|
topic_name=_("welcome to Zulip!"),
|
|
|
|
|
)
|
2024-03-26 13:58:30 +01:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content2_of_welcome_to_zulip_topic_name = _("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
You can read Zulip one conversation at a time, seeing each message in context,
|
|
|
|
|
no matter how many other conversations are going on.
|
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content3_of_welcome_to_zulip_topic_name = _("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
:point_right: When you're ready, check out your [Inbox](/#inbox) for other
|
2024-05-11 00:18:35 +02:00
|
|
|
|
conversations with unread messages.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content1_of_start_conversation_topic_name = _("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
To kick off a new conversation, click **Start new conversation** below.
|
2024-05-11 00:18:35 +02:00
|
|
|
|
The new conversation thread will be labeled with its own topic.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content2_of_start_conversation_topic_name = _("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
For a good topic name, think about finishing the sentence: “Hey, can we chat about…?”
|
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content3_of_start_conversation_topic_name = _("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
:point_right: Try starting a new conversation in this channel.
|
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content1_of_experiments_topic_name = (
|
|
|
|
|
_("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
:point_right: Use this topic to try out [Zulip's messaging features]({format_message_help_url}).
|
|
|
|
|
""")
|
2024-05-13 09:30:12 +02:00
|
|
|
|
).format(format_message_help_url="/help/format-your-message-using-markdown")
|
2024-03-26 13:58:30 +01:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content2_of_experiments_topic_name = (
|
|
|
|
|
_("""
|
2024-03-26 13:58:30 +01:00
|
|
|
|
```spoiler Want to see some examples?
|
|
|
|
|
|
|
|
|
|
````python
|
2024-07-10 00:50:13 +02:00
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
print("code blocks")
|
2024-07-10 00:50:13 +02:00
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
- bulleted
|
|
|
|
|
- lists
|
|
|
|
|
|
|
|
|
|
Link to a conversation: #**{zulip_discussion_channel_name}>{topic_name}**
|
2024-07-10 00:50:13 +02:00
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
```
|
|
|
|
|
""")
|
2024-05-13 09:30:12 +02:00
|
|
|
|
).format(
|
|
|
|
|
zulip_discussion_channel_name=str(Realm.ZULIP_DISCUSSION_CHANNEL_NAME),
|
|
|
|
|
topic_name=_("welcome to Zulip!"),
|
|
|
|
|
)
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content1_of_greetings_topic_name = _("""
|
2024-05-11 00:18:35 +02:00
|
|
|
|
This **greetings** topic is a great place to say “hi” :wave: to your teammates.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
""")
|
|
|
|
|
|
2024-05-13 09:30:12 +02:00
|
|
|
|
content2_of_greetings_topic_name = _("""
|
2024-05-11 00:18:35 +02:00
|
|
|
|
:point_right: Click on this message to start a new message in the same conversation.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
""")
|
|
|
|
|
|
2024-07-12 02:30:17 +02:00
|
|
|
|
welcome_messages: list[dict[str, str]] = []
|
2024-03-26 13:58:30 +01:00
|
|
|
|
|
|
|
|
|
# Messages added to the "welcome messages" list last will be most
|
|
|
|
|
# visible to users, since welcome messages will likely be browsed
|
|
|
|
|
# via the right sidebar or recent conversations view, both of
|
|
|
|
|
# which are sorted newest-first.
|
|
|
|
|
#
|
|
|
|
|
# Initial messages are configured below.
|
|
|
|
|
|
|
|
|
|
# Advertising moving messages.
|
|
|
|
|
welcome_messages += [
|
2021-02-12 08:19:30 +01:00
|
|
|
|
{
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"channel_name": str(Realm.ZULIP_DISCUSSION_CHANNEL_NAME),
|
|
|
|
|
"topic_name": _("moving messages"),
|
|
|
|
|
"content": content,
|
|
|
|
|
}
|
|
|
|
|
for content in [
|
|
|
|
|
content1_of_moving_messages_topic_name,
|
|
|
|
|
content2_of_moving_messages_topic_name,
|
|
|
|
|
]
|
|
|
|
|
]
|
|
|
|
|
|
2024-05-11 00:18:35 +02:00
|
|
|
|
# Suggestion to test messaging features.
|
|
|
|
|
# Dependency on knowing how to send messages.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
welcome_messages += [
|
2021-02-12 08:19:30 +01:00
|
|
|
|
{
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"channel_name": str(realm.ZULIP_SANDBOX_CHANNEL_NAME),
|
2024-05-11 00:18:35 +02:00
|
|
|
|
"topic_name": _("experiments"),
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"content": content,
|
|
|
|
|
}
|
2024-05-11 00:18:35 +02:00
|
|
|
|
for content in [content1_of_experiments_topic_name, content2_of_experiments_topic_name]
|
2024-03-26 13:58:30 +01:00
|
|
|
|
]
|
|
|
|
|
|
2024-05-11 00:18:35 +02:00
|
|
|
|
# Suggestion to start your first new conversation.
|
2024-03-26 13:58:30 +01:00
|
|
|
|
welcome_messages += [
|
2024-02-05 17:12:55 +01:00
|
|
|
|
{
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"channel_name": str(realm.ZULIP_SANDBOX_CHANNEL_NAME),
|
2024-05-11 00:18:35 +02:00
|
|
|
|
"topic_name": _("start a conversation"),
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"content": content,
|
|
|
|
|
}
|
2024-05-11 00:18:35 +02:00
|
|
|
|
for content in [
|
|
|
|
|
content1_of_start_conversation_topic_name,
|
|
|
|
|
content2_of_start_conversation_topic_name,
|
|
|
|
|
content3_of_start_conversation_topic_name,
|
|
|
|
|
]
|
2024-03-26 13:58:30 +01:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# Suggestion to send first message as a hi to your team.
|
|
|
|
|
welcome_messages += [
|
|
|
|
|
{
|
|
|
|
|
"channel_name": str(Realm.DEFAULT_NOTIFICATION_STREAM_NAME),
|
|
|
|
|
"topic_name": _("greetings"),
|
|
|
|
|
"content": content,
|
|
|
|
|
}
|
|
|
|
|
for content in [content1_of_greetings_topic_name, content2_of_greetings_topic_name]
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# Main welcome message, this should be last.
|
|
|
|
|
welcome_messages += [
|
|
|
|
|
{
|
|
|
|
|
"channel_name": str(realm.ZULIP_DISCUSSION_CHANNEL_NAME),
|
|
|
|
|
"topic_name": _("welcome to Zulip!"),
|
|
|
|
|
"content": content,
|
|
|
|
|
}
|
|
|
|
|
for content in [
|
|
|
|
|
content1_of_welcome_to_zulip_topic_name,
|
|
|
|
|
content2_of_welcome_to_zulip_topic_name,
|
|
|
|
|
content3_of_welcome_to_zulip_topic_name,
|
|
|
|
|
]
|
python: Convert assignment type annotations to Python 3.6 style.
This commit was split by tabbott; this piece covers the vast majority
of files in Zulip, but excludes scripts/, tools/, and puppet/ to help
ensure we at least show the right error messages for Xenial systems.
We can likely further refine the remaining pieces with some testing.
Generated by com2ann, with whitespace fixes and various manual fixes
for runtime issues:
- invoiced_through: Optional[LicenseLedger] = models.ForeignKey(
+ invoiced_through: Optional["LicenseLedger"] = models.ForeignKey(
-_apns_client: Optional[APNsClient] = None
+_apns_client: Optional["APNsClient"] = None
- notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- signup_notifications_stream: Optional[Stream] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
+ signup_notifications_stream: Optional["Stream"] = models.ForeignKey('Stream', related_name='+', null=True, blank=True, on_delete=CASCADE)
- author: Optional[UserProfile] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
+ author: Optional["UserProfile"] = models.ForeignKey('UserProfile', blank=True, null=True, on_delete=CASCADE)
- bot_owner: Optional[UserProfile] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
+ bot_owner: Optional["UserProfile"] = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
- default_sending_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
- default_events_register_stream: Optional[Stream] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_sending_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
+ default_events_register_stream: Optional["Stream"] = models.ForeignKey('zerver.Stream', null=True, related_name='+', on_delete=CASCADE)
-descriptors_by_handler_id: Dict[int, ClientDescriptor] = {}
+descriptors_by_handler_id: Dict[int, "ClientDescriptor"] = {}
-worker_classes: Dict[str, Type[QueueProcessingWorker]] = {}
-queues: Dict[str, Dict[str, Type[QueueProcessingWorker]]] = {}
+worker_classes: Dict[str, Type["QueueProcessingWorker"]] = {}
+queues: Dict[str, Dict[str, Type["QueueProcessingWorker"]]] = {}
-AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional[LDAPSearch] = None
+AUTH_LDAP_REVERSE_EMAIL_SEARCH: Optional["LDAPSearch"] = None
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-22 01:09:50 +02:00
|
|
|
|
]
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
# End of message declarations; now we actually send them.
|
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
messages = [
|
|
|
|
|
internal_prep_stream_message_by_name(
|
|
|
|
|
realm,
|
|
|
|
|
welcome_bot,
|
2024-03-26 13:58:30 +01:00
|
|
|
|
message["channel_name"],
|
2024-01-14 14:38:50 +01:00
|
|
|
|
message["topic_name"],
|
2024-05-12 05:54:25 +02:00
|
|
|
|
remove_single_newlines(message["content"]),
|
2021-02-12 08:19:30 +01:00
|
|
|
|
)
|
|
|
|
|
for message in welcome_messages
|
|
|
|
|
]
|
2023-10-09 13:11:32 +02:00
|
|
|
|
message_ids = [
|
|
|
|
|
sent_message_result.message_id for sent_message_result in do_send_messages(messages)
|
|
|
|
|
]
|
2017-08-02 06:02:06 +02:00
|
|
|
|
|
2024-06-27 15:06:09 +02:00
|
|
|
|
seen_topics = set()
|
|
|
|
|
onboarding_topics_first_message_ids = set()
|
|
|
|
|
for index, message in enumerate(welcome_messages):
|
|
|
|
|
topic_name = message["topic_name"]
|
|
|
|
|
if topic_name not in seen_topics:
|
|
|
|
|
onboarding_topics_first_message_ids.add(message_ids[index])
|
|
|
|
|
seen_topics.add(topic_name)
|
|
|
|
|
|
|
|
|
|
onboarding_user_messages = []
|
|
|
|
|
for message_id in message_ids:
|
|
|
|
|
flags = OnboardingUserMessage.flags.historical
|
|
|
|
|
if message_id in onboarding_topics_first_message_ids:
|
|
|
|
|
flags |= OnboardingUserMessage.flags.starred
|
|
|
|
|
onboarding_user_messages.append(
|
|
|
|
|
OnboardingUserMessage(realm=realm, message_id=message_id, flags=flags)
|
2024-06-21 08:05:00 +02:00
|
|
|
|
)
|
2024-06-27 15:06:09 +02:00
|
|
|
|
|
2024-06-21 08:05:00 +02:00
|
|
|
|
OnboardingUserMessage.objects.bulk_create(onboarding_user_messages)
|
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
# We find the one of our just-sent greetings messages, and react to it.
|
|
|
|
|
# This is a bit hacky, but works and is kinda a 1-off thing.
|
|
|
|
|
greetings_message = (
|
|
|
|
|
Message.objects.select_for_update()
|
2024-05-12 06:29:58 +02:00
|
|
|
|
.filter(
|
|
|
|
|
id__in=message_ids, content=remove_single_newlines(content1_of_greetings_topic_name)
|
|
|
|
|
)
|
2024-03-26 13:58:30 +01:00
|
|
|
|
.first()
|
2020-11-14 09:10:24 +01:00
|
|
|
|
)
|
2024-03-26 13:58:30 +01:00
|
|
|
|
assert greetings_message is not None
|
|
|
|
|
emoji_data = get_emoji_data(realm.id, "wave")
|
2023-07-14 14:25:57 +02:00
|
|
|
|
do_add_reaction(
|
2024-03-26 13:58:30 +01:00
|
|
|
|
welcome_bot, greetings_message, "wave", emoji_data.emoji_code, emoji_data.reaction_type
|
2023-07-14 14:25:57 +02:00
|
|
|
|
)
|