[MM-22622] Add Ephemeral response when using mentions without permissions (#13902)
* MM-22282 Add Ephemeral response when using mentions without permission and add new prop to disable mention highlights on client * MM-22622 Make test name test actually what it does and fix comment style * MM-22622 Check ephemeral post created when post create with mentions on API * MM-22622 More tests for App>CreatePost * MM-22622 Make DisableMentionHighlights more concise and rename ephemeral post * MM-22622 Dont send ephemeral message for system message created by user * Trigger build
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
4c7fee7ac8
Коммит
aec606500f
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
@@ -58,6 +59,8 @@ const (
|
||||
POST_PROPS_DELETE_BY = "deleteBy"
|
||||
POST_PROPS_OVERRIDE_ICON_URL = "override_icon_url"
|
||||
POST_PROPS_OVERRIDE_ICON_EMOJI = "override_icon_emoji"
|
||||
|
||||
POST_PROPS_MENTION_HIGHLIGHT_DISABLED = "mentionHighlightDisabled"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
@@ -432,6 +435,34 @@ func (o *Post) ChannelMentions() []string {
|
||||
return ChannelMentions(o.Message)
|
||||
}
|
||||
|
||||
// DisableMentionHighlights disables a posts mention highlighting and returns the first channel mention that was present in the message.
|
||||
func (o *Post) DisableMentionHighlights() string {
|
||||
mention, hasMentions := findAtChannelMention(o.Message)
|
||||
if hasMentions {
|
||||
o.AddProp(POST_PROPS_MENTION_HIGHLIGHT_DISABLED, true)
|
||||
}
|
||||
return mention
|
||||
}
|
||||
|
||||
// DisableMentionHighlights disables mention highlighting for a post patch if required.
|
||||
func (o *PostPatch) DisableMentionHighlights() {
|
||||
if _, hasMentions := findAtChannelMention(*o.Message); hasMentions {
|
||||
if o.Props == nil {
|
||||
o.Props = &StringInterface{}
|
||||
}
|
||||
(*o.Props)[POST_PROPS_MENTION_HIGHLIGHT_DISABLED] = true
|
||||
}
|
||||
}
|
||||
|
||||
func findAtChannelMention(message string) (mention string, found bool) {
|
||||
re := regexp.MustCompile(`(?i)\B@(channel|all|here)\b`)
|
||||
matched := re.FindStringSubmatch(message)
|
||||
if found = (len(matched) > 0); found {
|
||||
mention = strings.ToLower(matched[0])
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (o *Post) Attachments() []*SlackAttachment {
|
||||
if attachments, ok := o.Props["attachments"].([]*SlackAttachment); ok {
|
||||
return attachments
|
||||
|
||||
Ссылка в новой задаче
Block a user