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
|
2020-11-24 12:31:28 +01:00
|
|
|
|
from zerver.lib.message import SendMessageRequest
|
2019-02-24 22:22:32 +01:00
|
|
|
|
from zerver.models import Message, Realm, UserProfile, 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:
|
|
|
|
|
getting_started_help = user.realm.uri + "/help/using-zulip-for-a-class"
|
|
|
|
|
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:
|
|
|
|
|
getting_started_help = user.realm.uri + "/help/getting-started-with-zulip"
|
|
|
|
|
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:
|
|
|
|
|
organization_setup_help = user.realm.uri + "/help/setting-up-zulip-for-a-class"
|
|
|
|
|
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 = (
|
|
|
|
|
user.realm.uri + "/help/getting-your-organization-started-with-zulip"
|
|
|
|
|
)
|
|
|
|
|
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:
|
|
|
|
|
demo_organization_help = user.realm.uri + "/help/demo-organizations"
|
|
|
|
|
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",
|
|
|
|
|
"streams",
|
|
|
|
|
"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")
|
|
|
|
|
return ", ".join(["`" + command + "`" for command in commands]) + "."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
[
|
|
|
|
|
_(
|
|
|
|
|
"In Zulip, streams [determine who gets a message](/help/streams-and-topics). "
|
|
|
|
|
"They are similar to channels in other chat apps."
|
|
|
|
|
)
|
|
|
|
|
+ "\n\n",
|
|
|
|
|
_("[Browse and subscribe to streams](#streams/all)."),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
elif human_response_lower in ["topic", "topics"]:
|
|
|
|
|
return "".join(
|
|
|
|
|
[
|
|
|
|
|
_(
|
|
|
|
|
"In Zulip, topics [tell you what a message is about](/help/streams-and-topics). "
|
|
|
|
|
"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:
|
2021-07-26 17:04:16 +02:00
|
|
|
|
welcome_bot = get_system_bot(settings.WELCOME_BOT, realm.id)
|
2017-08-02 05:20:50 +02:00
|
|
|
|
# Make sure each stream created in the realm creation process has at least one message below
|
|
|
|
|
# Order corresponds to the ordering of the streams on the left sidebar, to make the initial Home
|
|
|
|
|
# view slightly less overwhelming
|
2020-04-10 18:50:22 +02:00
|
|
|
|
content_of_private_streams_topic = (
|
2021-02-12 08:19:30 +01:00
|
|
|
|
_("This is a private stream, as indicated by the lock icon next to the stream name.")
|
|
|
|
|
+ " "
|
|
|
|
|
+ _("Private streams are only visible to stream members.")
|
|
|
|
|
+ "\n"
|
2020-04-10 18:50:22 +02:00
|
|
|
|
"\n"
|
2021-02-12 08:19:30 +01:00
|
|
|
|
+ _(
|
|
|
|
|
"To manage this stream, go to [Stream settings]({stream_settings_url}) "
|
|
|
|
|
"and click on `{initial_private_stream_name}`."
|
|
|
|
|
)
|
|
|
|
|
).format(
|
|
|
|
|
stream_settings_url="#streams/subscribed",
|
|
|
|
|
initial_private_stream_name=Realm.INITIAL_PRIVATE_STREAM_NAME,
|
|
|
|
|
)
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
|
|
|
|
content1_of_topic_demonstration_topic = (
|
2021-02-12 08:19:30 +01:00
|
|
|
|
_(
|
|
|
|
|
"This is a message on stream #**{default_notification_stream_name}** with the "
|
|
|
|
|
"topic `topic demonstration`."
|
|
|
|
|
)
|
2020-04-10 18:50:22 +02:00
|
|
|
|
).format(default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME)
|
|
|
|
|
|
|
|
|
|
content2_of_topic_demonstration_topic = (
|
2021-02-12 08:19:30 +01:00
|
|
|
|
_("Topics are a lightweight tool to keep conversations organized.")
|
|
|
|
|
+ " "
|
|
|
|
|
+ _("You can learn more about topics at [Streams and topics]({about_topics_help_url}).")
|
2021-09-15 01:42:35 +02:00
|
|
|
|
).format(about_topics_help_url="/help/streams-and-topics")
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
|
|
|
|
content_of_swimming_turtles_topic = (
|
2021-02-12 08:19:30 +01:00
|
|
|
|
_(
|
|
|
|
|
"This is a message on stream #**{default_notification_stream_name}** with the "
|
|
|
|
|
"topic `swimming turtles`."
|
|
|
|
|
)
|
|
|
|
|
+ "\n"
|
2020-04-10 18:50:22 +02:00
|
|
|
|
"\n"
|
|
|
|
|
"[](/static/images/cute/turtle.png)"
|
|
|
|
|
"\n"
|
2021-02-12 08:19:30 +01:00
|
|
|
|
"\n"
|
|
|
|
|
+ _(
|
|
|
|
|
"[Start a new topic]({start_topic_help_url}) any time you're not replying to a \
|
|
|
|
|
previous message."
|
|
|
|
|
)
|
|
|
|
|
).format(
|
|
|
|
|
default_notification_stream_name=Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
|
|
|
|
|
start_topic_help_url="/help/start-a-new-topic",
|
|
|
|
|
)
|
2020-04-10 18:50:22 +02:00
|
|
|
|
|
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
|
|
|
|
welcome_messages: List[Dict[str, str]] = [
|
2021-02-12 08:19:30 +01:00
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
|
"stream": Realm.INITIAL_PRIVATE_STREAM_NAME,
|
|
|
|
|
"topic": "private streams",
|
|
|
|
|
"content": content_of_private_streams_topic,
|
2021-02-12 08:19:30 +01:00
|
|
|
|
},
|
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
|
"stream": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
|
|
|
|
|
"topic": "topic demonstration",
|
|
|
|
|
"content": content1_of_topic_demonstration_topic,
|
2021-02-12 08:19:30 +01:00
|
|
|
|
},
|
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
|
"stream": Realm.DEFAULT_NOTIFICATION_STREAM_NAME,
|
|
|
|
|
"topic": "topic demonstration",
|
|
|
|
|
"content": content2_of_topic_demonstration_topic,
|
2021-02-12 08:19:30 +01:00
|
|
|
|
},
|
|
|
|
|
{
|
2021-02-12 08:20:45 +01:00
|
|
|
|
"stream": realm.DEFAULT_NOTIFICATION_STREAM_NAME,
|
|
|
|
|
"topic": "swimming turtles",
|
|
|
|
|
"content": content_of_swimming_turtles_topic,
|
2021-02-12 08:19:30 +01:00
|
|
|
|
},
|
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
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
messages = [
|
|
|
|
|
internal_prep_stream_message_by_name(
|
|
|
|
|
realm,
|
|
|
|
|
welcome_bot,
|
2021-02-12 08:20:45 +01:00
|
|
|
|
message["stream"],
|
|
|
|
|
message["topic"],
|
|
|
|
|
message["content"],
|
2021-02-12 08:19:30 +01:00
|
|
|
|
)
|
|
|
|
|
for message in welcome_messages
|
|
|
|
|
]
|
2017-08-02 06:02:06 +02:00
|
|
|
|
message_ids = do_send_messages(messages)
|
|
|
|
|
|
|
|
|
|
# We find the one of our just-sent messages with turtle.png in it,
|
|
|
|
|
# and react to it. This is a bit hacky, but works and is kinda a
|
|
|
|
|
# 1-off thing.
|
2020-11-14 09:10:24 +01:00
|
|
|
|
turtle_message = Message.objects.select_for_update().get(
|
|
|
|
|
id__in=message_ids, content__icontains="cute/turtle.png"
|
|
|
|
|
)
|
2023-07-14 14:25:57 +02:00
|
|
|
|
emoji_data = get_emoji_data(realm.id, "turtle")
|
|
|
|
|
do_add_reaction(
|
|
|
|
|
welcome_bot, turtle_message, "turtle", emoji_data.emoji_code, emoji_data.reaction_type
|
|
|
|
|
)
|