summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-11-18 17:29:06 -0500
committerChristopher Speller <crspeller@gmail.com>2015-11-23 09:53:15 -0500
commit9e8cd937908d5d2e730e94f761d6533eb2d95e28 (patch)
treefb6324a5896da7123b76854e7eb504c239113824 /api
parent5ee226d7f92d9408736b0e2a9ff105eb6f520a19 (diff)
downloadchat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.tar.gz
chat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.tar.bz2
chat-9e8cd937908d5d2e730e94f761d6533eb2d95e28.zip
Implementing Permalinks and jumping to post from search. Performance
improvements.
Diffstat (limited to 'api')
-rw-r--r--api/context.go2
-rw-r--r--api/post.go36
2 files changed, 38 insertions, 0 deletions
diff --git a/api/context.go b/api/context.go
index a5d4169cb..a6f9bc1e1 100644
--- a/api/context.go
+++ b/api/context.go
@@ -37,6 +37,8 @@ type Page struct {
ClientCfg map[string]string
User *model.User
Team *model.Team
+ Channel *model.Channel
+ PostID string
SessionTokenIndex int64
}
diff --git a/api/post.go b/api/post.go
index 0860fd299..ca99eb15b 100644
--- a/api/post.go
+++ b/api/post.go
@@ -23,6 +23,7 @@ func InitPost(r *mux.Router) {
l4g.Debug("Initializing post api routes")
r.Handle("/posts/search", ApiUserRequired(searchPosts)).Methods("GET")
+ r.Handle("/posts/{post_id}", ApiUserRequired(getPostById)).Methods("GET")
sr := r.PathPrefix("/channels/{id:[A-Za-z0-9]+}").Subrouter()
sr.Handle("/create", ApiUserRequired(createPost)).Methods("POST")
@@ -767,6 +768,41 @@ func getPost(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+func getPostById(c *Context, w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+
+ postId := params["post_id"]
+ if len(postId) != 26 {
+ c.SetInvalidParam("getPostById", "postId")
+ return
+ }
+
+ if result := <-Srv.Store.Post().Get(postId); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ list := result.Data.(*model.PostList)
+
+ if len(list.Order) != 1 {
+ c.Err = model.NewAppError("getPostById", "Unable to get post", "")
+ return
+ }
+ post := list.Posts[list.Order[0]]
+
+ cchan := Srv.Store.Channel().CheckPermissionsTo(c.Session.TeamId, post.ChannelId, c.Session.UserId)
+ if !c.HasPermissionsToChannel(cchan, "getPostById") {
+ return
+ }
+
+ if HandleEtag(list.Etag(), w, r) {
+ return
+ }
+
+ w.Header().Set(model.HEADER_ETAG_SERVER, list.Etag())
+ w.Write([]byte(list.ToJson()))
+ }
+}
+
func deletePost(c *Context, w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)