refactor: Move default_sending_stream logic to Addressee.

Having Addressee take care of setting stream_name to
sender.default_sending_stream.name makes us able to have
the invariant that stream_name is never None when the
message type is 'stream', which will help for mypy, among
other things.

One thing to be aware of is that Addressee does do a little
bit of validation work, and this adds yet another JsonableError
exception.  I don't view this as a bad thing, just something to
know.
This commit is contained in:
Steve Howell 2017-09-28 12:14:08 -07:00
parent e3917b7d63
commit aaaaa66d4c
2 changed files with 5 additions and 7 deletions

View File

@ -1546,12 +1546,6 @@ def check_message(sender, client, addressee,
if addressee.is_stream(): if addressee.is_stream():
stream_name = addressee.stream_name() stream_name = addressee.stream_name()
if stream_name is None:
if sender.default_sending_stream:
# Use the users default stream
stream_name = sender.default_sending_stream.name
else:
raise JsonableError(_('Missing stream'))
stream_name = stream_name.strip() stream_name = stream_name.strip()
check_stream_name(stream_name) check_stream_name(stream_name)

View File

@ -97,7 +97,11 @@ class Addressee(object):
# This is a hack to deal with the fact that we still support # This is a hack to deal with the fact that we still support
# default streams (and the None will be converted later in the # default streams (and the None will be converted later in the
# callpath). # callpath).
stream_name = None if sender.default_sending_stream:
# Use the users default stream
stream_name = sender.default_sending_stream.name
else:
raise JsonableError(_('Missing stream'))
return Addressee.for_stream(stream_name, topic_name) return Addressee.for_stream(stream_name, topic_name)
elif message_type_name == 'private': elif message_type_name == 'private':