From 4ae9c02e575ae7f4c012466a7a86720c269ae1cd Mon Sep 17 00:00:00 2001 From: Boris Melnik Date: Fri, 17 Nov 2023 16:18:18 +0300 Subject: [PATCH] fix(discord): Handle multiple channels with the same name (#4313) --- protocol/messenger_communities_import_discord.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/protocol/messenger_communities_import_discord.go b/protocol/messenger_communities_import_discord.go index 8c1dd251c..100fcb0f0 100644 --- a/protocol/messenger_communities_import_discord.go +++ b/protocol/messenger_communities_import_discord.go @@ -1087,6 +1087,9 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor processedChannelIds := make(map[string]string, 0) processedCategoriesIds := make(map[string]string, 0) + // The map with counts of duplicated channel names + uniqueChatNames := make(map[string]int, 0) + for i, importFile := range request.FilesToImport { exportData, errs := m.ExtractDiscordDataFromImportFiles([]string{importFile}) @@ -1184,12 +1187,20 @@ func (m *Messenger) RequestImportDiscordCommunity(request *requests.ImportDiscor } if !exists { + channelUniqueName := channel.Channel.Name + if count, ok := uniqueChatNames[channelUniqueName]; ok { + uniqueChatNames[channelUniqueName] = count + 1 + channelUniqueName = fmt.Sprintf("%s_%d", channelUniqueName, uniqueChatNames[channelUniqueName]) + } else { + uniqueChatNames[channelUniqueName] = 1 + } + communityChat := &protobuf.CommunityChat{ Permissions: &protobuf.CommunityPermissions{ Access: protobuf.CommunityPermissions_AUTO_ACCEPT, }, Identity: &protobuf.ChatIdentity{ - DisplayName: channel.Channel.Name, + DisplayName: channelUniqueName, Emoji: "", Description: channel.Channel.Description, Color: discordCommunity.Color(),