diff --git a/zerver/lib/slack_data_to_zulip_data.py b/zerver/lib/slack_data_to_zulip_data.py index d73895414d..0743b75ad7 100755 --- a/zerver/lib/slack_data_to_zulip_data.py +++ b/zerver/lib/slack_data_to_zulip_data.py @@ -28,7 +28,7 @@ from zerver.lib.emoji import NAME_TO_CODEPOINT_PATH # stubs ZerverFieldsT = Dict[str, Any] AddedUsersT = Dict[str, int] -AddedChannelsT = Dict[str, int] +AddedChannelsT = Dict[str, Tuple[str, int]] AddedRecipientsT = Dict[str, int] def rm_tree(path: str) -> None: @@ -47,7 +47,7 @@ def slack_workspace_to_realm(domain_name: str, realm_id: int, user_list: List[Ze 1. realm, Converted Realm data 2. added_users, which is a dictionary to map from slack user id to zulip user id 3. added_recipient, which is a dictionary to map from channel name to zulip recipient_id - 4. added_channels, which is a dictionary to map from channel name to zulip stream_id + 4. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 5. avatars, which is list to map avatars to zulip avatar records.json 6. emoji_url_map, which is maps emoji name to its slack url """ @@ -301,7 +301,7 @@ def channels_to_zerver_stream(slack_data_dir: str, realm_id: int, added_users: A Returns: 1. zerver_defaultstream, which is a list of the default streams 2. zerver_stream, while is a list of all streams - 3. added_channels, which is a dictionary to map from channel name to zulip stream_id + 3. added_channels, which is a dictionary to map from channel name to channel id, zulip stream_id 4. zerver_subscription, which is a list of the subscriptions 5. zerver_recipient, which is a list of the recipients 6. added_recipient, which is a dictionary to map from channel name to zulip recipient_id @@ -352,7 +352,7 @@ def channels_to_zerver_stream(slack_data_dir: str, realm_id: int, added_users: A defaultstream_id += 1 zerver_stream.append(stream) - added_channels[stream['name']] = stream_id + added_channels[stream['name']] = (channel['id'], stream_id) # construct the recipient object and append it to zerver_recipient # type 1: private @@ -492,7 +492,9 @@ def convert_slack_workspace_messages(slack_data_dir: str, users: List[ZerverFiel reactions = channel_message_to_zerver_message(realm_id, users, added_users, added_recipient, all_messages, zerver_realmemoji, - realm['zerver_subscription'], domain_name) + realm['zerver_subscription'], + added_channels, + domain_name) logging.info('######### IMPORTING MESSAGES FINISHED #########\n') @@ -522,6 +524,7 @@ def channel_message_to_zerver_message(realm_id: int, users: List[ZerverFieldsT], all_messages: List[ZerverFieldsT], zerver_realmemoji: List[ZerverFieldsT], zerver_subscription: List[ZerverFieldsT], + added_channels: AddedChannelsT, domain_name: str) -> Tuple[List[ZerverFieldsT], List[ZerverFieldsT], List[ZerverFieldsT], @@ -556,6 +559,7 @@ def channel_message_to_zerver_message(realm_id: int, users: List[ZerverFieldsT], has_attachment = has_image = False content, mentioned_users_id, has_link = convert_to_zulip_markdown(message['text'], users, + added_channels, added_users) rendered_content = None diff --git a/zerver/lib/slack_message_conversion.py b/zerver/lib/slack_message_conversion.py index b32e58bbdf..0ce811933b 100644 --- a/zerver/lib/slack_message_conversion.py +++ b/zerver/lib/slack_message_conversion.py @@ -4,6 +4,7 @@ from typing import Any, Dict, Tuple, List # stubs ZerverFieldsT = Dict[str, Any] AddedUsersT = Dict[str, int] +AddedChannelsT = Dict[str, Tuple[str, int]] # Slack link can be in the format and LINK_REGEX = r""" @@ -66,6 +67,7 @@ def get_user_full_name(user: ZerverFieldsT) -> str: # Markdown mapping def convert_to_zulip_markdown(text: str, users: List[ZerverFieldsT], + added_channels: AddedChannelsT, added_users: AddedUsersT) -> Tuple[str, List[int], bool]: mentioned_users_id = [] text = convert_markdown_syntax(text, SLACK_BOLD_REGEX, "**") @@ -80,6 +82,11 @@ def convert_to_zulip_markdown(text: str, users: List[ZerverFieldsT], text = text.replace('', '@**all**') text = text.replace('', '@**all**') + # Map Slack channel mention: '<#C5Z73A7RA|general>' to '#**general**' + for cname, ids in added_channels.items(): + cid = ids[0] + text = text.replace('<#%s|%s>' % (cid, cname), '#**' + cname + '**') + tokens = text.split(' ') for iterator in range(len(tokens)):