summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2016-10-04 13:51:38 +0100
committerChristopher Speller <crspeller@gmail.com>2016-10-04 08:51:38 -0400
commit1a5a6244701615b4f085bb5337d92c2809ac95d3 (patch)
tree114b6285f064c45342796bc1c915044292993690 /api
parent38c34017a3760e62fb08025c76fd3c7a25006e58 (diff)
downloadchat-1a5a6244701615b4f085bb5337d92c2809ac95d3.tar.gz
chat-1a5a6244701615b4f085bb5337d92c2809ac95d3.tar.bz2
chat-1a5a6244701615b4f085bb5337d92c2809ac95d3.zip
Fix import of Slack file_comment messages. (#4132)
At the moment, the importer fails to parse the JSON of these types of message, and so ignores them. This fix means they are now parsed and imported just as if they were standalone messages (not file comments), which is better, and what the existing code clearly intended to happen. For the future, they should probably be changed to be imported as replies to the message with the file attached that they are commenting on. Fixes #4131.
Diffstat (limited to 'api')
-rw-r--r--api/slackimport.go32
1 files changed, 20 insertions, 12 deletions
diff --git a/api/slackimport.go b/api/slackimport.go
index 27b8e7f5d..a374d335b 100644
--- a/api/slackimport.go
+++ b/api/slackimport.go
@@ -31,14 +31,19 @@ type SlackUser struct {
}
type SlackPost struct {
- User string `json:"user"`
- BotId string `json:"bot_id"`
- BotUsername string `json:"username"`
- Text string `json:"text"`
- TimeStamp string `json:"ts"`
- Type string `json:"type"`
- SubType string `json:"subtype"`
- Comment map[string]string `json:"comment"`
+ User string `json:"user"`
+ BotId string `json:"bot_id"`
+ BotUsername string `json:"username"`
+ Text string `json:"text"`
+ TimeStamp string `json:"ts"`
+ Type string `json:"type"`
+ SubType string `json:"subtype"`
+ Comment *SlackComment `json:"comment"`
+}
+
+type SlackComment struct {
+ User string `json:"user"`
+ Comment string `json:"comment"`
}
func SlackConvertTimeStamp(ts string) int64 {
@@ -172,17 +177,20 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
}
ImportPost(&newPost)
case sPost.Type == "message" && sPost.SubType == "file_comment":
- if sPost.Comment["user"] == "" {
+ if sPost.Comment == nil {
+ l4g.Debug(utils.T("api.slackimport.slack_add_posts.msg_no_comment.debug"))
+ continue
+ } else if sPost.Comment.User == "" {
l4g.Debug(utils.T("api.slackimport.slack_add_posts.msg_no_usr.debug"))
continue
- } else if users[sPost.Comment["user"]] == nil {
+ } else if users[sPost.Comment.User] == nil {
l4g.Debug(utils.T("api.slackimport.slack_add_posts.user_no_exists.debug"), sPost.User)
continue
}
newPost := model.Post{
- UserId: users[sPost.Comment["user"]].Id,
+ UserId: users[sPost.Comment.User].Id,
ChannelId: channel.Id,
- Message: sPost.Comment["comment"],
+ Message: sPost.Comment.Comment,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
}
ImportPost(&newPost)