streams: refactor stream creation code path.

Refactor list_to_streams and create_streams_if_needed to take a list
of dictionaries, instead of a list of stream names.  This is
preparation for being able to pass additional arguments into the
stream creation process.

An important note: This removes a set of validation code from the
start of add_subscriptions_backend; doing so is correct because
list_to_streams has that same validation code already.

[with some tweaks by tabbott for clarity]
This commit is contained in:
Calvin Lee
2016-11-20 15:55:50 -05:00
committed by Tim Abbott
parent 308069d828
commit 8461cc411e
3 changed files with 41 additions and 26 deletions

View File

@@ -976,13 +976,15 @@ def create_stream_if_needed(realm, stream_name, invite_only=False):
send_event(event, active_user_ids(realm))
return stream, created
def create_streams_if_needed(realm, stream_names, invite_only):
# type: (Realm, List[text_type], bool) -> Tuple[List[Stream], List[Stream]]
def create_streams_if_needed(realm, stream_dicts, invite_only):
# type: (Realm, List[Mapping[str, text_type]], bool) -> Tuple[List[Stream], List[Stream]]
"""Note that stream_dict["name"] is assumed to already be stripped of
whitespace"""
added_streams = [] # type: List[Stream]
existing_streams = [] # type: List[Stream]
for stream_name in stream_names:
for stream_dict in stream_dicts:
stream, created = create_stream_if_needed(realm,
stream_name,
stream_dict["name"],
invite_only=invite_only)
if created:
added_streams.append(stream)