diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.py index bc36358acf..8d6032b251 100644 --- a/analytics/tests/test_counts.py +++ b/analytics/tests/test_counts.py @@ -175,16 +175,20 @@ class AnalyticsTestCase(ZulipTestCase): stream.save(update_fields=["recipient"]) return stream, recipient - def create_huddle_with_recipient(self, **kwargs: Any) -> tuple[DirectMessageGroup, Recipient]: + def create_direct_message_group_with_recipient( + self, **kwargs: Any + ) -> tuple[DirectMessageGroup, Recipient]: self.name_counter += 1 defaults = {"huddle_hash": f"hash{self.name_counter}"} for key, value in defaults.items(): kwargs[key] = kwargs.get(key, value) - huddle = DirectMessageGroup.objects.create(**kwargs) - recipient = Recipient.objects.create(type_id=huddle.id, type=Recipient.DIRECT_MESSAGE_GROUP) - huddle.recipient = recipient - huddle.save(update_fields=["recipient"]) - return huddle, recipient + direct_message_group = DirectMessageGroup.objects.create(**kwargs) + recipient = Recipient.objects.create( + type_id=direct_message_group.id, type=Recipient.DIRECT_MESSAGE_GROUP + ) + direct_message_group.recipient = recipient + direct_message_group.save(update_fields=["recipient"]) + return direct_message_group, recipient def create_message(self, sender: UserProfile, recipient: Recipient, **kwargs: Any) -> Message: defaults = { @@ -547,8 +551,8 @@ class TestCountStats(AnalyticsTestCase): self.create_user(realm=self.no_message_realm) self.create_stream_with_recipient(realm=self.no_message_realm) - # This huddle should not show up anywhere - self.create_huddle_with_recipient() + # This direct_message_group should not show up anywhere + self.create_direct_message_group_with_recipient() def test_upload_quota_used_bytes(self) -> None: stat = COUNT_STATS["upload_quota_used_bytes::day"] @@ -595,11 +599,11 @@ class TestCountStats(AnalyticsTestCase): recipient_human1 = Recipient.objects.get(type_id=human1.id, type=Recipient.PERSONAL) recipient_stream = self.create_stream_with_recipient()[1] - recipient_huddle = self.create_huddle_with_recipient()[1] + recipient_direct_message_group = self.create_direct_message_group_with_recipient()[1] self.create_message(bot, recipient_human1) self.create_message(bot, recipient_stream) - self.create_message(bot, recipient_huddle) + self.create_message(bot, recipient_direct_message_group) self.create_message(human1, recipient_human1) self.create_message(human2, recipient_human1) @@ -636,19 +640,19 @@ class TestCountStats(AnalyticsTestCase): recipient_human1 = Recipient.objects.get(type_id=human1.id, type=Recipient.PERSONAL) recipient_stream = self.create_stream_with_recipient()[1] - recipient_huddle = self.create_huddle_with_recipient()[1] + recipient_direct_message_group = self.create_direct_message_group_with_recipient()[1] # To be included self.create_message(bot, recipient_human1) self.create_message(bot, recipient_stream) - self.create_message(bot, recipient_huddle) + self.create_message(bot, recipient_direct_message_group) self.create_message(human1, recipient_human1) self.create_message(human2, recipient_human1) # To be excluded self.create_message(self.hourly_user, recipient_human1) self.create_message(self.hourly_user, recipient_stream) - self.create_message(self.hourly_user, recipient_huddle) + self.create_message(self.hourly_user, recipient_direct_message_group) do_fill_count_stat_at_hour(stat, self.TIME_ZERO, self.default_realm) @@ -692,11 +696,11 @@ class TestCountStats(AnalyticsTestCase): self.create_message(user1, recipient_stream4) self.create_message(user2, recipient_stream3) - # huddles - recipient_huddle1 = self.create_huddle_with_recipient()[1] - recipient_huddle2 = self.create_huddle_with_recipient()[1] - self.create_message(user1, recipient_huddle1) - self.create_message(user2, recipient_huddle2) + # direct message groups + recipient_direct_message_group1 = self.create_direct_message_group_with_recipient()[1] + recipient_direct_message_group2 = self.create_direct_message_group_with_recipient()[1] + self.create_message(user1, recipient_direct_message_group1) + self.create_message(user2, recipient_direct_message_group2) # direct messages recipient_user1 = Recipient.objects.get(type_id=user1.id, type=Recipient.PERSONAL) @@ -759,13 +763,13 @@ class TestCountStats(AnalyticsTestCase): user_recipient = Recipient.objects.get(type_id=user.id, type=Recipient.PERSONAL) private_stream_recipient = self.create_stream_with_recipient(invite_only=True)[1] stream_recipient = self.create_stream_with_recipient()[1] - huddle_recipient = self.create_huddle_with_recipient()[1] + direct_message_group_recipient = self.create_direct_message_group_with_recipient()[1] # To be included self.create_message(user, user_recipient) self.create_message(user, private_stream_recipient) self.create_message(user, stream_recipient) - self.create_message(user, huddle_recipient) + self.create_message(user, direct_message_group_recipient) do_fill_count_stat_at_hour(stat, self.TIME_ZERO, self.default_realm) @@ -773,7 +777,7 @@ class TestCountStats(AnalyticsTestCase): self.create_message(self.hourly_user, user_recipient) self.create_message(self.hourly_user, private_stream_recipient) self.create_message(self.hourly_user, stream_recipient) - self.create_message(self.hourly_user, huddle_recipient) + self.create_message(self.hourly_user, direct_message_group_recipient) self.assertTableState( UserCount, @@ -806,11 +810,11 @@ class TestCountStats(AnalyticsTestCase): user = self.create_user(id=1000) user_recipient = Recipient.objects.get(type_id=user.id, type=Recipient.PERSONAL) stream_recipient = self.create_stream_with_recipient(id=1000)[1] - huddle_recipient = self.create_huddle_with_recipient(id=1000)[1] + direct_message_group_recipient = self.create_direct_message_group_with_recipient(id=1000)[1] self.create_message(user, user_recipient) self.create_message(user, stream_recipient) - self.create_message(user, huddle_recipient) + self.create_message(user, direct_message_group_recipient) do_fill_count_stat_at_hour(stat, self.TIME_ZERO) @@ -827,13 +831,13 @@ class TestCountStats(AnalyticsTestCase): recipient_user2 = Recipient.objects.get(type_id=user2.id, type=Recipient.PERSONAL) recipient_stream = self.create_stream_with_recipient()[1] - recipient_huddle = self.create_huddle_with_recipient()[1] + recipient_direct_message_group = self.create_direct_message_group_with_recipient()[1] client2 = Client.objects.create(name="client2") self.create_message(user1, recipient_user2, sending_client=client2) self.create_message(user1, recipient_stream) - self.create_message(user1, recipient_huddle) + self.create_message(user1, recipient_direct_message_group) self.create_message(user2, recipient_user2, sending_client=client2) self.create_message(user2, recipient_user2, sending_client=client2) @@ -923,8 +927,8 @@ class TestCountStats(AnalyticsTestCase): # To be excluded self.create_message(human2, recipient_human1) self.create_message(bot, recipient_human1) - recipient_huddle = self.create_huddle_with_recipient()[1] - self.create_message(human1, recipient_huddle) + recipient_direct_message_group = self.create_direct_message_group_with_recipient()[1] + self.create_message(human1, recipient_direct_message_group) do_fill_count_stat_at_hour(stat, self.TIME_ZERO) diff --git a/tools/rebuild-test-database b/tools/rebuild-test-database index 70ca2550a2..a445751601 100755 --- a/tools/rebuild-test-database +++ b/tools/rebuild-test-database @@ -33,7 +33,7 @@ create_zulip_test # This next line can be simplified to "-n0" once we fix our app (and tests) with 0 messages. ./manage.py populate_db --test-suite -n30 --threads=1 \ --max-topics=3 \ - --huddles=0 --personals=0 --percent-huddles=0 --percent-personals=0 + --direct-message-groups=0 --personals=0 --percent-direct-message-groups=0 --percent-personals=0 ./manage.py dumpdata \ zerver.UserProfile zerver.Stream zerver.Recipient \ diff --git a/zerver/actions/users.py b/zerver/actions/users.py index faee21b25a..61ed0fc8c9 100644 --- a/zerver/actions/users.py +++ b/zerver/actions/users.py @@ -62,7 +62,7 @@ def do_delete_user(user_profile: UserProfile, *, acting_user: UserProfile | None do_deactivate_user(user_profile, acting_user=acting_user) - subscribed_huddle_recipient_ids = set( + to_resubscribe_recipient_ids = set( Subscription.objects.filter( user_profile=user_profile, recipient__type=Recipient.DIRECT_MESSAGE_GROUP ).values_list("recipient_id", flat=True) @@ -97,7 +97,7 @@ def do_delete_user(user_profile: UserProfile, *, acting_user: UserProfile | None recipient=recipient, is_user_active=replacement_user.is_active, ) - for recipient in Recipient.objects.filter(id__in=subscribed_huddle_recipient_ids) + for recipient in Recipient.objects.filter(id__in=to_resubscribe_recipient_ids) ] Subscription.objects.bulk_create(subs_to_recreate) @@ -271,8 +271,8 @@ def send_events_for_user_deactivation(user_profile: UserProfile) -> None: # This code path is parallel to # get_subscribers_of_target_user_subscriptions, but can't reuse it - # because we need to process stream and huddle subscriptions - # separately. + # because we need to process stream and direct_message_group + # subscriptions separately. deactivated_user_subs = Subscription.objects.filter( user_profile=user_profile, recipient__type__in=[Recipient.STREAM, Recipient.DIRECT_MESSAGE_GROUP], @@ -285,18 +285,18 @@ def send_events_for_user_deactivation(user_profile: UserProfile) -> None: active=True, ).values_list("recipient__type", "user_profile_id") - subscribers_in_deactivated_user_streams = set() - subscribers_in_deactivated_user_huddles = set() + peer_stream_subscribers = set() + peer_direct_message_group_subscribers = set() for recipient_type, user_id in subscribers_in_deactivated_user_subs: if recipient_type == Recipient.DIRECT_MESSAGE_GROUP: - subscribers_in_deactivated_user_huddles.add(user_id) + peer_direct_message_group_subscribers.add(user_id) else: - subscribers_in_deactivated_user_streams.add(user_id) + peer_stream_subscribers.add(user_id) users_with_access_to_deactivated_user = ( set(non_guest_user_ids) | users_involved_in_dms_dict[user_profile.id] - | subscribers_in_deactivated_user_huddles + | peer_direct_message_group_subscribers ) if users_with_access_to_deactivated_user: send_event_on_commit( @@ -304,7 +304,7 @@ def send_events_for_user_deactivation(user_profile: UserProfile) -> None: ) users_losing_access_to_deactivated_user = ( - subscribers_in_deactivated_user_streams - users_with_access_to_deactivated_user + peer_stream_subscribers - users_with_access_to_deactivated_user ) if users_losing_access_to_deactivated_user: event_remove_user = dict( diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py index 81386b2730..0ce2fbaa73 100644 --- a/zerver/data_import/mattermost.py +++ b/zerver/data_import/mattermost.py @@ -235,7 +235,7 @@ def convert_direct_message_group_data( direct_message_group_data: list[ZerverFieldsT], user_data_map: dict[str, dict[str, Any]], subscriber_handler: SubscriberHandler, - huddle_id_mapper: IdMapper[frozenset[str]], + direct_message_group_id_mapper: IdMapper[frozenset[str]], user_id_mapper: IdMapper[str], realm_id: int, team_name: str, @@ -244,7 +244,9 @@ def convert_direct_message_group_data( for direct_message_group in direct_message_group_data: if len(direct_message_group["members"]) > 2: direct_message_group_members = frozenset(direct_message_group["members"]) - direct_message_group_id = huddle_id_mapper.get(direct_message_group_members) + direct_message_group_id = direct_message_group_id_mapper.get( + direct_message_group_members + ) direct_message_group_dict = build_direct_message_group(direct_message_group_id) direct_message_group_user_ids = { user_id_mapper.get(username) for username in direct_message_group["members"] @@ -653,7 +655,7 @@ def write_message_data( output_dir: str, masking_content: bool, stream_id_mapper: IdMapper[str], - huddle_id_mapper: IdMapper[frozenset[str]], + direct_message_group_id_mapper: IdMapper[frozenset[str]], user_id_mapper: IdMapper[str], user_handler: UserHandler, zerver_realmemoji: list[dict[str, Any]], @@ -663,14 +665,14 @@ def write_message_data( mattermost_data_dir: str, ) -> None: stream_id_to_recipient_id = {} - huddle_id_to_recipient_id = {} + direct_message_group_id_to_recipient_id = {} user_id_to_recipient_id = {} for d in zerver_recipient: if d["type"] == Recipient.STREAM: stream_id_to_recipient_id[d["type_id"]] = d["id"] elif d["type"] == Recipient.DIRECT_MESSAGE_GROUP: - huddle_id_to_recipient_id[d["type_id"]] = d["id"] + direct_message_group_id_to_recipient_id[d["type_id"]] = d["id"] if d["type"] == Recipient.PERSONAL: user_id_to_recipient_id[d["type_id"]] = d["id"] @@ -681,8 +683,8 @@ def write_message_data( def get_recipient_id_from_direct_message_group_members( direct_message_group_members: frozenset[str], ) -> int: - receiver_id = huddle_id_mapper.get(direct_message_group_members) - return huddle_id_to_recipient_id[receiver_id] + receiver_id = direct_message_group_id_mapper.get(direct_message_group_members) + return direct_message_group_id_to_recipient_id[receiver_id] def get_recipient_id_from_username(username: str) -> int: receiver_id = user_id_mapper.get(username) @@ -892,7 +894,7 @@ def do_convert_data(mattermost_data_dir: str, output_dir: str, masking_content: subscriber_handler = SubscriberHandler() user_id_mapper = IdMapper[str]() stream_id_mapper = IdMapper[str]() - huddle_id_mapper = IdMapper[frozenset[str]]() + direct_message_group_id_mapper = IdMapper[frozenset[str]]() print("Generating data for", team_name) realm = make_realm(realm_id, team) @@ -928,7 +930,7 @@ def do_convert_data(mattermost_data_dir: str, output_dir: str, masking_content: direct_message_group_data=mattermost_data["direct_channel"], user_data_map=username_to_user, subscriber_handler=subscriber_handler, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, realm_id=realm_id, team_name=team_name, @@ -993,7 +995,7 @@ def do_convert_data(mattermost_data_dir: str, output_dir: str, masking_content: output_dir=realm_output_dir, masking_content=masking_content, stream_id_mapper=stream_id_mapper, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, user_handler=user_handler, zerver_realmemoji=zerver_realmemoji, diff --git a/zerver/data_import/rocketchat.py b/zerver/data_import/rocketchat.py index 5b287f8bc5..9ab66cfd65 100644 --- a/zerver/data_import/rocketchat.py +++ b/zerver/data_import/rocketchat.py @@ -238,19 +238,21 @@ def convert_stream_subscription_data( def convert_direct_message_group_data( - huddle_id_to_huddle_map: dict[str, dict[str, Any]], - huddle_id_mapper: IdMapper[str], + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]], + direct_message_group_id_mapper: IdMapper[str], user_id_mapper: IdMapper[str], subscriber_handler: SubscriberHandler, ) -> list[ZerverFieldsT]: zerver_direct_message_group: list[ZerverFieldsT] = [] - for rc_huddle_id in huddle_id_to_huddle_map: - direct_message_group_id = huddle_id_mapper.get(rc_huddle_id) + for rc_direct_message_group_id in direct_message_group_id_to_direct_message_group_map: + direct_message_group_id = direct_message_group_id_mapper.get(rc_direct_message_group_id) direct_message_group = build_direct_message_group(direct_message_group_id) zerver_direct_message_group.append(direct_message_group) - direct_message_group_dict = huddle_id_to_huddle_map[rc_huddle_id] + direct_message_group_dict = direct_message_group_id_to_direct_message_group_map[ + rc_direct_message_group_id + ] direct_message_group_user_ids = { user_id_mapper.get(rc_user_id) for rc_user_id in direct_message_group_dict["uids"] } @@ -613,13 +615,13 @@ def process_messages( user_id_to_recipient_id: dict[int, int], stream_id_mapper: IdMapper[str], stream_id_to_recipient_id: dict[int, int], - huddle_id_mapper: IdMapper[str], - huddle_id_to_recipient_id: dict[int, int], + direct_message_group_id_mapper: IdMapper[str], + direct_message_group_id_to_recipient_id: dict[int, int], thread_id_mapper: IdMapper[str], room_id_to_room_map: dict[str, dict[str, Any]], dsc_id_to_dsc_map: dict[str, dict[str, Any]], direct_id_to_direct_map: dict[str, dict[str, Any]], - huddle_id_to_huddle_map: dict[str, dict[str, Any]], + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]], zerver_realmemoji: list[ZerverFieldsT], total_reactions: list[ZerverFieldsT], uploads_list: list[ZerverFieldsT], @@ -677,9 +679,11 @@ def process_messages( if is_pm_data: # Message is in a 1:1 or group direct message. rc_channel_id = message["rid"] - if rc_channel_id in huddle_id_to_huddle_map: - direct_message_group_id = huddle_id_mapper.get(rc_channel_id) - message_dict["recipient_id"] = huddle_id_to_recipient_id[direct_message_group_id] + if rc_channel_id in direct_message_group_id_to_direct_message_group_map: + direct_message_group_id = direct_message_group_id_mapper.get(rc_channel_id) + message_dict["recipient_id"] = direct_message_group_id_to_recipient_id[ + direct_message_group_id + ] else: rc_member_ids = direct_id_to_direct_map[rc_channel_id]["uids"] @@ -748,7 +752,7 @@ def process_messages( parent_channel_id = dsc_channel["prid"] if ( parent_channel_id in direct_id_to_direct_map - or parent_channel_id in huddle_id_to_huddle_map + or parent_channel_id in direct_message_group_id_to_direct_message_group_map ): # Discussion belongs to a direct channel and thus, should not be # linked. @@ -842,13 +846,16 @@ def separate_channel_private_and_livechat_messages( messages: list[dict[str, Any]], dsc_id_to_dsc_map: dict[str, dict[str, Any]], direct_id_to_direct_map: dict[str, dict[str, Any]], - huddle_id_to_huddle_map: dict[str, dict[str, Any]], + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]], livechat_id_to_livechat_map: dict[str, dict[str, Any]], channel_messages: list[dict[str, Any]], private_messages: list[dict[str, Any]], livechat_messages: list[dict[str, Any]], ) -> None: - private_channels_list = [*direct_id_to_direct_map, *huddle_id_to_huddle_map] + private_channels_list = [ + *direct_id_to_direct_map, + *direct_message_group_id_to_direct_message_group_map, + ] for message in messages: if not message.get("rid"): # Message does not belong to any channel (might be @@ -872,7 +879,7 @@ def separate_channel_private_and_livechat_messages( def map_receiver_id_to_recipient_id( zerver_recipient: list[ZerverFieldsT], stream_id_to_recipient_id: dict[int, int], - huddle_id_to_recipient_id: dict[int, int], + direct_message_group_id_to_recipient_id: dict[int, int], user_id_to_recipient_id: dict[int, int], ) -> None: # receiver_id represents stream_id/direct_message_group_id/user_id @@ -880,7 +887,7 @@ def map_receiver_id_to_recipient_id( if recipient["type"] == Recipient.STREAM: stream_id_to_recipient_id[recipient["type_id"]] = recipient["id"] elif recipient["type"] == Recipient.DIRECT_MESSAGE_GROUP: - huddle_id_to_recipient_id[recipient["type_id"]] = recipient["id"] + direct_message_group_id_to_recipient_id[recipient["type_id"]] = recipient["id"] elif recipient["type"] == Recipient.PERSONAL: user_id_to_recipient_id[recipient["type_id"]] = recipient["id"] @@ -891,7 +898,7 @@ def categorize_channels_and_map_with_id( team_id_to_team_map: dict[str, dict[str, Any]], dsc_id_to_dsc_map: dict[str, dict[str, Any]], direct_id_to_direct_map: dict[str, dict[str, Any]], - huddle_id_to_huddle_map: dict[str, dict[str, Any]], + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]], livechat_id_to_livechat_map: dict[str, dict[str, Any]], ) -> None: direct_message_group_hashed_channels: dict[frozenset[str], Any] = {} @@ -901,16 +908,16 @@ def categorize_channels_and_map_with_id( elif channel["t"] == "d": if len(channel["uids"]) > 2: direct_message_group_members = frozenset(channel["uids"]) - logging.info("Huddle channel found. UIDs: %r", channel["uids"]) + logging.info("Direct message group channel found. UIDs: %r", channel["uids"]) if channel["msgs"] == 0: # nocoverage # Rocket.Chat exports in the wild sometimes - # contain duplicates of real huddles, with no - # messages in the duplicate. We ignore these - # minor database corruptions in the Rocket.Chat - # export. Doing so is safe, because a direct - # message group with no message history has no - # value in Zulip's data model. + # contain duplicates of real direct message + # groups, with no messages in the duplicate. + # We ignore these minor database corruptions + # in the Rocket.Chat export. Doing so is safe, + # because a direct message group with no message + # history has no value in Zulip's data model. logging.debug("Skipping direct message group with 0 messages: %s", channel) elif ( direct_message_group_members in direct_message_group_hashed_channels @@ -920,9 +927,9 @@ def categorize_channels_and_map_with_id( direct_message_group_members, direct_message_group_hashed_channels[direct_message_group_members], ) - huddle_id_to_huddle_map[channel["_id"]] = direct_message_group_hashed_channels[ - direct_message_group_members - ] + direct_message_group_id_to_direct_message_group_map[channel["_id"]] = ( + direct_message_group_hashed_channels[direct_message_group_members] + ) # Ideally, we'd merge the duplicate direct message # groups. Doing so correctly requires special @@ -930,15 +937,15 @@ def categorize_channels_and_map_with_id( # and on the message import side as well, since # those appear to be mapped via rocketchat channel # IDs and not all of that information is resolved - # via the huddle_id_to_huddle_map. + # via the direct_message_group_id_to_direct_message_group_map. # # For now, just throw an exception here rather # than during the import process. raise NotImplementedError( - "Mapping multiple huddles with messages to one is not fully implemented yet" + "Mapping multiple direct message groups with messages to one is not fully implemented yet" ) else: - huddle_id_to_huddle_map[channel["_id"]] = channel + direct_message_group_id_to_direct_message_group_map[channel["_id"]] = channel direct_message_group_hashed_channels[direct_message_group_members] = channel else: direct_id_to_direct_map[channel["_id"]] = channel @@ -1054,7 +1061,7 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: subscriber_handler = SubscriberHandler() user_id_mapper = IdMapper[str]() stream_id_mapper = IdMapper[str]() - huddle_id_mapper = IdMapper[str]() + direct_message_group_id_mapper = IdMapper[str]() thread_id_mapper = IdMapper[str]() process_users( @@ -1069,7 +1076,7 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} categorize_channels_and_map_with_id( @@ -1078,7 +1085,7 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -1101,8 +1108,8 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: ) zerver_direct_message_group = convert_direct_message_group_data( - huddle_id_to_huddle_map=huddle_id_to_huddle_map, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, subscriber_handler=subscriber_handler, ) @@ -1150,13 +1157,13 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: ) stream_id_to_recipient_id: dict[int, int] = {} - huddle_id_to_recipient_id: dict[int, int] = {} + direct_message_group_id_to_recipient_id: dict[int, int] = {} user_id_to_recipient_id: dict[int, int] = {} map_receiver_id_to_recipient_id( zerver_recipient=zerver_recipient, stream_id_to_recipient_id=stream_id_to_recipient_id, - huddle_id_to_recipient_id=huddle_id_to_recipient_id, + direct_message_group_id_to_recipient_id=direct_message_group_id_to_recipient_id, user_id_to_recipient_id=user_id_to_recipient_id, ) @@ -1168,7 +1175,7 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: messages=rocketchat_data["message"], dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, channel_messages=channel_messages, private_messages=private_messages, @@ -1193,13 +1200,13 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: user_id_to_recipient_id=user_id_to_recipient_id, stream_id_mapper=stream_id_mapper, stream_id_to_recipient_id=stream_id_to_recipient_id, - huddle_id_mapper=huddle_id_mapper, - huddle_id_to_recipient_id=huddle_id_to_recipient_id, + direct_message_group_id_mapper=direct_message_group_id_mapper, + direct_message_group_id_to_recipient_id=direct_message_group_id_to_recipient_id, thread_id_mapper=thread_id_mapper, room_id_to_room_map=room_id_to_room_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, zerver_realmemoji=zerver_realmemoji, total_reactions=total_reactions, uploads_list=uploads_list, @@ -1219,13 +1226,13 @@ def do_convert_data(rocketchat_data_dir: str, output_dir: str) -> None: user_id_to_recipient_id=user_id_to_recipient_id, stream_id_mapper=stream_id_mapper, stream_id_to_recipient_id=stream_id_to_recipient_id, - huddle_id_mapper=huddle_id_mapper, - huddle_id_to_recipient_id=huddle_id_to_recipient_id, + direct_message_group_id_mapper=direct_message_group_id_mapper, + direct_message_group_id_to_recipient_id=direct_message_group_id_to_recipient_id, thread_id_mapper=thread_id_mapper, room_id_to_room_map=room_id_to_room_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, zerver_realmemoji=zerver_realmemoji, total_reactions=total_reactions, uploads_list=uploads_list, diff --git a/zerver/lib/display_recipient.py b/zerver/lib/display_recipient.py index a72fba4aec..8e99477b84 100644 --- a/zerver/lib/display_recipient.py +++ b/zerver/lib/display_recipient.py @@ -151,7 +151,7 @@ def bulk_fetch_user_display_recipients( direct_message_group_recipient_ids = [ get_recipient_id(tup) for tup in direct_message_group_tuples ] - huddle_recipient_id_to_user_ids = bulk_get_direct_message_group_user_ids( + user_ids_in_direct_message_groups = bulk_get_direct_message_group_user_ids( direct_message_group_recipient_ids ) @@ -161,7 +161,7 @@ def bulk_fetch_user_display_recipients( } for recipient_id in direct_message_group_recipient_ids: - direct_message_group_user_ids = huddle_recipient_id_to_user_ids[recipient_id] + direct_message_group_user_ids = user_ids_in_direct_message_groups[recipient_id] user_ids_to_fetch |= direct_message_group_user_ids # Fetch the needed user dictionaries. @@ -174,7 +174,7 @@ def bulk_fetch_user_display_recipients( result[recipient_id] = display_recipients for recipient_id in direct_message_group_recipient_ids: - user_ids = sorted(huddle_recipient_id_to_user_ids[recipient_id]) + user_ids = sorted(user_ids_in_direct_message_groups[recipient_id]) display_recipients = [user_display_recipients[user_id] for user_id in user_ids] result[recipient_id] = display_recipients diff --git a/zerver/lib/export.py b/zerver/lib/export.py index db27fb193d..dd4a9188c6 100644 --- a/zerver/lib/export.py +++ b/zerver/lib/export.py @@ -1134,39 +1134,48 @@ def custom_fetch_direct_message_groups(response: TableData, context: Context) -> r["id"] for r in response["zerver_userprofile"] + response["zerver_userprofile_mirrordummy"] } - # First we get all huddles involving someone in the realm. - realm_huddle_subs = Subscription.objects.select_related("recipient").filter( + # First we get all direct message groups involving someone in the realm. + realm_direct_message_group_subs = Subscription.objects.select_related("recipient").filter( recipient__type=Recipient.DIRECT_MESSAGE_GROUP, user_profile__in=user_profile_ids ) - realm_huddle_recipient_ids = {sub.recipient_id for sub in realm_huddle_subs} + realm_direct_message_group_recipient_ids = { + sub.recipient_id for sub in realm_direct_message_group_subs + } # Mark all Direct Message groups whose recipient ID contains a cross-realm user. - unsafe_huddle_recipient_ids = set() + unsafe_direct_message_group_recipient_ids = set() for sub in Subscription.objects.select_related("user_profile").filter( - recipient__in=realm_huddle_recipient_ids + recipient__in=realm_direct_message_group_recipient_ids ): if sub.user_profile.realm_id != realm.id: # In almost every case the other realm will be zulip.com - unsafe_huddle_recipient_ids.add(sub.recipient_id) + unsafe_direct_message_group_recipient_ids.add(sub.recipient_id) - # Now filter down to just those huddles that are entirely within the realm. + # Now filter down to just those direct message groups that are + # entirely within the realm. # # This is important for ensuring that the User objects needed # to import it on the other end exist (since we're only # exporting the users from this realm), at the cost of losing # some of these cross-realm messages. - huddle_subs = [ - sub for sub in realm_huddle_subs if sub.recipient_id not in unsafe_huddle_recipient_ids + direct_message_group_subs = [ + sub + for sub in realm_direct_message_group_subs + if sub.recipient_id not in unsafe_direct_message_group_recipient_ids ] - huddle_recipient_ids = {sub.recipient_id for sub in huddle_subs} - huddle_ids = {sub.recipient.type_id for sub in huddle_subs} + direct_message_group_recipient_ids = {sub.recipient_id for sub in direct_message_group_subs} + direct_message_group_ids = {sub.recipient.type_id for sub in direct_message_group_subs} - huddle_subscription_dicts = make_raw(huddle_subs) - huddle_recipients = make_raw(Recipient.objects.filter(id__in=huddle_recipient_ids)) + direct_message_group_subscription_dicts = make_raw(direct_message_group_subs) + direct_message_group_recipients = make_raw( + Recipient.objects.filter(id__in=direct_message_group_recipient_ids) + ) - response["_huddle_recipient"] = huddle_recipients - response["_huddle_subscription"] = huddle_subscription_dicts - response["zerver_huddle"] = make_raw(DirectMessageGroup.objects.filter(id__in=huddle_ids)) + response["_huddle_recipient"] = direct_message_group_recipients + response["_huddle_subscription"] = direct_message_group_subscription_dicts + response["zerver_huddle"] = make_raw( + DirectMessageGroup.objects.filter(id__in=direct_message_group_ids) + ) def custom_fetch_scheduled_messages(response: TableData, context: Context) -> None: diff --git a/zerver/lib/narrow.py b/zerver/lib/narrow.py index 80e12f7f4a..49f89aae06 100644 --- a/zerver/lib/narrow.py +++ b/zerver/lib/narrow.py @@ -605,7 +605,7 @@ class NarrowBuilder: except (JsonableError, ValidationError): raise BadNarrowOperatorError("unknown user in " + str(operand)) except DirectMessageGroup.DoesNotExist: - # Group DM where huddle doesn't exist + # Group DM where direct message group doesn't exist return query.where(maybe_negate(false())) # Group direct message diff --git a/zerver/lib/users.py b/zerver/lib/users.py index aed8001434..3b00d4187f 100644 --- a/zerver/lib/users.py +++ b/zerver/lib/users.py @@ -719,7 +719,7 @@ def get_user_ids_who_can_access_user(target_user: UserProfile) -> list[int]: def get_subscribers_of_target_user_subscriptions( - target_users: list[UserProfile], include_deactivated_users_for_huddles: bool = False + target_users: list[UserProfile], include_deactivated_users_for_dm_groups: bool = False ) -> dict[int, set[int]]: target_user_ids = [user.id for user in target_users] target_user_subscriptions = ( @@ -747,7 +747,7 @@ def get_subscribers_of_target_user_subscriptions( active=True, ) - if include_deactivated_users_for_huddles: + if include_deactivated_users_for_dm_groups: subs_in_target_user_subscriptions_query = subs_in_target_user_subscriptions_query.filter( Q(recipient__type=Recipient.STREAM, is_user_active=True) | Q(recipient__type=Recipient.DIRECT_MESSAGE_GROUP) @@ -916,7 +916,7 @@ def get_accessible_user_ids( realm: Realm, user_profile: UserProfile, include_deactivated_users: bool = False ) -> list[int]: subscribers_dict_of_target_user_subscriptions = get_subscribers_of_target_user_subscriptions( - [user_profile], include_deactivated_users_for_huddles=include_deactivated_users + [user_profile], include_deactivated_users_for_dm_groups=include_deactivated_users ) users_involved_in_dms_dict = get_users_involved_in_dms_with_target_users( [user_profile], realm, include_deactivated_users=include_deactivated_users diff --git a/zerver/models/messages.py b/zerver/models/messages.py index 6bfe69cfa1..65cc5ea9b3 100644 --- a/zerver/models/messages.py +++ b/zerver/models/messages.py @@ -150,7 +150,7 @@ class Message(AbstractMessage): # A detail worth noting: # * "direct" was introduced in 2023 with the goal of # deprecating the original "private" and becoming the - # preferred way to indicate a personal or huddle + # preferred way to indicate a personal or direct_message_group # Recipient type via the API. API_RECIPIENT_TYPES = ["direct", "private", "stream", "channel"] diff --git a/zerver/models/recipients.py b/zerver/models/recipients.py index b7546122fb..85b89e59ee 100644 --- a/zerver/models/recipients.py +++ b/zerver/models/recipients.py @@ -43,7 +43,7 @@ class Recipient(models.Model): id = models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID") type_id = models.IntegerField(db_index=True) type = models.PositiveSmallIntegerField(db_index=True) - # Valid types are {personal, stream, huddle} + # Valid types are {personal, stream, direct_message_group} # The type for 1:1 direct messages. PERSONAL = 1 @@ -56,7 +56,11 @@ class Recipient(models.Model): unique_together = ("type", "type_id") # N.B. If we used Django's choice=... we would get this for free (kinda) - _type_names = {PERSONAL: "personal", STREAM: "stream", DIRECT_MESSAGE_GROUP: "huddle"} + _type_names = { + PERSONAL: "personal", + STREAM: "stream", + DIRECT_MESSAGE_GROUP: "direct_message_group", + } @override def __str__(self) -> str: @@ -91,12 +95,13 @@ def get_direct_message_group_user_ids(recipient: Recipient) -> ValuesQuerySet["S def bulk_get_direct_message_group_user_ids(recipient_ids: list[int]) -> dict[int, set[int]]: """ - Takes a list of huddle-type recipient_ids, returns a dict - mapping recipient id to list of user ids in the huddle. + Takes a list of direct_message_group type recipient_ids, returns + a dictmapping recipient id to list of user ids in the direct + message group. We rely on our caller to pass us recipient_ids that correspond - to huddles, but technically this function is valid for any type - of subscription. + to direct_message_group, but technically this function is valid + for any typeof subscription. """ from zerver.models import Subscription diff --git a/zerver/models/scheduled_jobs.py b/zerver/models/scheduled_jobs.py index db42bdba27..97e8c2b0ce 100644 --- a/zerver/models/scheduled_jobs.py +++ b/zerver/models/scheduled_jobs.py @@ -72,7 +72,7 @@ class MissedMessageEmailAddress(models.Model): class NotificationTriggers: - # "direct_message" is for 1:1 direct messages as well as huddles + # "direct_message" is for 1:1 and group direct messages DIRECT_MESSAGE = "direct_message" MENTION = "mentioned" TOPIC_WILDCARD_MENTION = "topic_wildcard_mentioned" diff --git a/zerver/tests/test_mattermost_importer.py b/zerver/tests/test_mattermost_importer.py index ddfe39e6e9..ab0dbb4644 100644 --- a/zerver/tests/test_mattermost_importer.py +++ b/zerver/tests/test_mattermost_importer.py @@ -345,7 +345,7 @@ class MatterMostImporter(ZulipTestCase): user_handler = UserHandler() subscriber_handler = SubscriberHandler() - huddle_id_mapper = IdMapper[frozenset[str]]() + direct_message_group_id_mapper = IdMapper[frozenset[str]]() user_id_mapper = IdMapper[str]() team_name = "gryffindor" @@ -361,7 +361,7 @@ class MatterMostImporter(ZulipTestCase): direct_message_group_data=mattermost_data["direct_channel"], user_data_map=username_to_user, subscriber_handler=subscriber_handler, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, realm_id=3, team_name=team_name, @@ -370,10 +370,12 @@ class MatterMostImporter(ZulipTestCase): self.assert_length(zerver_huddle, 1) direct_message_group_members = frozenset(mattermost_data["direct_channel"][1]["members"]) - self.assertTrue(huddle_id_mapper.has(direct_message_group_members)) + self.assertTrue(direct_message_group_id_mapper.has(direct_message_group_members)) self.assertEqual( subscriber_handler.get_users( - direct_message_group_id=huddle_id_mapper.get(direct_message_group_members) + direct_message_group_id=direct_message_group_id_mapper.get( + direct_message_group_members + ) ), {1, 2, 3}, ) diff --git a/zerver/tests/test_rocketchat_importer.py b/zerver/tests/test_rocketchat_importer.py index 26533d9901..b943249603 100644 --- a/zerver/tests/test_rocketchat_importer.py +++ b/zerver/tests/test_rocketchat_importer.py @@ -188,7 +188,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -198,7 +198,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -208,7 +208,7 @@ class RocketChatImporter(ZulipTestCase): self.assert_length(team_id_to_team_map, 1) self.assert_length(dsc_id_to_dsc_map, 5) self.assert_length(direct_id_to_direct_map, 2) - self.assert_length(huddle_id_to_huddle_map, 1) + self.assert_length(direct_message_group_id_to_direct_message_group_map, 1) self.assert_length(livechat_id_to_livechat_map, 2) room_id = rocketchat_data["room"][0]["_id"] @@ -228,9 +228,10 @@ class RocketChatImporter(ZulipTestCase): self.assertEqual(direct_id_to_direct_map[direct_id], rocketchat_data["room"][4]) direct_message_group_id = rocketchat_data["room"][12]["_id"] - self.assertIn(direct_message_group_id, huddle_id_to_huddle_map) + self.assertIn(direct_message_group_id, direct_message_group_id_to_direct_message_group_map) self.assertEqual( - huddle_id_to_huddle_map[direct_message_group_id], rocketchat_data["room"][12] + direct_message_group_id_to_direct_message_group_map[direct_message_group_id], + rocketchat_data["room"][12], ) livechat_id = rocketchat_data["room"][14]["_id"] @@ -248,7 +249,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -258,7 +259,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -333,7 +334,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -343,7 +344,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -424,7 +425,7 @@ class RocketChatImporter(ZulipTestCase): user_handler = UserHandler() subscriber_handler = SubscriberHandler() user_id_mapper = IdMapper[str]() - huddle_id_mapper = IdMapper[str]() + direct_message_group_id_mapper = IdMapper[str]() user_id_to_user_map = map_user_id_to_user(rocketchat_data["user"]) @@ -440,7 +441,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -450,23 +451,23 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) zerver_direct_message_group = convert_direct_message_group_data( - huddle_id_to_huddle_map=huddle_id_to_huddle_map, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, subscriber_handler=subscriber_handler, ) self.assert_length(zerver_direct_message_group, 1) - rc_huddle_id = rocketchat_data["room"][12]["_id"] - self.assertTrue(huddle_id_mapper.has(rc_huddle_id)) + rc_direct_message_group_id = rocketchat_data["room"][12]["_id"] + self.assertTrue(direct_message_group_id_mapper.has(rc_direct_message_group_id)) - direct_message_group_id = huddle_id_mapper.get(rc_huddle_id) + direct_message_group_id = direct_message_group_id_mapper.get(rc_direct_message_group_id) self.assertEqual( subscriber_handler.get_users(direct_message_group_id=direct_message_group_id), {3, 4, 5} ) @@ -527,7 +528,7 @@ class RocketChatImporter(ZulipTestCase): subscriber_handler = SubscriberHandler() user_id_mapper = IdMapper[str]() stream_id_mapper = IdMapper[str]() - huddle_id_mapper = IdMapper[str]() + direct_message_group_id_mapper = IdMapper[str]() user_id_to_user_map = map_user_id_to_user(rocketchat_data["user"]) @@ -543,7 +544,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -553,7 +554,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -565,8 +566,8 @@ class RocketChatImporter(ZulipTestCase): ) zerver_direct_message_group = convert_direct_message_group_data( - huddle_id_to_huddle_map=huddle_id_to_huddle_map, - huddle_id_mapper=huddle_id_mapper, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, + direct_message_group_id_mapper=direct_message_group_id_mapper, user_id_mapper=user_id_mapper, subscriber_handler=subscriber_handler, ) @@ -581,20 +582,20 @@ class RocketChatImporter(ZulipTestCase): stream_id_to_recipient_id: dict[int, int] = {} user_id_to_recipient_id: dict[int, int] = {} - huddle_id_to_recipient_id: dict[int, int] = {} + direct_message_group_id_to_recipient_id: dict[int, int] = {} map_receiver_id_to_recipient_id( zerver_recipient=zerver_recipient, stream_id_to_recipient_id=stream_id_to_recipient_id, user_id_to_recipient_id=user_id_to_recipient_id, - huddle_id_to_recipient_id=huddle_id_to_recipient_id, + direct_message_group_id_to_recipient_id=direct_message_group_id_to_recipient_id, ) # 6 for streams and 6 for users. self.assert_length(zerver_recipient, 13) self.assert_length(stream_id_to_recipient_id, 6) self.assert_length(user_id_to_recipient_id, 6) - self.assert_length(huddle_id_to_recipient_id, 1) + self.assert_length(direct_message_group_id_to_recipient_id, 1) # First user recipients are built, followed by stream recipients in `build_recipients`. self.assertEqual( @@ -612,7 +613,8 @@ class RocketChatImporter(ZulipTestCase): ) self.assertEqual( - huddle_id_to_recipient_id[zerver_recipient[12]["type_id"]], zerver_recipient[12]["id"] + direct_message_group_id_to_recipient_id[zerver_recipient[12]["type_id"]], + zerver_recipient[12]["id"], ) def test_separate_channel_private_and_livechat_messages(self) -> None: @@ -623,7 +625,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map: dict[str, dict[str, Any]] = {} dsc_id_to_dsc_map: dict[str, dict[str, Any]] = {} direct_id_to_direct_map: dict[str, dict[str, Any]] = {} - huddle_id_to_huddle_map: dict[str, dict[str, Any]] = {} + direct_message_group_id_to_direct_message_group_map: dict[str, dict[str, Any]] = {} livechat_id_to_livechat_map: dict[str, dict[str, Any]] = {} with self.assertLogs(level="INFO"): @@ -633,7 +635,7 @@ class RocketChatImporter(ZulipTestCase): team_id_to_team_map=team_id_to_team_map, dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, ) @@ -645,7 +647,7 @@ class RocketChatImporter(ZulipTestCase): messages=rocketchat_data["message"], dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, channel_messages=channel_messages, private_messages=private_messages, @@ -705,7 +707,7 @@ class RocketChatImporter(ZulipTestCase): messages=rocketchat_data["message"], dsc_id_to_dsc_map=dsc_id_to_dsc_map, direct_id_to_direct_map=direct_id_to_direct_map, - huddle_id_to_huddle_map=huddle_id_to_huddle_map, + direct_message_group_id_to_direct_message_group_map=direct_message_group_id_to_direct_message_group_map, livechat_id_to_livechat_map=livechat_id_to_livechat_map, channel_messages=channel_messages, private_messages=private_messages, @@ -890,7 +892,7 @@ class RocketChatImporter(ZulipTestCase): self.assertEqual( info_log.output, [ - "INFO:root:Huddle channel found. UIDs: ['LdBZ7kPxtKESyHPEe', 'M2sXGqoQRJQwQoXY2', 'os6N2Xg2JkNMCSW9Z']", + "INFO:root:Direct message group channel found. UIDs: ['LdBZ7kPxtKESyHPEe', 'M2sXGqoQRJQwQoXY2', 'os6N2Xg2JkNMCSW9Z']", "INFO:root:Starting to process custom emoji", "INFO:root:Done processing emoji", "INFO:root:skipping direct messages discussion mention: Discussion with Hermione", diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 05ff4292e0..3166fa9c53 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -250,11 +250,11 @@ class Command(ZulipBaseCommand): parser.add_argument("--max-topics", type=int, help="The number of maximum topics to create") parser.add_argument( - "--huddles", - dest="num_huddles", + "--direct-message-groups", + dest="num_direct_message_groups", type=int, default=3, - help="The number of huddles to create.", + help="The number of direct message groups to create.", ) parser.add_argument( @@ -268,10 +268,10 @@ class Command(ZulipBaseCommand): parser.add_argument("--threads", type=int, default=1, help="The number of threads to use.") parser.add_argument( - "--percent-huddles", + "--percent-direct-message-groups", type=float, default=15, - help="The percent of messages to be huddles.", + help="The percent of messages to be direct message groups.", ) parser.add_argument( @@ -307,7 +307,7 @@ class Command(ZulipBaseCommand): # Suppress spammy output from the push notifications logger push_notifications_logger.disabled = True - if options["percent_huddles"] + options["percent_personals"] > 100: + if options["percent_direct_message_groups"] + options["percent_personals"] > 100: self.stderr.write("Error! More than 100% of messages allocated.\n") return @@ -937,8 +937,8 @@ class Command(ZulipBaseCommand): user_profiles_ids = [user_profile.id for user_profile in user_profiles] - # Create several initial huddles - for i in range(options["num_huddles"]): + # Create several initial direct message groups + for i in range(options["num_direct_message_groups"]): get_or_create_direct_message_group( random.sample(user_profiles_ids, random.randint(3, 4)) ) @@ -1167,7 +1167,7 @@ def get_recipient_by_id(rid: int) -> Recipient: # Create some test messages, including: # - multiple streams # - multiple subjects per stream -# - multiple huddles +# - multiple direct message groups # - multiple personal conversations # - multiple messages per subject # - both single and multi-line content @@ -1193,13 +1193,15 @@ def generate_and_send_messages( recipient.id for recipient in Recipient.objects.filter(type=Recipient.STREAM, type_id__in=stream_ids) ] - recipient_huddles: list[int] = [ + recipient_direct_message_groups: list[int] = [ h.id for h in Recipient.objects.filter(type=Recipient.DIRECT_MESSAGE_GROUP) ] - huddle_members: dict[int, list[int]] = {} - for h in recipient_huddles: - huddle_members[h] = [s.user_profile.id for s in Subscription.objects.filter(recipient_id=h)] + direct_message_group_members: dict[int, list[int]] = {} + for h in recipient_direct_message_groups: + direct_message_group_members[h] = [ + s.user_profile.id for s in Subscription.objects.filter(recipient_id=h) + ] # Generate different topics for each stream possible_topic_names = {} @@ -1242,12 +1244,14 @@ def generate_and_send_messages( message.recipient = get_recipient_by_id(recipient_id) elif message_type == Recipient.DIRECT_MESSAGE_GROUP: message.recipient = get_recipient_by_id(recipient_id) - elif randkey <= random_max * options["percent_huddles"] / 100.0: + elif randkey <= random_max * options["percent_direct_message_groups"] / 100.0: message_type = Recipient.DIRECT_MESSAGE_GROUP - message.recipient = get_recipient_by_id(random.choice(recipient_huddles)) + message.recipient = get_recipient_by_id(random.choice(recipient_direct_message_groups)) elif ( randkey - <= random_max * (options["percent_huddles"] + options["percent_personals"]) / 100.0 + <= random_max + * (options["percent_direct_message_groups"] + options["percent_personals"]) + / 100.0 ): message_type = Recipient.PERSONAL personals_pair = random.choice(personals_pairs) @@ -1257,7 +1261,7 @@ def generate_and_send_messages( message.recipient = get_recipient_by_id(random.choice(recipient_streams)) if message_type == Recipient.DIRECT_MESSAGE_GROUP: - sender_id = random.choice(huddle_members[message.recipient.id]) + sender_id = random.choice(direct_message_group_members[message.recipient.id]) message.sender = get_user_profile_by_id(sender_id) elif message_type == Recipient.PERSONAL: message.recipient = Recipient.objects.get(