summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/mattermost/mattermost-server/v5/model/post.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2021-10-17 00:47:22 +0200
committerGitHub <noreply@github.com>2021-10-17 00:47:22 +0200
commit4dd8bae5c91fa4aef09d865d8fef1acd84f90925 (patch)
treeffad9b242daccaf8c86d1c1fbd59032302bd3be9 /vendor/github.com/mattermost/mattermost-server/v5/model/post.go
parent7ae45c42e712bd0e66c101f3f714c05aa1dc2104 (diff)
downloadmatterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.gz
matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.tar.bz2
matterbridge-msglm-4dd8bae5c91fa4aef09d865d8fef1acd84f90925.zip
Update dependencies (#1610)
* Update dependencies * Update module to go 1.17
Diffstat (limited to 'vendor/github.com/mattermost/mattermost-server/v5/model/post.go')
-rw-r--r--vendor/github.com/mattermost/mattermost-server/v5/model/post.go116
1 files changed, 100 insertions, 16 deletions
diff --git a/vendor/github.com/mattermost/mattermost-server/v5/model/post.go b/vendor/github.com/mattermost/mattermost-server/v5/model/post.go
index 6e29ba3e..b7dff5bc 100644
--- a/vendor/github.com/mattermost/mattermost-server/v5/model/post.go
+++ b/vendor/github.com/mattermost/mattermost-server/v5/model/post.go
@@ -14,7 +14,7 @@ import (
"sync"
"unicode/utf8"
- "github.com/mattermost/mattermost-server/v5/utils/markdown"
+ "github.com/mattermost/mattermost-server/v5/shared/markdown"
)
const (
@@ -45,7 +45,7 @@ const (
POST_EPHEMERAL = "system_ephemeral"
POST_CHANGE_CHANNEL_PRIVACY = "system_change_chan_privacy"
POST_ADD_BOT_TEAMS_CHANNELS = "add_bot_teams_channels"
- POST_FILEIDS_MAX_RUNES = 150
+ POST_FILEIDS_MAX_RUNES = 300
POST_FILENAMES_MAX_RUNES = 4000
POST_HASHTAGS_MAX_RUNES = 1000
POST_MESSAGE_MAX_RUNES_V1 = 4000
@@ -96,10 +96,14 @@ type Post struct {
FileIds StringArray `json:"file_ids,omitempty"`
PendingPostId string `json:"pending_post_id" db:"-"`
HasReactions bool `json:"has_reactions,omitempty"`
+ RemoteId *string `json:"remote_id,omitempty"`
// Transient data populated before sending a post to the client
- ReplyCount int64 `json:"reply_count" db:"-"`
- Metadata *PostMetadata `json:"metadata,omitempty" db:"-"`
+ ReplyCount int64 `json:"reply_count" db:"-"`
+ LastReplyAt int64 `json:"last_reply_at" db:"-"`
+ Participants []*User `json:"participants" db:"-"`
+ IsFollowing *bool `json:"is_following,omitempty" db:"-"` // for root posts in collapsed thread mode indicates if the current user is following this thread
+ Metadata *PostMetadata `json:"metadata,omitempty" db:"-"`
}
type PostEphemeral struct {
@@ -163,6 +167,12 @@ type PostForIndexing struct {
ParentCreateAt *int64 `json:"parent_create_at"`
}
+type FileForIndexing struct {
+ FileInfo
+ ChannelId string `json:"channel_id"`
+ Content string `json:"content"`
+}
+
// ShallowCopy is an utility function to shallow copy a Post to the given
// destination without touching the internal RWMutex.
func (o *Post) ShallowCopy(dst *Post) error {
@@ -194,7 +204,13 @@ func (o *Post) ShallowCopy(dst *Post) error {
dst.PendingPostId = o.PendingPostId
dst.HasReactions = o.HasReactions
dst.ReplyCount = o.ReplyCount
+ dst.Participants = o.Participants
+ dst.LastReplyAt = o.LastReplyAt
dst.Metadata = o.Metadata
+ if o.IsFollowing != nil {
+ dst.IsFollowing = NewBool(*o.IsFollowing)
+ }
+ dst.RemoteId = o.RemoteId
return nil
}
@@ -218,17 +234,35 @@ func (o *Post) ToUnsanitizedJson() string {
}
type GetPostsSinceOptions struct {
- ChannelId string
- Time int64
- SkipFetchThreads bool
+ UserId string
+ ChannelId string
+ Time int64
+ SkipFetchThreads bool
+ CollapsedThreads bool
+ CollapsedThreadsExtended bool
+ SortAscending bool
+}
+
+type GetPostsSinceForSyncCursor struct {
+ LastPostUpdateAt int64
+ LastPostId string
+}
+
+type GetPostsSinceForSyncOptions struct {
+ ChannelId string
+ ExcludeRemoteId string
+ IncludeDeleted bool
}
type GetPostsOptions struct {
- ChannelId string
- PostId string
- Page int
- PerPage int
- SkipFetchThreads bool
+ UserId string
+ ChannelId string
+ PostId string
+ Page int
+ PerPage int
+ SkipFetchThreads bool
+ CollapsedThreads bool
+ CollapsedThreadsExtended bool
}
func PostFromJson(data io.Reader) *Post {
@@ -262,19 +296,19 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
return NewAppError("Post.IsValid", "model.post.is_valid.channel_id.app_error", nil, "", http.StatusBadRequest)
}
- if !(IsValidId(o.RootId) || len(o.RootId) == 0) {
+ if !(IsValidId(o.RootId) || o.RootId == "") {
return NewAppError("Post.IsValid", "model.post.is_valid.root_id.app_error", nil, "", http.StatusBadRequest)
}
- if !(IsValidId(o.ParentId) || len(o.ParentId) == 0) {
+ if !(IsValidId(o.ParentId) || o.ParentId == "") {
return NewAppError("Post.IsValid", "model.post.is_valid.parent_id.app_error", nil, "", http.StatusBadRequest)
}
- if len(o.ParentId) == 26 && len(o.RootId) == 0 {
+ if len(o.ParentId) == 26 && o.RootId == "" {
return NewAppError("Post.IsValid", "model.post.is_valid.root_parent.app_error", nil, "", http.StatusBadRequest)
}
- if !(len(o.OriginalId) == 26 || len(o.OriginalId) == 0) {
+ if !(len(o.OriginalId) == 26 || o.OriginalId == "") {
return NewAppError("Post.IsValid", "model.post.is_valid.original_id.app_error", nil, "", http.StatusBadRequest)
}
@@ -337,6 +371,9 @@ func (o *Post) IsValid(maxPostSize int) *AppError {
}
func (o *Post) SanitizeProps() {
+ if o == nil {
+ return
+ }
membersToSanitize := []string{
PROPS_ADD_CHANNEL_MEMBER,
}
@@ -346,6 +383,9 @@ func (o *Post) SanitizeProps() {
o.DelProp(member)
}
}
+ for _, p := range o.Participants {
+ p.Sanitize(map[string]bool{})
+ }
}
func (o *Post) PreSave() {
@@ -432,6 +472,19 @@ func (o *Post) IsSystemMessage() bool {
return len(o.Type) >= len(POST_SYSTEM_MESSAGE_PREFIX) && o.Type[:len(POST_SYSTEM_MESSAGE_PREFIX)] == POST_SYSTEM_MESSAGE_PREFIX
}
+// IsRemote returns true if the post originated on a remote cluster.
+func (o *Post) IsRemote() bool {
+ return o.RemoteId != nil && *o.RemoteId != ""
+}
+
+// GetRemoteID safely returns the remoteID or empty string if not remote.
+func (o *Post) GetRemoteID() string {
+ if o.RemoteId != nil {
+ return *o.RemoteId
+ }
+ return ""
+}
+
func (o *Post) IsJoinLeaveMessage() bool {
return o.Type == POST_JOIN_LEAVE ||
o.Type == POST_ADD_REMOVE ||
@@ -552,6 +605,25 @@ func (o *Post) Attachments() []*SlackAttachment {
if enc, err := json.Marshal(attachment); err == nil {
var decoded SlackAttachment
if json.Unmarshal(enc, &decoded) == nil {
+ // Ignoring nil actions
+ i := 0
+ for _, action := range decoded.Actions {
+ if action != nil {
+ decoded.Actions[i] = action
+ i++
+ }
+ }
+ decoded.Actions = decoded.Actions[:i]
+
+ // Ignoring nil fields
+ i = 0
+ for _, field := range decoded.Fields {
+ if field != nil {
+ decoded.Fields[i] = field
+ i++
+ }
+ }
+ decoded.Fields = decoded.Fields[:i]
ret = append(ret, &decoded)
}
}
@@ -665,3 +737,15 @@ func RewriteImageURLs(message string, f func(string) string) string {
return string(result)
}
+
+func (o *Post) IsFromOAuthBot() bool {
+ props := o.GetProps()
+ return props["from_webhook"] == "true" && props["override_username"] != ""
+}
+
+func (o *Post) ToNilIfInvalid() *Post {
+ if o.Id == "" {
+ return nil
+ }
+ return o
+}