mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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.
This commit is contained in:
committed by
Christopher Speller
parent
00e12f25c6
commit
55342e8fe1
@@ -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)
|
||||
|
||||
|
||||
@@ -1419,6 +1419,10 @@
|
||||
"id": "api.slackimport.slack_convert_timestamp.bad.warn",
|
||||
"translation": "Bad timestamp detected"
|
||||
},
|
||||
{
|
||||
"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}}"
|
||||
},
|
||||
{
|
||||
"id": "api.slackimport.slack_import.log",
|
||||
"translation": "Mattermost Slack Import Log\r\n"
|
||||
|
||||
@@ -48,7 +48,7 @@ class TeamImportTab extends React.Component {
|
||||
<div>
|
||||
<FormattedHTMLMessage
|
||||
id='team_import_tab.importHelp'
|
||||
defaultMessage="<p>To import a team from Slack go to Slack > Team Settings > Import/Export Data > Export > Start Export. Slack does not allow you to export files, images, private groups or direct messages stored in Slack. Therefore, Slack import to Mattermost only supports importing of text messages in your Slack team's public channels.</p><p>The Slack import to Mattermost is in 'Beta'. Slack bot posts do not yet import and Slack @mentions are not currently supported.</p>"
|
||||
defaultMessage="<p>To import a team from Slack go to Slack > Team Settings > Import/Export Data > Export > Start Export. Slack does not allow you to export files, images, private groups or direct messages stored in Slack. Therefore, Slack import to Mattermost only supports importing of text messages in your Slack team's public channels.</p><p>The Slack import to Mattermost is in 'Beta'. Slack bot posts do not yet import.</p>"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -1664,7 +1664,7 @@
|
||||
"team_export_tab.unable": " Unable to export: {error}",
|
||||
"team_import_tab.failure": " Import failure: ",
|
||||
"team_import_tab.import": "Import",
|
||||
"team_import_tab.importHelp": "<p>To import a team from Slack go to Slack > Team Settings > Import/Export Data > Export > Start Export. Slack does not allow you to export files, images, private groups or direct messages stored in Slack. Therefore, Slack import to Mattermost only supports importing of text messages in your Slack team's public channels.</p><p>The Slack import to Mattermost is in 'Beta'. Slack bot posts do not yet import and Slack @mentions are not currently supported.</p>",
|
||||
"team_import_tab.importHelp": "<p>To import a team from Slack go to Slack > Team Settings > Import/Export Data > Export > Start Export. Slack does not allow you to export files, images, private groups or direct messages stored in Slack. Therefore, Slack import to Mattermost only supports importing of text messages in your Slack team's public channels.</p><p>The Slack import to Mattermost is in 'Beta'. Slack bot posts do not yet import.</p>",
|
||||
"team_import_tab.importSlack": "Import from Slack (Beta)",
|
||||
"team_import_tab.importing": " Importing...",
|
||||
"team_import_tab.successful": " Import successful: ",
|
||||
|
||||
Reference in New Issue
Block a user