summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
Diffstat (limited to 'model')
-rw-r--r--model/slack_attachment.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/model/slack_attachment.go b/model/slack_attachment.go
index 197d3f0f9..827bf35b3 100644
--- a/model/slack_attachment.go
+++ b/model/slack_attachment.go
@@ -5,8 +5,11 @@ package model
import (
"fmt"
+ "regexp"
)
+var linkWithTextRegex = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
+
type SlackAttachment struct {
Id int64 `json:"id"`
Fallback string `json:"fallback"`
@@ -57,3 +60,25 @@ func StringifySlackFieldValue(a []*SlackAttachment) []*SlackAttachment {
}
return nonNilAttachments
}
+
+// This method only parses and processes the attachments,
+// all else should be set in the post which is passed
+func ParseSlackAttachment(post *Post, attachments []*SlackAttachment) {
+ post.Type = POST_SLACK_ATTACHMENT
+
+ for _, attachment := range attachments {
+ attachment.Text = ParseSlackLinksToMarkdown(attachment.Text)
+ attachment.Pretext = ParseSlackLinksToMarkdown(attachment.Pretext)
+
+ for _, field := range attachment.Fields {
+ if value, ok := field.Value.(string); ok {
+ field.Value = ParseSlackLinksToMarkdown(value)
+ }
+ }
+ }
+ post.AddProp("attachments", attachments)
+}
+
+func ParseSlackLinksToMarkdown(text string) string {
+ return linkWithTextRegex.ReplaceAllString(text, "[${2}](${1})")
+}