[MM-11860]: Expose slack attachment parsing functions in the model package (#9351)

Refactored parseSlackAttachment functions from https://github.com/mattermost/mattermost-server/blob/master/app/post.go#L312
into model/slack_attachments.go so that plugins have access to them.
Этот коммит содержится в:
Charles Birk
2018-09-17 10:15:28 -04:00
коммит произвёл Joram Wilander
родитель 7226ea7dfb
Коммит a755bcdde6
5 изменённых файлов: 30 добавлений и 30 удалений

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

@@ -13,7 +13,6 @@ import (
"net/http"
"net/url"
"path"
"regexp"
"strings"
"github.com/dyatlov/go-opengraph/opengraph"
@@ -25,8 +24,6 @@ import (
"golang.org/x/net/html/charset"
)
var linkWithTextRegex = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
func (a *App) CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError) {
// Check that channel has not been deleted
var channel *model.Channel
@@ -308,28 +305,6 @@ func (a *App) handlePostEvents(post *model.Post, user *model.User, channel *mode
return nil
}
// This method only parses and processes the attachments,
// all else should be set in the post which is passed
func parseSlackAttachment(post *model.Post, attachments []*model.SlackAttachment) {
post.Type = model.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})")
}
func (a *App) SendEphemeralPost(userId string, post *model.Post) *model.Post {
post.Type = model.POST_EPHEMERAL
@@ -931,7 +906,7 @@ func (a *App) DoPostAction(postId, actionId, userId, selectedOption string) *mod
if response.EphemeralText != "" {
ephemeralPost := &model.Post{}
ephemeralPost.Message = parseSlackLinksToMarkdown(response.EphemeralText)
ephemeralPost.Message = model.ParseSlackLinksToMarkdown(response.EphemeralText)
ephemeralPost.ChannelId = post.ChannelId
ephemeralPost.RootId = post.RootId
if ephemeralPost.RootId == "" {