diff options
author | Corey Hulen <corey@hulen.com> | 2016-01-20 13:36:27 -0600 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-01-20 13:36:27 -0600 |
commit | d703d09063538fb91baa5a21b1001216c43d848a (patch) | |
tree | d87809ff2a306e5428b0ab6973d05509baa21abd /api/slackimport.go | |
parent | 0b1aff3b24b4ac2df8e963c83d6e52b127c603f9 (diff) | |
parent | aefbb541d0d5bdd9919fef44fbf1a1fbfeaeb58b (diff) | |
download | chat-d703d09063538fb91baa5a21b1001216c43d848a.tar.gz chat-d703d09063538fb91baa5a21b1001216c43d848a.tar.bz2 chat-d703d09063538fb91baa5a21b1001216c43d848a.zip |
Merge pull request #1932 from mattermost/revert-1930-PLT-7-server-db
Revert " PLT-7 adding loc for db calls"
Diffstat (limited to 'api/slackimport.go')
-rw-r--r-- | api/slackimport.go | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/api/slackimport.go b/api/slackimport.go index 8e6cc05c4..e0a0ff036 100644 --- a/api/slackimport.go +++ b/api/slackimport.go @@ -7,14 +7,12 @@ import ( "archive/zip" "bytes" "encoding/json" + l4g "github.com/alecthomas/log4go" + "github.com/mattermost/platform/model" "io" "mime/multipart" "strconv" "strings" - - l4g "github.com/alecthomas/log4go" - "github.com/mattermost/platform/model" - goi18n "github.com/nicksnyder/go-i18n/i18n" ) type SlackChannel struct { @@ -91,7 +89,7 @@ func SlackParsePosts(data io.Reader) []SlackPost { return posts } -func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User { +func SlackAddUsers(teamId string, slackusers []SlackUser, log *bytes.Buffer) map[string]*model.User { // Log header log.WriteString("\r\n Users Created\r\n") log.WriteString("===============\r\n\r\n") @@ -118,7 +116,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser Password: password, } - if mUser := ImportUser(T, &newUser); mUser != nil { + if mUser := ImportUser(&newUser); mUser != nil { addedUsers[sUser.Id] = mUser log.WriteString("Email, Password: " + newUser.Email + ", " + password + "\r\n") } else { @@ -129,7 +127,7 @@ func SlackAddUsers(T goi18n.TranslateFunc, teamId string, slackusers []SlackUser return addedUsers } -func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []SlackPost, users map[string]*model.User) { +func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*model.User) { for _, sPost := range posts { switch { case sPost.Type == "message" && (sPost.SubType == "" || sPost.SubType == "file_share"): @@ -146,7 +144,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack Message: sPost.Text, CreateAt: SlackConvertTimeStamp(sPost.TimeStamp), } - ImportPost(T, &newPost) + ImportPost(&newPost) case sPost.Type == "message" && sPost.SubType == "file_comment": if sPost.Comment["user"] == "" { l4g.Debug("Message without user") @@ -161,7 +159,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack Message: sPost.Comment["comment"], CreateAt: SlackConvertTimeStamp(sPost.TimeStamp), } - ImportPost(T, &newPost) + ImportPost(&newPost) case sPost.Type == "message" && sPost.SubType == "bot_message": // In the future this will use the "Action Post" spec to post // a message without using a username. For now we just warn that we don't handle this case @@ -172,7 +170,7 @@ func SlackAddPosts(T goi18n.TranslateFunc, channel *model.Channel, posts []Slack } } -func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel { +func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[string][]SlackPost, users map[string]*model.User, log *bytes.Buffer) map[string]*model.Channel { // Write Header log.WriteString("\r\n Channels Added \r\n") log.WriteString("=================\r\n\r\n") @@ -186,10 +184,10 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla Name: SlackConvertChannelName(sChannel.Name), Purpose: sChannel.Topic["value"], } - mChannel := ImportChannel(T, &newChannel) + mChannel := ImportChannel(&newChannel) if mChannel == nil { // Maybe it already exists? - if result := <-Srv.Store.Channel().GetByName(T, teamId, sChannel.Name); result.Err != nil { + if result := <-Srv.Store.Channel().GetByName(teamId, sChannel.Name); result.Err != nil { l4g.Debug("Failed to import: %s", newChannel.DisplayName) log.WriteString("Failed to import: " + newChannel.DisplayName + "\r\n") continue @@ -200,13 +198,13 @@ func SlackAddChannels(T goi18n.TranslateFunc, teamId string, slackchannels []Sla } log.WriteString(newChannel.DisplayName + "\r\n") addedChannels[sChannel.Id] = mChannel - SlackAddPosts(T, mChannel, posts[sChannel.Name], users) + SlackAddPosts(mChannel, posts[sChannel.Name], users) } return addedChannels } -func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64, teamID string) (*model.AppError, *bytes.Buffer) { +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 { return model.NewAppError("SlackImport", "Unable to open zip file", err.Error()), nil @@ -242,8 +240,8 @@ func SlackImport(T goi18n.TranslateFunc, fileData multipart.File, fileSize int64 } } - addedUsers := SlackAddUsers(T, teamID, users, log) - SlackAddChannels(T, teamID, channels, posts, addedUsers, log) + addedUsers := SlackAddUsers(teamID, users, log) + SlackAddChannels(teamID, channels, posts, addedUsers, log) log.WriteString("\r\n Notes \r\n") log.WriteString("=======\r\n\r\n") |