summaryrefslogtreecommitdiffstats
path: root/api/slackimport.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@grundleborg.com>2016-08-29 14:45:27 +0100
committerChristopher Speller <crspeller@gmail.com>2016-08-29 09:45:27 -0400
commit55342e8fe16613f06528ed1aa726231e9b597d26 (patch)
tree121b217caed1dcb1280af16fe58d5453992db760 /api/slackimport.go
parent00e12f25c6bd4efec2461bb61687939070264370 (diff)
downloadchat-55342e8fe16613f06528ed1aa726231e9b597d26.tar.gz
chat-55342e8fe16613f06528ed1aa726231e9b597d26.tar.bz2
chat-55342e8fe16613f06528ed1aa726231e9b597d26.zip
Convert @mentions on Slack import. (#3837)
Converts @mentions in Slack imports for regular messages, comments and Slack upload messages. Updates the description on the Team Settings Import tab to remove mention of @mentions not importing.
Diffstat (limited to 'api/slackimport.go')
-rw-r--r--api/slackimport.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/api/slackimport.go b/api/slackimport.go
index df43e1a8b..4382e7f6d 100644
--- a/api/slackimport.go
+++ b/api/slackimport.go
@@ -12,6 +12,7 @@ import (
"github.com/mattermost/platform/utils"
"io"
"mime/multipart"
+ "regexp"
"strconv"
"strings"
)
@@ -230,6 +231,29 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
return addedChannels
}
+func SlackConvertUserMentions(users []SlackUser, posts map[string][]SlackPost) map[string][]SlackPost {
+ var regexes = make(map[string]*regexp.Regexp, len(users))
+ for _, user := range users {
+ r, err := regexp.Compile("<@" + user.Id + `(\|` + user.Username + ")?>")
+ if err != nil {
+ l4g.Warn(utils.T("api.slackimport.slack_convert_user_mentions.compile_regexp_failed.warn"), user.Id, user.Username)
+ continue
+ }
+ regexes["@"+user.Username] = r
+ }
+
+ for channelName, channelPosts := range posts {
+ for postIdx, post := range channelPosts {
+ for mention, r := range regexes {
+ post.Text = r.ReplaceAllString(post.Text, mention)
+ posts[channelName][postIdx] = post
+ }
+ }
+ }
+
+ return posts
+}
+
func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
zipreader, err := zip.NewReader(fileData, fileSize)
if err != nil || zipreader.File == nil {
@@ -266,6 +290,8 @@ func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model
}
}
+ posts = SlackConvertUserMentions(users, posts)
+
addedUsers := SlackAddUsers(teamID, users, log)
SlackAddChannels(teamID, channels, posts, addedUsers, log)