Fix !channel linking in Slack import. (#4065)
Original version of the patch didn't take into account that, like with @mentions, there's an "old" and a "new" format in the Slack export files for channel mentions. This version imports both correctly.
Этот коммит содержится в:
коммит произвёл
enahum
родитель
185387e277
Коммит
de79343b9a
@@ -286,15 +286,20 @@ func SlackConvertUserMentions(users []SlackUser, posts map[string][]SlackPost) m
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SlackConvertChannelMentions(channels []SlackChannel, posts map[string][]SlackPost) map[string][]SlackPost {
|
func SlackConvertChannelMentions(channels []SlackChannel, posts map[string][]SlackPost) map[string][]SlackPost {
|
||||||
var channelPatterns = make(map[string]string, len(channels))
|
var regexes = make(map[string]*regexp.Regexp, len(channels))
|
||||||
for _, channel := range channels {
|
for _, channel := range channels {
|
||||||
channelPatterns["!"+channel.Name] = "<#" + channel.Id + ">"
|
r, err := regexp.Compile("<#" + channel.Id + `(\|` + channel.Name + ")?>")
|
||||||
|
if err != nil {
|
||||||
|
l4g.Warn(utils.T("api.slackimport.slack_convert_channel_mentions.compile_regexp_failed.warn"), channel.Id, channel.Name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
regexes["!"+channel.Name] = r
|
||||||
}
|
}
|
||||||
|
|
||||||
for channelName, channelPosts := range posts {
|
for channelName, channelPosts := range posts {
|
||||||
for postIdx, post := range channelPosts {
|
for postIdx, post := range channelPosts {
|
||||||
for channelReplace, channelMatch := range channelPatterns {
|
for channelReplace, r := range regexes {
|
||||||
post.Text = strings.Replace(post.Text, channelMatch, channelReplace, -1)
|
post.Text = r.ReplaceAllString(post.Text, channelReplace)
|
||||||
posts[channelName][postIdx] = post
|
posts[channelName][postIdx] = post
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1511,6 +1511,10 @@
|
|||||||
"id": "api.slackimport.slack_convert_user_mentions.compile_regexp_failed.warn",
|
"id": "api.slackimport.slack_convert_user_mentions.compile_regexp_failed.warn",
|
||||||
"translation": "Failed to compile the @mention matching regular expression for Slack user {{.UserID}} {{.Username}}"
|
"translation": "Failed to compile the @mention matching regular expression for Slack user {{.UserID}} {{.Username}}"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "api.slackimport.slack_convert_channel_mentions.compile_regexp_failed.warn",
|
||||||
|
"translation": "Failed to compile the !channel matching regular expression for Slack channel {{.ChannelID}} {{.ChannelName}}"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "api.slackimport.slack_import.log",
|
"id": "api.slackimport.slack_import.log",
|
||||||
"translation": "Mattermost Slack Import Log\r\n"
|
"translation": "Mattermost Slack Import Log\r\n"
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user