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.
Этот коммит содержится в:
George Goldberg
2016-10-04 13:51:38 +01:00
коммит произвёл Christopher Speller
родитель 38c34017a3
Коммит 1a5a624470
2 изменённых файлов: 24 добавлений и 12 удалений

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

@@ -38,7 +38,12 @@ type SlackPost struct {
TimeStamp string `json:"ts"` TimeStamp string `json:"ts"`
Type string `json:"type"` Type string `json:"type"`
SubType string `json:"subtype"` SubType string `json:"subtype"`
Comment map[string]string `json:"comment"` Comment *SlackComment `json:"comment"`
}
type SlackComment struct {
User string `json:"user"`
Comment string `json:"comment"`
} }
func SlackConvertTimeStamp(ts string) int64 { func SlackConvertTimeStamp(ts string) int64 {
@@ -172,17 +177,20 @@ func SlackAddPosts(channel *model.Channel, posts []SlackPost, users map[string]*
} }
ImportPost(&newPost) ImportPost(&newPost)
case sPost.Type == "message" && sPost.SubType == "file_comment": 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")) l4g.Debug(utils.T("api.slackimport.slack_add_posts.msg_no_usr.debug"))
continue 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) l4g.Debug(utils.T("api.slackimport.slack_add_posts.user_no_exists.debug"), sPost.User)
continue continue
} }
newPost := model.Post{ newPost := model.Post{
UserId: users[sPost.Comment["user"]].Id, UserId: users[sPost.Comment.User].Id,
ChannelId: channel.Id, ChannelId: channel.Id,
Message: sPost.Comment["comment"], Message: sPost.Comment.Comment,
CreateAt: SlackConvertTimeStamp(sPost.TimeStamp), CreateAt: SlackConvertTimeStamp(sPost.TimeStamp),
} }
ImportPost(&newPost) ImportPost(&newPost)

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

@@ -1547,6 +1547,10 @@
"id": "api.slackimport.slack_add_posts.bot.warn", "id": "api.slackimport.slack_add_posts.bot.warn",
"translation": "Slack bot posts are not imported yet" "translation": "Slack bot posts are not imported yet"
}, },
{
"id": "api.slackimport.slack_add_posts.msg_no_comment.debug",
"translation": "File comment message without comment"
},
{ {
"id": "api.slackimport.slack_add_posts.msg_no_usr.debug", "id": "api.slackimport.slack_add_posts.msg_no_usr.debug",
"translation": "Message without user" "translation": "Message without user"