Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

mattermost_importer: Be precise when refering to Mattermost channel ID.

PieterCK21831d3dd78f
diff --git a/zerver/data_import/mattermost.py b/zerver/data_import/mattermost.py
index bf1455b1c9f..791d431dc59 100644
--- a/zerver/data_import/mattermost.py
+++ b/zerver/data_import/mattermost.py
@@ -168,9 +168,9 @@ def convert_channel_data(
def initialize_stream_membership_dicts() -> None:
for channel in channel_data:
- channel_name = channel["name"]
- channel_members_map[channel_name] = []
- channel_admins_map[channel_name] = []
+ mattermost_channel_id = channel["name"]
+ channel_members_map[mattermost_channel_id] = []
+ channel_admins_map[mattermost_channel_id] = []
for username, user_dict in user_data_map.items():
teams = user_dict["teams"]
@@ -182,11 +182,11 @@ def convert_channel_data(
continue
for channel in team["channels"]:
channel_roles = channel["roles"]
- channel_name = channel["name"]
+ mattermost_channel_id = channel["name"]
if "channel_admin" in channel_roles:
- channel_admins_map[channel_name].append(username)
+ channel_admins_map[mattermost_channel_id].append(username)
elif "channel_user" in channel_roles:
- channel_members_map[channel_name].append(username)
+ channel_members_map[mattermost_channel_id].append(username)
def get_invite_only_value_from_channel_type(channel_type: str) -> bool:
# Channel can have two types in Mattermost
@@ -204,8 +204,9 @@ def convert_channel_data(
channel_name_count: dict[str, int] = {}
for channel_dict in channel_data_list:
now = int(timezone_now().timestamp())
- stream_id = stream_id_mapper.get(channel_dict["name"])
- stream_name = channel_dict["name"]
+ # The "name" field is Mattermost channel's unique identifier.
+ mattermost_channel_id = channel_dict["name"]
+ stream_id = stream_id_mapper.get(mattermost_channel_id)
invite_only = get_invite_only_value_from_channel_type(channel_dict["type"])
channel_display_name = truncate_content(
channel_dict["display_name"], Stream.MAX_NAME_LENGTH, "…"
@@ -244,8 +245,14 @@ def convert_channel_data(
)
channel_users = {
- *(user_id_mapper.get(username) for username in channel_admins_map[stream_name]),
- *(user_id_mapper.get(username) for username in channel_members_map[stream_name]),
+ *(
+ user_id_mapper.get(username)
+ for username in channel_admins_map[mattermost_channel_id]
+ ),
+ *(
+ user_id_mapper.get(username)
+ for username in channel_members_map[mattermost_channel_id]
+ ),
}
subscriber_handler.set_info(
@@ -426,7 +433,7 @@ def process_raw_message_batch(
subscriber_map: dict[int, set[int]],
user_id_mapper: IdMapper[str],
user_handler: UserHandler,
- get_recipient_id_from_channel_name: Callable[[str], int],
+ get_recipient_id_from_mattermost_channel_id: Callable[[str], int],
get_recipient_id_from_direct_message_group_members: Callable[[frozenset[str]], int],
get_recipient_id_from_username: Callable[[str], int],
is_pm_data: bool,
@@ -476,7 +483,7 @@ def process_raw_message_batch(
sender_user_id = raw_message["sender_id"]
if "channel_name" in raw_message:
is_direct_message_type = False
- recipient_id = get_recipient_id_from_channel_name(raw_message["channel_name"])
+ recipient_id = get_recipient_id_from_mattermost_channel_id(raw_message["channel_name"])
elif "direct_message_group_members" in raw_message:
is_direct_message_type = True
recipient_id = get_recipient_id_from_direct_message_group_members(
@@ -567,7 +574,7 @@ def process_posts(
team_name: str,
realm_id: int,
post_data: list[dict[str, Any]],
- get_recipient_id_from_channel_name: Callable[[str], int],
+ get_recipient_id_from_mattermost_channel_id: Callable[[str], int],
get_recipient_id_from_direct_message_group_members: Callable[[frozenset[str]], int],
get_recipient_id_from_username: Callable[[str], int],
subscriber_map: dict[int, set[int]],
@@ -655,7 +662,7 @@ def process_posts(
subscriber_map=subscriber_map,
user_id_mapper=user_id_mapper,
user_handler=user_handler,
- get_recipient_id_from_channel_name=get_recipient_id_from_channel_name,
+ get_recipient_id_from_mattermost_channel_id=get_recipient_id_from_mattermost_channel_id,
get_recipient_id_from_direct_message_group_members=get_recipient_id_from_direct_message_group_members,
get_recipient_id_from_username=get_recipient_id_from_username,
is_pm_data=is_pm_data,
@@ -707,8 +714,8 @@ def write_message_data(
if d["type"] == Recipient.PERSONAL:
user_id_to_recipient_id[d["type_id"]] = d["id"]
- def get_recipient_id_from_channel_name(channel_name: str) -> int:
- receiver_id = stream_id_mapper.get(channel_name)
+ def get_recipient_id_from_mattermost_channel_id(mattermost_channel_id: str) -> int:
+ receiver_id = stream_id_mapper.get(mattermost_channel_id)
return stream_id_to_recipient_id[receiver_id]
def get_recipient_id_from_direct_message_group_members(
@@ -735,7 +742,7 @@ def write_message_data(
team_name=team_name,
realm_id=realm_id,
post_data=post_data[post_type],
- get_recipient_id_from_channel_name=get_recipient_id_from_channel_name,
+ get_recipient_id_from_mattermost_channel_id=get_recipient_id_from_mattermost_channel_id,
get_recipient_id_from_direct_message_group_members=get_recipient_id_from_direct_message_group_members,
get_recipient_id_from_username=get_recipient_id_from_username,
subscriber_map=subscriber_map,