summaryrefslogtreecommitdiffstats
path: root/app/slackimport.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-01-26 02:14:12 +0000
committerenahum <nahumhbl@gmail.com>2017-01-25 23:14:12 -0300
commitf7476b2fb6a01d50868a128c1d1f77c14691482d (patch)
tree211398e395f42f60f866b791cc005eb1dcc2959d /app/slackimport.go
parent57d9d0ad1ee3e841640d74fcb122516bce8efd9a (diff)
downloadchat-f7476b2fb6a01d50868a128c1d1f77c14691482d.tar.gz
chat-f7476b2fb6a01d50868a128c1d1f77c14691482d.tar.bz2
chat-f7476b2fb6a01d50868a128c1d1f77c14691482d.zip
PLT-4378 Slack import when channel name is deleted (#4649)
This fixes the issue where the channel fails to Import from Slack if there is already a channel with the same name on Mattermost that has been deleted.
Diffstat (limited to 'app/slackimport.go')
-rw-r--r--app/slackimport.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/app/slackimport.go b/app/slackimport.go
index 53f455069..508803126 100644
--- a/app/slackimport.go
+++ b/app/slackimport.go
@@ -470,18 +470,28 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
Header: sChannel.Topic["value"],
}
newChannel = SlackSanitiseChannelProperties(newChannel)
- mChannel := ImportChannel(&newChannel)
+
+ var mChannel *model.Channel
+ if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err == nil {
+ // The channel already exists as an active channel. Merge with the existing one.
+ mChannel = result.Data.(*model.Channel)
+ log.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
+ } else if result := <-Srv.Store.Channel().GetDeletedByName(teamId, sChannel.Name); result.Err == nil {
+ // The channel already exists but has been deleted. Generate a random string for the handle instead.
+ newChannel.Name = model.NewId()
+ newChannel = SlackSanitiseChannelProperties(newChannel)
+ }
+
if mChannel == nil {
- // Maybe it already exists?
- if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil {
+ // Haven't found an existing channel to merge with. Try importing it as a new one.
+ mChannel = ImportChannel(&newChannel)
+ if mChannel == nil {
l4g.Warn(utils.T("api.slackimport.slack_add_channels.import_failed.warn"), newChannel.DisplayName)
log.WriteString(utils.T("api.slackimport.slack_add_channels.import_failed", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
continue
- } else {
- mChannel = result.Data.(*model.Channel)
- log.WriteString(utils.T("api.slackimport.slack_add_channels.merge", map[string]interface{}{"DisplayName": newChannel.DisplayName}))
}
}
+
addSlackUsersToChannel(sChannel.Members, users, mChannel, log)
log.WriteString(newChannel.DisplayName + "\r\n")
addedChannels[sChannel.Id] = mChannel