diff --git a/zerver/actions/streams.py b/zerver/actions/streams.py index 6d0d15de09..e90f192ef3 100644 --- a/zerver/actions/streams.py +++ b/zerver/actions/streams.py @@ -39,8 +39,8 @@ from zerver.lib.stream_traffic import get_streams_traffic from zerver.lib.streams import ( can_access_stream_user_ids, check_basic_stream_access, + get_group_setting_value_dict_for_streams, get_occupied_streams, - get_setting_values_for_group_settings, get_stream_permission_policy_name, render_stream_description, send_stream_creation_event, @@ -354,13 +354,8 @@ def send_subscription_add_events( subscribers = list(subscriber_dict[stream.id]) stream_subscribers_dict[stream.id] = subscribers - setting_group_ids = set() - for sub_info in sub_info_list: - stream = sub_info.stream - for setting_name in Stream.stream_permission_group_settings: - setting_group_ids.add(getattr(stream, setting_name + "_id")) - - setting_groups_dict = get_setting_values_for_group_settings(list(setting_group_ids)) + streams = [sub_info.stream for sub_info in sub_info_list] + setting_groups_dict = get_group_setting_value_dict_for_streams(streams) for user_id, sub_infos in info_by_user.items(): sub_dicts: list[APISubscriptionDict] = [] @@ -460,12 +455,7 @@ def send_stream_creation_events_for_previously_inaccessible_streams( stream_ids = set(altered_user_dict.keys()) recent_traffic = get_streams_traffic(stream_ids, realm) - setting_group_ids = set() - for stream_id in stream_ids: - stream = stream_dict[stream_id] - for setting_name in Stream.stream_permission_group_settings: - setting_group_ids.add(getattr(stream, setting_name + "_id")) - + streams = [stream_dict[stream_id] for stream_id in stream_ids] setting_groups_dict: dict[int, int | AnonymousSettingGroupDict] | None = None for stream_id, stream_users_ids in altered_user_dict.items(): @@ -489,7 +479,7 @@ def send_stream_creation_events_for_previously_inaccessible_streams( if notify_user_ids: if setting_groups_dict is None: - setting_groups_dict = get_setting_values_for_group_settings(list(setting_group_ids)) + setting_groups_dict = get_group_setting_value_dict_for_streams(streams) send_stream_creation_event( realm, stream, notify_user_ids, recent_traffic, setting_groups_dict diff --git a/zerver/lib/streams.py b/zerver/lib/streams.py index 4c047fc5c6..9cf555c861 100644 --- a/zerver/lib/streams.py +++ b/zerver/lib/streams.py @@ -999,6 +999,17 @@ def get_streams_for_user( return list(streams) +def get_group_setting_value_dict_for_streams( + streams: list[Stream], +) -> dict[int, int | AnonymousSettingGroupDict]: + setting_group_ids = set() + for stream in streams: + for setting_name in Stream.stream_permission_group_settings: + setting_group_ids.add(getattr(stream, setting_name + "_id")) + + return get_setting_values_for_group_settings(list(setting_group_ids)) + + def get_setting_values_for_group_settings( group_ids: list[int], ) -> dict[int, int | AnonymousSettingGroupDict]: @@ -1056,12 +1067,7 @@ def do_get_streams( stream_ids = {stream.id for stream in streams} recent_traffic = get_streams_traffic(stream_ids, user_profile.realm) - setting_group_ids = set() - for stream in streams: - for setting_name in Stream.stream_permission_group_settings: - setting_group_ids.add(getattr(stream, setting_name + "_id")) - - setting_groups_dict = get_setting_values_for_group_settings(list(setting_group_ids)) + setting_groups_dict = get_group_setting_value_dict_for_streams(streams) stream_dicts = sorted( (stream_to_dict(stream, recent_traffic, setting_groups_dict) for stream in streams),