diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-30 00:09:05 +0900 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2017-03-29 08:09:05 -0700 |
commit | 8a31718db11c803fa3b14f85c760ca9db6083670 (patch) | |
tree | 80a006c8994ef57ccd6d09fc7b0d00ebe6969f39 /api4/channel.go | |
parent | 64f80decaf4c20c643e43426e3c4285b2d501a90 (diff) | |
download | chat-8a31718db11c803fa3b14f85c760ca9db6083670.tar.gz chat-8a31718db11c803fa3b14f85c760ca9db6083670.tar.bz2 chat-8a31718db11c803fa3b14f85c760ca9db6083670.zip |
APIv4 get /channels/{channel_id}/pinned (#5893)
Diffstat (limited to 'api4/channel.go')
-rw-r--r-- | api4/channel.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go index 278bf1d2e..ea4f2783a 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -29,6 +29,7 @@ func InitChannel() { BaseRoutes.Channel.Handle("/patch", ApiSessionRequired(patchChannel)).Methods("PUT") BaseRoutes.Channel.Handle("", ApiSessionRequired(deleteChannel)).Methods("DELETE") BaseRoutes.Channel.Handle("/stats", ApiSessionRequired(getChannelStats)).Methods("GET") + BaseRoutes.Channel.Handle("/pinned", ApiSessionRequired(getPinnedPosts)).Methods("GET") BaseRoutes.ChannelForUser.Handle("/unread", ApiSessionRequired(getChannelUnread)).Methods("GET") @@ -303,6 +304,28 @@ func getChannelStats(c *Context, w http.ResponseWriter, r *http.Request) { w.Write([]byte(stats.ToJson())) } +func getPinnedPosts(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireChannelId() + if c.Err != nil { + return + } + + if !app.SessionHasPermissionToChannel(c.Session, c.Params.ChannelId, model.PERMISSION_READ_CHANNEL) { + c.SetPermissionError(model.PERMISSION_READ_CHANNEL) + return + } + + if posts, err := app.GetPinnedPosts(c.Params.ChannelId); err != nil { + c.Err = err + return + } else if HandleEtag(posts.Etag(), "Get Pinned Posts", w, r) { + return + } else { + w.Header().Set(model.HEADER_ETAG_SERVER, posts.Etag()) + w.Write([]byte(posts.ToJson())) + } +} + func getPublicChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId() if c.Err != nil { |