topic -> subject: Extract get_topic_from_message_info().

This changes files where it's safe to just assume caller
may use either "topic" or "subject", and we prefer "topic"
but support "subject".
This commit is contained in:
Steve Howell
2018-11-10 21:50:28 +00:00
committed by Tim Abbott
parent aa4e9cec2d
commit 27d79352da
7 changed files with 50 additions and 11 deletions

View File

@@ -16,6 +16,7 @@ from zerver.models import Realm, UserProfile, get_user_profile_by_id, get_client
GENERIC_INTERFACE, Service, SLACK_INTERFACE, email_to_domain, get_service_profile
from zerver.lib.actions import check_send_message
from zerver.lib.queue import retry_event
from zerver.lib.topic import get_topic_from_message_info
from zerver.lib.url_encoding import near_message_url
from zerver.lib.validator import check_dict, check_string
from zerver.decorator import JsonableError
@@ -128,7 +129,7 @@ def send_response_message(bot_id: str, message_info: Dict[str, Any], response_da
message_info is used to address the message and should have these fields:
type - "stream" or "private"
display_recipient - like we have in other message events
subject - the topic name (if relevant)
topic - see get_topic_from_message_info
response_data is what the bot wants to send back and has these fields:
content - raw markdown content for Zulip to render
@@ -136,7 +137,10 @@ def send_response_message(bot_id: str, message_info: Dict[str, Any], response_da
message_type = message_info['type']
display_recipient = message_info['display_recipient']
topic_name = message_info.get('subject')
try:
topic_name = get_topic_from_message_info(message_info)
except KeyError:
topic_name = None
bot_user = get_user_profile_by_id(bot_id)
realm = bot_user.realm