summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2016-09-21 19:17:48 +0100
committerenahum <nahumhbl@gmail.com>2016-09-21 15:17:48 -0300
commitde79343b9aa9dc601e5633cef329e1a83452aa1a (patch)
tree5acb88e5bef80fddf3ea89f5a00a183cad118a50 /api
parent185387e277aa65781ecb9e5fa710c2a8fb4cee65 (diff)
downloadchat-de79343b9aa9dc601e5633cef329e1a83452aa1a.tar.gz
chat-de79343b9aa9dc601e5633cef329e1a83452aa1a.tar.bz2
chat-de79343b9aa9dc601e5633cef329e1a83452aa1a.zip
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.
Diffstat (limited to 'api')
-rw-r--r--api/slackimport.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/api/slackimport.go b/api/slackimport.go
index cb6877616..27b8e7f5d 100644
--- a/api/slackimport.go
+++ b/api/slackimport.go
@@ -286,15 +286,20 @@ func SlackConvertUserMentions(users []SlackUser, posts map[string][]SlackPost) m
}
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 {
- 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 postIdx, post := range channelPosts {
- for channelReplace, channelMatch := range channelPatterns {
- post.Text = strings.Replace(post.Text, channelMatch, channelReplace, -1)
+ for channelReplace, r := range regexes {
+ post.Text = r.ReplaceAllString(post.Text, channelReplace)
posts[channelName][postIdx] = post
}
}