APIv4 put /posts/{post_id}/patch (#5883)
* APIv4 put /posts/{post_id}/patch
* Add props and edit permission
Этот коммит содержится в:
коммит произвёл
Corey Hulen
родитель
31830ffc7b
Коммит
2f15523fe8
@@ -1193,6 +1193,16 @@ func (c *Client4) UpdatePost(postId string, post *Post) (*Post, *Response) {
|
||||
}
|
||||
}
|
||||
|
||||
// PatchPost partially updates a post. Any missing fields are not updated.
|
||||
func (c *Client4) PatchPost(postId string, patch *PostPatch) (*Post, *Response) {
|
||||
if r, err := c.DoApiPut(c.GetPostRoute(postId)+"/patch", patch.ToJson()); err != nil {
|
||||
return nil, &Response{StatusCode: r.StatusCode, Error: err}
|
||||
} else {
|
||||
defer closeBody(r)
|
||||
return PostFromJson(r.Body), BuildResponse(r)
|
||||
}
|
||||
}
|
||||
|
||||
// GetPost gets a single post.
|
||||
func (c *Client4) GetPost(postId string, etag string) (*Post, *Response) {
|
||||
if r, err := c.DoApiGet(c.GetPostRoute(postId), etag); err != nil {
|
||||
|
||||
@@ -54,6 +54,14 @@ type Post struct {
|
||||
HasReactions bool `json:"has_reactions,omitempty"`
|
||||
}
|
||||
|
||||
type PostPatch struct {
|
||||
IsPinned *bool `json:"is_pinned"`
|
||||
Message *string `json:"message"`
|
||||
Props *StringInterface `json:"props"`
|
||||
FileIds *StringArray `json:"file_ids"`
|
||||
HasReactions *bool `json:"has_reactions"`
|
||||
}
|
||||
|
||||
func (o *Post) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
@@ -190,3 +198,45 @@ func (o *Post) AddProp(key string, value interface{}) {
|
||||
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
|
||||
}
|
||||
|
||||
func (p *Post) Patch(patch *PostPatch) {
|
||||
if patch.IsPinned != nil {
|
||||
p.IsPinned = *patch.IsPinned
|
||||
}
|
||||
|
||||
if patch.Message != nil {
|
||||
p.Message = *patch.Message
|
||||
}
|
||||
|
||||
if patch.Props != nil {
|
||||
p.Props = *patch.Props
|
||||
}
|
||||
|
||||
if patch.FileIds != nil {
|
||||
p.FileIds = *patch.FileIds
|
||||
}
|
||||
|
||||
if patch.HasReactions != nil {
|
||||
p.HasReactions = *patch.HasReactions
|
||||
}
|
||||
}
|
||||
|
||||
func (o *PostPatch) ToJson() string {
|
||||
b, err := json.Marshal(o)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func PostPatchFromJson(data io.Reader) *PostPatch {
|
||||
decoder := json.NewDecoder(data)
|
||||
var post PostPatch
|
||||
err := decoder.Decode(&post)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &post
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user