diff options
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 { |