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

@@ -36,6 +36,25 @@ LEGACY_PREV_TOPIC = "prev_subject"
# database, but it's the JSON field.
EXPORT_TOPIC_NAME = "subject"
'''
The following functions are for user-facing APIs
where we'll want to support "subject" for a while.
'''
def get_topic_from_message_info(message_info: Dict[str, Any]) -> str:
'''
Use this where you are getting dicts that are based off of messages
that may come from the outside world, especially from third party
APIs and bots.
We prefer 'topic' to 'subject' here. We expect at least one field
to be present (or the caller must know how to handle KeyError).
'''
if 'topic' in message_info:
return message_info['topic']
return message_info['subject']
def REQ_topic() -> Optional[str]:
# REQ handlers really return a REQ, but we
# lie to make the rest of the type matching work.