summaryrefslogtreecommitdiffstats
path: root/model/post.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-03-30 00:06:51 +0900
committerCorey Hulen <corey@hulen.com>2017-03-29 08:06:51 -0700
commit2f15523fe88c3a382abda1e64b2ef962c3ab5128 (patch)
treeb82d0f98d68c16fd23e886072f8a513d8450bef0 /model/post.go
parent31830ffc7b578de643f5748227e4b783ee0782dd (diff)
downloadchat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.tar.gz
chat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.tar.bz2
chat-2f15523fe88c3a382abda1e64b2ef962c3ab5128.zip
APIv4 put /posts/{post_id}/patch (#5883)
* APIv4 put /posts/{post_id}/patch * Add props and edit permission
Diffstat (limited to 'model/post.go')
-rw-r--r--model/post.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/model/post.go b/model/post.go
index c419deb56..0d9651924 100644
--- a/model/post.go
+++ b/model/post.go
@@ -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
+}