diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-03-24 16:46:11 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-24 13:46:11 -0700 |
commit | 69fb47b88bc8d97c4797fa72e60416f8fb658e20 (patch) | |
tree | 263641b645eb1c1403d238c91c470de49a5a516d /api4/post.go | |
parent | 28a78d76074749a3b7f1ef2a56617b0a1c7fd623 (diff) | |
download | chat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.tar.gz chat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.tar.bz2 chat-69fb47b88bc8d97c4797fa72e60416f8fb658e20.zip |
Add query parameters to get posts v4 endpoint (#5858)
* Add since query paremeter to get posts v4 endpoint
* Add query paremeters for before/after to get posts v4 endpoint
Diffstat (limited to 'api4/post.go')
-rw-r--r-- | api4/post.go | 55 |
1 files changed, 49 insertions, 6 deletions
diff --git a/api4/post.go b/api4/post.go index a43f2f20f..329241139 100644 --- a/api4/post.go +++ b/api4/post.go @@ -60,24 +60,67 @@ func getPostsForChannel(c *Context, w http.ResponseWriter, r *http.Request) { return } + afterPost := r.URL.Query().Get("after") + beforePost := r.URL.Query().Get("before") + sinceString := r.URL.Query().Get("since") + + var since int64 + var parseError error + + if len(sinceString) > 0 { + since, parseError = strconv.ParseInt(sinceString, 10, 64) + if parseError != nil { + c.SetInvalidParam("since") + return + } + } + if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) { c.SetPermissionError(model.PERMISSION_READ_CHANNEL) return } - etag := app.GetPostsEtag(c.Params.ChannelId) + var list *model.PostList + var err *model.AppError + etag := "" - if HandleEtag(etag, "Get Posts", w, r) { - return + if since > 0 { + list, err = app.GetPostsSince(c.Params.ChannelId, since) + } else if len(afterPost) > 0 { + etag = app.GetPostsEtag(c.Params.ChannelId) + + if HandleEtag(etag, "Get Posts After", w, r) { + return + } + + list, err = app.GetPostsAfterPost(c.Params.ChannelId, afterPost, c.Params.Page, c.Params.PerPage) + } else if len(beforePost) > 0 { + etag = app.GetPostsEtag(c.Params.ChannelId) + + if HandleEtag(etag, "Get Posts Before", w, r) { + return + } + + list, err = app.GetPostsBeforePost(c.Params.ChannelId, beforePost, c.Params.Page, c.Params.PerPage) + } else { + etag = app.GetPostsEtag(c.Params.ChannelId) + + if HandleEtag(etag, "Get Posts", w, r) { + return + } + + list, err = app.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage) } - if list, err := app.GetPostsPage(c.Params.ChannelId, c.Params.Page, c.Params.PerPage); err != nil { + if err != nil { c.Err = err return - } else { + } + + if len(etag) > 0 { w.Header().Set(model.HEADER_ETAG_SERVER, etag) - w.Write([]byte(list.ToJson())) } + w.Write([]byte(list.ToJson())) } func getPost(c *Context, w http.ResponseWriter, r *http.Request) { |