From 06a7c3ba8e054237c44e8b1586c76d00c1cffb67 Mon Sep 17 00:00:00 2001 From: Harrison Healey Date: Fri, 10 Mar 2017 05:22:14 -0500 Subject: PLT-5800 Cleaned up duplicated code for adding slack attachments to posts (#5711) --- app/slackimport.go | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'app/slackimport.go') diff --git a/app/slackimport.go b/app/slackimport.go index ced0f6581..fcdd765bb 100644 --- a/app/slackimport.go +++ b/app/slackimport.go @@ -40,17 +40,17 @@ type SlackFile 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 *SlackComment `json:"comment"` - Upload bool `json:"upload"` - File *SlackFile `json:"file"` - Attachments []SlackAttachment `json:"attachments"` + 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"` + Upload bool `json:"upload"` + File *SlackFile `json:"file"` + Attachments []*model.SlackAttachment `json:"attachments"` } type SlackComment struct { @@ -58,13 +58,6 @@ type SlackComment struct { Comment string `json:"comment"` } -type SlackAttachment struct { - Id int `json:"id"` - Text string `json:"text"` - Pretext string `json:"pretext"` - Fields []map[string]interface{} `json:"fields"` -} - func truncateRunes(s string, i int) string { runes := []rune(s) if len(runes) > i { @@ -284,15 +277,7 @@ func SlackAddPosts(teamId string, channel *model.Channel, posts []SlackPost, use props := make(model.StringInterface) props["override_username"] = sPost.BotUsername if len(sPost.Attachments) > 0 { - var mAttachments []interface{} - for _, attachment := range sPost.Attachments { - mAttachments = append(mAttachments, map[string]interface{}{ - "text": attachment.Text, - "pretext": attachment.Pretext, - "fields": attachment.Fields, - }) - } - props["attachments"] = mAttachments + props["attachments"] = sPost.Attachments } post := &model.Post{ -- cgit v1.2.3-1-g7c22