PLT-5800 Cleaned up duplicated code for adding slack attachments to posts (#5711)

Этот коммит содержится в:
Harrison Healey
2017-03-10 05:22:14 -05:00
коммит произвёл George Goldberg
родитель 06930f378c
Коммит 06a7c3ba8e
4 изменённых файлов: 19 добавлений и 91 удалений

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

@@ -150,37 +150,8 @@ func CreateWebhookPost(userId, teamId, channelId, text, overrideUsername, overri
if len(props) > 0 {
for key, val := range props {
if key == "attachments" {
if list, success := val.([]interface{}); success {
// parse attachment links into Markdown format
for i, aInt := range list {
attachment := aInt.(map[string]interface{})
if aText, ok := attachment["text"].(string); ok {
aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
attachment["text"] = aText
list[i] = attachment
}
if aText, ok := attachment["pretext"].(string); ok {
aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
attachment["pretext"] = aText
list[i] = attachment
}
if fVal, ok := attachment["fields"]; ok {
if fields, ok := fVal.([]interface{}); ok {
// parse attachment field links into Markdown format
for j, fInt := range fields {
field := fInt.(map[string]interface{})
if fValue, ok := field["value"].(string); ok {
fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})")
field["value"] = fValue
fields[j] = field
}
}
attachment["fields"] = fields
list[i] = attachment
}
}
}
post.AddProp(key, list)
if attachments, success := val.([]*model.SlackAttachment); success {
parseSlackAttachment(post, attachments)
}
} else if key != "override_icon_url" && key != "override_username" && key != "from_webhook" {
post.AddProp(key, val)
@@ -452,7 +423,7 @@ func HandleIncomingWebhook(hookId string, req *model.IncomingWebhookRequest, sit
webhookType := req.Type
// attachments is in here for slack compatibility
if req.Attachments != nil {
if len(req.Attachments) > 0 {
if len(req.Props) == 0 {
req.Props = make(model.StringInterface)
}