mirror of https://github.com/zulip/zulip.git
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:
parent
e3917b7d63
commit
aaaaa66d4c
|
@ -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)
|
||||||
|
|
|
@ -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':
|
||||||
|
|
Loading…
Reference in New Issue