summaryrefslogtreecommitdiffstats
path: root/api/post.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-08-26 12:09:01 -0400
committerJoramWilander <jwawilander@gmail.com>2015-08-27 08:21:26 -0400
commit041d89b85a22b0a498a4176d0d26fd5dc84c33f9 (patch)
tree37cc2ca9252b45f6f30ba4e88037a67a700ec0ad /api/post.go
parent8356e25f80bbba3040ceeda5732b8843b8e493c1 (diff)
downloadchat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.tar.gz
chat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.tar.bz2
chat-041d89b85a22b0a498a4176d0d26fd5dc84c33f9.zip
Refactored post handling/updating on both the client and server.
Diffstat (limited to 'api/post.go')
-rw-r--r--api/post.go38
1 files changed, 35 insertions, 3 deletions
diff --git a/api/post.go b/api/post.go
index c013df87f..5363fdf79 100644
--- a/api/post.go
+++ b/api/post.go
@@ -28,6 +28,7 @@ func InitPost(r *mux.Router) {
sr.Handle("/valet_create", ApiUserRequired(createValetPost)).Methods("POST")
sr.Handle("/update", ApiUserRequired(updatePost)).Methods("POST")
sr.Handle("/posts/{offset:[0-9]+}/{limit:[0-9]+}", ApiUserRequiredActivity(getPosts, false)).Methods("GET")
+ sr.Handle("/posts/{time:[0-9]+}", ApiUserRequiredActivity(getPostsSince, false)).Methods("GET")
sr.Handle("/post/{post_id:[A-Za-z0-9]+}", ApiUserRequired(getPost)).Methods("GET")
sr.Handle("/post/{post_id:[A-Za-z0-9]+}/delete", ApiUserRequired(deletePost)).Methods("POST")
}
@@ -545,9 +546,7 @@ func updatePost(c *Context, w http.ResponseWriter, r *http.Request) {
rpost := result.Data.(*model.Post)
message := model.NewMessage(c.Session.TeamId, rpost.ChannelId, c.Session.UserId, model.ACTION_POST_EDITED)
- message.Add("post_id", rpost.Id)
- message.Add("channel_id", rpost.ChannelId)
- message.Add("message", rpost.Message)
+ message.Add("post", rpost.ToJson())
PublishAndForget(message)
@@ -603,6 +602,39 @@ func getPosts(c *Context, w http.ResponseWriter, r *http.Request) {
}
+func getPostsSince(c *Context, w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+
+ id := params["id"]
+ if len(id) != 26 {
+ c.SetInvalidParam("getPostsSince", "channelId")
+ return
+ }
+
+ time, err := strconv.ParseInt(params["time"], 10, 64)
+ if err != nil {
+ c.SetInvalidParam("getPostsSince", "time")
+ return
+ }
+
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, id, c.Session.UserId)
+ pchan := Srv.Store.Post().GetPostsSince(id, time)
+
+ if !c.HasPermissionsToChannel(cchan, "getPostsSince") {
+ return
+ }
+
+ if result := <-pchan; result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ list := result.Data.(*model.PostList)
+
+ w.Write([]byte(list.ToJson()))
+ }
+
+}
+
func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)