MM-29988 - Update exising Post APIs with collapsed threads (#16503)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2e1b578ccd
Коммит
b0bddeb5e6
@@ -2903,8 +2903,12 @@ func (c *Client4) DeletePost(postId string) (bool, *Response) {
|
||||
}
|
||||
|
||||
// GetPostThread gets a post with all the other posts in the same thread.
|
||||
func (c *Client4) GetPostThread(postId string, etag string) (*PostList, *Response) {
|
||||
r, err := c.DoApiGet(c.GetPostRoute(postId)+"/thread", etag)
|
||||
func (c *Client4) GetPostThread(postId string, etag string, collapsedThreads bool) (*PostList, *Response) {
|
||||
url := c.GetPostRoute(postId) + "/thread"
|
||||
if collapsedThreads {
|
||||
url += "?collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(url, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
@@ -2913,8 +2917,11 @@ func (c *Client4) GetPostThread(postId string, etag string) (*PostList, *Respons
|
||||
}
|
||||
|
||||
// GetPostsForChannel gets a page of posts with an array for ordering for a channel.
|
||||
func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag string) (*PostList, *Response) {
|
||||
func (c *Client4) GetPostsForChannel(channelId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v", page, perPage)
|
||||
if collapsedThreads {
|
||||
query += "&collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/posts"+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@@ -2965,8 +2972,11 @@ func (c *Client4) GetFlaggedPostsForUserInChannel(userId string, channelId strin
|
||||
}
|
||||
|
||||
// GetPostsSince gets posts created after a specified time as Unix time in milliseconds.
|
||||
func (c *Client4) GetPostsSince(channelId string, time int64) (*PostList, *Response) {
|
||||
func (c *Client4) GetPostsSince(channelId string, time int64, collapsedThreads bool) (*PostList, *Response) {
|
||||
query := fmt.Sprintf("?since=%v", time)
|
||||
if collapsedThreads {
|
||||
query += "&collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/posts"+query, "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@@ -2976,8 +2986,11 @@ func (c *Client4) GetPostsSince(channelId string, time int64) (*PostList, *Respo
|
||||
}
|
||||
|
||||
// GetPostsAfter gets a page of posts that were posted after the post provided.
|
||||
func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, etag string) (*PostList, *Response) {
|
||||
func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&after=%v", page, perPage, postId)
|
||||
if collapsedThreads {
|
||||
query += "&collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/posts"+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@@ -2987,8 +3000,11 @@ func (c *Client4) GetPostsAfter(channelId, postId string, page, perPage int, eta
|
||||
}
|
||||
|
||||
// GetPostsBefore gets a page of posts that were posted before the post provided.
|
||||
func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, etag string) (*PostList, *Response) {
|
||||
func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, etag string, collapsedThreads bool) (*PostList, *Response) {
|
||||
query := fmt.Sprintf("?page=%v&per_page=%v&before=%v", page, perPage, postId)
|
||||
if collapsedThreads {
|
||||
query += "&collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(c.GetChannelRoute(channelId)+"/posts"+query, etag)
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
@@ -2998,8 +3014,11 @@ func (c *Client4) GetPostsBefore(channelId, postId string, page, perPage int, et
|
||||
}
|
||||
|
||||
// GetPostsAroundLastUnread gets a list of posts around last unread post by a user in a channel.
|
||||
func (c *Client4) GetPostsAroundLastUnread(userId, channelId string, limitBefore, limitAfter int) (*PostList, *Response) {
|
||||
func (c *Client4) GetPostsAroundLastUnread(userId, channelId string, limitBefore, limitAfter int, collapsedThreads bool) (*PostList, *Response) {
|
||||
query := fmt.Sprintf("?limit_before=%v&limit_after=%v", limitBefore, limitAfter)
|
||||
if collapsedThreads {
|
||||
query += "&collapsedThreads=true"
|
||||
}
|
||||
r, err := c.DoApiGet(c.GetUserRoute(userId)+c.GetChannelRoute(channelId)+"/posts/unread"+query, "")
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
|
||||
@@ -99,8 +99,10 @@ type Post struct {
|
||||
HasReactions bool `json:"has_reactions,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:"-"`
|
||||
Metadata *PostMetadata `json:"metadata,omitempty" db:"-"`
|
||||
}
|
||||
|
||||
type PostEphemeral struct {
|
||||
@@ -201,6 +203,8 @@ 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
|
||||
return nil
|
||||
}
|
||||
@@ -225,17 +229,21 @@ func (o *Post) ToUnsanitizedJson() string {
|
||||
}
|
||||
|
||||
type GetPostsSinceOptions struct {
|
||||
ChannelId string
|
||||
Time int64
|
||||
SkipFetchThreads bool
|
||||
ChannelId string
|
||||
Time int64
|
||||
SkipFetchThreads bool
|
||||
CollapsedThreads bool
|
||||
CollapsedThreadsExtended bool
|
||||
}
|
||||
|
||||
type GetPostsOptions struct {
|
||||
ChannelId string
|
||||
PostId string
|
||||
Page int
|
||||
PerPage int
|
||||
SkipFetchThreads bool
|
||||
ChannelId string
|
||||
PostId string
|
||||
Page int
|
||||
PerPage int
|
||||
SkipFetchThreads bool
|
||||
CollapsedThreads bool
|
||||
CollapsedThreadsExtended bool
|
||||
}
|
||||
|
||||
func PostFromJson(data io.Reader) *Post {
|
||||
@@ -357,6 +365,9 @@ func (o *Post) SanitizeProps() {
|
||||
o.DelProp(member)
|
||||
}
|
||||
}
|
||||
for _, p := range o.Participants {
|
||||
p.Sanitize(map[string]bool{})
|
||||
}
|
||||
}
|
||||
|
||||
func (o *Post) PreSave() {
|
||||
|
||||
Ссылка в новой задаче
Block a user