Extract get_turtle_message().

This seems like kind of a silly function to extract
to topic.py, but it will theoretically help us sweep
"subject" if we change the DB.

It had test coverage.
This commit is contained in:
Steve Howell 2018-11-11 19:35:31 +00:00 committed by Tim Abbott
parent cc33e4cd0c
commit eb4d279bbc
3 changed files with 11 additions and 5 deletions

View File

@ -40,7 +40,6 @@ FILES_WITH_LEGACY_SUBJECT = {
# TRY TO FIX THESE! If you can't fix them, try to
# add comments here and/or in the file itself about
# why sweeping subject is tricky.
'zerver/lib/onboarding.py',
'zerver/lib/stream_topic.py',
# This has lots of query data embedded, so it's hard

View File

@ -5,6 +5,7 @@ from zerver.lib.actions import set_default_streams, bulk_add_subscriptions, \
internal_prep_stream_message, internal_send_private_message, \
create_stream_if_needed, create_streams_if_needed, do_send_messages, \
do_add_reaction_legacy, create_users, missing_any_realm_internal_bots
from zerver.lib.topic import get_turtle_message
from zerver.models import Realm, UserProfile, Message, Reaction, get_system_bot
from typing import Any, Dict, List, Mapping
@ -114,8 +115,5 @@ def send_initial_realm_messages(realm: Realm) -> None:
# 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.
turtle_message = Message.objects.get(
id__in=message_ids,
subject='topic demonstration',
content__icontains='cute/turtle.png')
turtle_message = get_turtle_message(message_ids=message_ids)
do_add_reaction_legacy(welcome_bot, turtle_message, 'turtle')

View File

@ -227,3 +227,12 @@ def get_topic_history_for_web_public_stream(recipient: Recipient) -> List[Dict[s
cursor.close()
return generate_topic_history_from_db_rows(rows)
def get_turtle_message(message_ids: List[int]) -> Message:
# This is used for onboarding, and it's only extracted
# here to make subject -> topic sweeping easier.
turtle_message = Message.objects.get( # nolint
id__in=message_ids,
subject='topic demonstration',
content__icontains='cute/turtle.png')
return turtle_message