2020-11-24 12:31:28 +01:00
|
|
|
|
from typing import Dict, List
|
2020-06-11 00:54:34 +02:00
|
|
|
|
|
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
|
2023-12-15 01:16:00 +01:00
|
|
|
|
from zerver.models import Message, Realm, UserProfile
|
|
|
|
|
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()
|
2023-03-23 21:16:47 +01:00
|
|
|
|
return UserProfile.objects.filter(email__in=bot_emails).values("email").annotate(
|
|
|
|
|
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
|
|
|
|
|
2023-05-01 18:01:47 +02:00
|
|
|
|
def send_initial_direct_message(user: UserProfile) -> None:
|
|
|
|
|
# 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-05-06 15:27:22 +02:00
|
|
|
|
getting_started_help = user.realm.url + "/help/using-zulip-for-a-class"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
getting_started_string = (
|
|
|
|
|
_(
|
|
|
|
|
"If you are new to Zulip, check out our [Using Zulip for a class guide]({getting_started_url})!"
|
|
|
|
|
)
|
|
|
|
|
).format(getting_started_url=getting_started_help)
|
|
|
|
|
else:
|
2024-05-06 15:27:22 +02:00
|
|
|
|
getting_started_help = user.realm.url + "/help/getting-started-with-zulip"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
getting_started_string = (
|
|
|
|
|
_(
|
|
|
|
|
"If you are new to Zulip, check out our [Getting started guide]({getting_started_url})!"
|
|
|
|
|
)
|
|
|
|
|
).format(getting_started_url=getting_started_help)
|
|
|
|
|
|
|
|
|
|
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-05-06 15:27:22 +02:00
|
|
|
|
organization_setup_help = user.realm.url + "/help/setting-up-zulip-for-a-class"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
organization_setup_string = (
|
|
|
|
|
" "
|
|
|
|
|
+ _(
|
|
|
|
|
"We also have a guide for [Setting up Zulip for a class]({organization_setup_url})."
|
|
|
|
|
)
|
|
|
|
|
).format(organization_setup_url=organization_setup_help)
|
|
|
|
|
else:
|
|
|
|
|
organization_setup_help = (
|
2024-05-06 15:27:22 +02:00
|
|
|
|
user.realm.url + "/help/getting-your-organization-started-with-zulip"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
)
|
|
|
|
|
organization_setup_string = (
|
|
|
|
|
" "
|
|
|
|
|
+ _(
|
|
|
|
|
"We also have a guide for [Setting up your organization]({organization_setup_url})."
|
|
|
|
|
)
|
|
|
|
|
).format(organization_setup_url=organization_setup_help)
|
|
|
|
|
|
|
|
|
|
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-05-06 15:27:22 +02:00
|
|
|
|
demo_organization_help = user.realm.url + "/help/demo-organizations"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
demo_organization_warning_string = (
|
2022-01-24 11:22:11 +01:00
|
|
|
|
_(
|
2023-05-01 18:01:47 +02:00
|
|
|
|
"Note that this is a [demo organization]({demo_organization_help_url}) and will be "
|
2022-01-24 11:22:11 +01:00
|
|
|
|
"**automatically deleted** in 30 days."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n"
|
2023-05-01 18:01:47 +02:00
|
|
|
|
).format(demo_organization_help_url=demo_organization_help)
|
2022-01-24 11:22:11 +01:00
|
|
|
|
|
|
|
|
|
content = "".join(
|
|
|
|
|
[
|
2023-05-01 18:01:47 +02:00
|
|
|
|
_("Hello, and welcome to Zulip!") + "👋" + " ",
|
2023-01-24 15:36:03 +01:00
|
|
|
|
_("This is a direct message from me, Welcome Bot.") + "\n\n",
|
2023-05-01 18:01:47 +02:00
|
|
|
|
"{getting_started_text}",
|
2023-01-03 02:16:53 +01:00
|
|
|
|
"{organization_setup_text}\n\n",
|
2023-05-01 18:01:47 +02:00
|
|
|
|
"{demo_organization_text}",
|
2022-01-24 11:22:11 +01:00
|
|
|
|
_(
|
|
|
|
|
"I can also help you get set up! Just click anywhere on this message or press `r` to reply."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
|
|
|
|
_("Here are a few messages I understand:") + " ",
|
|
|
|
|
bot_commands(),
|
|
|
|
|
]
|
|
|
|
|
)
|
2021-02-12 08:19:30 +01:00
|
|
|
|
|
|
|
|
|
content = content.format(
|
2023-05-01 18:01:47 +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
|
|
|
|
)
|
|
|
|
|
|
2021-07-26 17:04:16 +02:00
|
|
|
|
internal_send_private_message(
|
2022-10-22 13:25:06 +02:00
|
|
|
|
get_system_bot(settings.WELCOME_BOT, user.realm_id),
|
|
|
|
|
user,
|
|
|
|
|
content,
|
|
|
|
|
# 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
|
|
|
|
)
|
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"]:
|
|
|
|
|
return _(
|
2023-03-23 03:59:33 +01:00
|
|
|
|
"You can [download](/apps/) the [mobile and desktop apps](/apps/). "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"Zulip also works great in a browser."
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower == "profile":
|
|
|
|
|
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)."
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower == "theme":
|
|
|
|
|
return _(
|
2023-06-29 15:28:38 +02:00
|
|
|
|
"Go to [Preferences](#settings/preferences) "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"to [switch between the light and dark themes](/help/dark-theme), "
|
|
|
|
|
"[pick your favorite emoji theme](/help/emoji-and-emoticons#change-your-emoji-set), "
|
|
|
|
|
"[change your language](/help/change-your-language), "
|
|
|
|
|
"and make other tweaks to your Zulip experience."
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["stream", "streams", "channel", "channels"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
2024-04-17 15:37:13 +02:00
|
|
|
|
_("In Zulip, channels [determine who gets a message]({help_link}).").format(
|
2024-05-06 21:25:38 +02:00
|
|
|
|
help_link="/help/introduction-to-channels"
|
2021-10-16 10:29:21 +02:00
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
2024-04-17 15:37:13 +02:00
|
|
|
|
_("[Browse and subscribe to channels]({settings_link}).").format(
|
2024-04-30 13:30:24 +02:00
|
|
|
|
settings_link="#channels/all"
|
2024-04-17 15:37:13 +02:00
|
|
|
|
),
|
2021-10-16 10:29:21 +02:00
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["topic", "topics"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_(
|
2024-05-07 09:51:46 +02:00
|
|
|
|
"In Zulip, topics [tell you what a message is about](/help/introduction-to-topics). "
|
2021-10-16 10:29:21 +02:00
|
|
|
|
"They are light-weight subjects, very similar to the subject line of an email."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
|
|
|
|
_(
|
2022-10-24 12:18:09 +02:00
|
|
|
|
"Check out [Recent conversations](#recent) to see what's happening! "
|
2023-01-24 15:36:03 +01:00
|
|
|
|
'You can return to this conversation by clicking "Direct messages" in the upper left.'
|
2021-10-16 10:29:21 +02:00
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["keyboard", "shortcuts", "keyboard shortcuts"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_(
|
|
|
|
|
"Zulip's [keyboard shortcuts](#keyboard-shortcuts) "
|
|
|
|
|
"let you navigate the app quickly and efficiently."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
|
|
|
|
_("Press `?` any time to see a [cheat sheet](#keyboard-shortcuts)."),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["formatting", "message formatting"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_(
|
|
|
|
|
"Zulip uses [Markdown](/help/format-your-message-using-markdown), "
|
|
|
|
|
"an intuitive format for **bold**, *italics*, bulleted lists, and more. "
|
|
|
|
|
"Click [here](#message-formatting) for a cheat sheet."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
|
|
|
|
_(
|
|
|
|
|
"Check out our [messaging tips](/help/messaging-tips) "
|
|
|
|
|
"to learn about emoji reactions, code blocks and much more!"
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["help", "?"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_("Here are a few messages I understand:") + " ",
|
2021-12-06 19:55:22 +01:00
|
|
|
|
bot_commands(no_help_command=True) + "\n\n",
|
2021-10-16 10:29:21 +02:00
|
|
|
|
_(
|
|
|
|
|
"Check out our [Getting started guide](/help/getting-started-with-zulip), "
|
|
|
|
|
"or browse the [Help center](/help/) to learn more!"
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
else:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_(
|
|
|
|
|
"I’m sorry, I did not understand your message. Please try one of the following commands:"
|
|
|
|
|
)
|
|
|
|
|
+ " ",
|
|
|
|
|
bot_commands(),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
content = select_welcome_bot_response(human_response_lower)
|
2022-10-22 13:25:06 +02:00
|
|
|
|
|
|
|
|
|
internal_send_private_message(
|
|
|
|
|
welcome_bot,
|
|
|
|
|
send_request.message.sender,
|
|
|
|
|
content,
|
|
|
|
|
# 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
|
|
|
|
|
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
|
|
|
|
@transaction.atomic
|
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
|
|
|
|
|
print("code blocks")
|
|
|
|
|
````
|
|
|
|
|
|
|
|
|
|
- bulleted
|
|
|
|
|
- lists
|
|
|
|
|
|
|
|
|
|
Link to a conversation: #**{zulip_discussion_channel_name}>{topic_name}**
|
|
|
|
|
```
|
|
|
|
|
""")
|
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-05-13 09:30:12 +02:00
|
|
|
|
content_of_zulip_update_announcements_topic_name = (
|
|
|
|
|
_("""
|
2024-03-23 04:29:56 +01:00
|
|
|
|
Welcome! To help you learn about new features and configuration options,
|
2024-02-05 17:12:55 +01:00
|
|
|
|
this topic will receive messages about important changes in Zulip.
|
|
|
|
|
|
2024-03-23 04:29:56 +01:00
|
|
|
|
You can read these update messages whenever it's convenient, or
|
|
|
|
|
[mute]({mute_topic_help_url}) this topic if you are not interested.
|
|
|
|
|
If your organization does not want to receive these announcements,
|
2024-02-05 17:12:55 +01:00
|
|
|
|
they can be disabled. [Learn more]({zulip_update_announcements_help_url}).
|
2024-05-13 09:30:12 +02:00
|
|
|
|
""")
|
|
|
|
|
).format(
|
|
|
|
|
zulip_update_announcements_help_url="/help/configure-automated-notices#zulip-update-announcements",
|
|
|
|
|
mute_topic_help_url="/help/mute-a-topic",
|
|
|
|
|
)
|
2024-02-05 17:12:55 +01:00
|
|
|
|
|
2024-03-26 13:58:30 +01:00
|
|
|
|
welcome_messages: List[Dict[str, str]] = []
|
|
|
|
|
|
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
|
|
# Zulip updates system advertisement.
|
|
|
|
|
welcome_messages += [
|
2021-02-12 08:19:30 +01:00
|
|
|
|
{
|
2024-03-26 13:58:30 +01:00
|
|
|
|
"channel_name": str(Realm.DEFAULT_NOTIFICATION_STREAM_NAME),
|
|
|
|
|
"topic_name": str(Realm.ZULIP_UPDATE_ANNOUNCEMENTS_TOPIC_NAME),
|
|
|
|
|
"content": content_of_zulip_update_announcements_topic_name,
|
2021-02-12 08:19:30 +01:00
|
|
|
|
},
|
2024-03-26 13:58:30 +01:00
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
# 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-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
|
|
|
|
)
|