PLT-4847 Fix formatting of links imported from Slack. (#4674)

This fixes mailto: links built from email addresses posted to Slack as
described in the ticket, but also fixes any other type of URL that has
been auto-linked in the Slack messages.
Этот коммит содержится в:
George Goldberg
2016-11-29 19:07:07 +00:00
коммит произвёл Joram Wilander
родитель 7f911d1632
Коммит e7710cf1d2
2 изменённых файлов: 35 добавлений и 0 удалений

Просмотреть файл

@@ -494,6 +494,19 @@ func SlackConvertChannelMentions(channels []SlackChannel, posts map[string][]Sla
return posts
}
func SlackConvertPostsMarkup(posts map[string][]SlackPost) map[string][]SlackPost {
// Convert URLs in Slack's format to Markdown format.
regex := regexp.MustCompile(`<([^|<>]+)\|([^|<>]+)>`)
for channelName, channelPosts := range posts {
for postIdx, post := range channelPosts {
posts[channelName][postIdx].Text = regex.ReplaceAllString(post.Text, "[$2]($1)")
}
}
return posts
}
func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) {
// Create log file
log := bytes.NewBufferString(utils.T("api.slackimport.slack_import.log"))
@@ -536,6 +549,7 @@ func SlackImport(fileData multipart.File, fileSize int64, teamID string) (*model
posts = SlackConvertUserMentions(users, posts)
posts = SlackConvertChannelMentions(channels, posts)
posts = SlackConvertPostsMarkup(posts)
addedUsers := SlackAddUsers(teamID, users, log)
botUser := SlackAddBotUser(teamID, log)