mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user