diff options
author | JoramWilander <jwawilander@gmail.com> | 2015-08-10 14:47:45 -0400 |
---|---|---|
committer | JoramWilander <jwawilander@gmail.com> | 2015-08-11 12:11:35 -0400 |
commit | 6c0fefad152e1843bccf80fb675301b789f70dd5 (patch) | |
tree | e48b601f97cf9f7456e8783082fcb3974691785b /api | |
parent | 1c0ee4d2f65d1d4434a3a16070abe7d61a268ce6 (diff) | |
download | chat-6c0fefad152e1843bccf80fb675301b789f70dd5.tar.gz chat-6c0fefad152e1843bccf80fb675301b789f70dd5.tar.bz2 chat-6c0fefad152e1843bccf80fb675301b789f70dd5.zip |
added getChannelCounts service and refactored the client to more intelligently pull channel data
Diffstat (limited to 'api')
-rw-r--r-- | api/channel.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/api/channel.go b/api/channel.go index a3de30377..851816dde 100644 --- a/api/channel.go +++ b/api/channel.go @@ -18,6 +18,7 @@ func InitChannel(r *mux.Router) { sr := r.PathPrefix("/channels").Subrouter() sr.Handle("/", ApiUserRequiredActivity(getChannels, false)).Methods("GET") sr.Handle("/more", ApiUserRequired(getMoreChannels)).Methods("GET") + sr.Handle("/counts", ApiUserRequiredActivity(getChannelCounts, false)).Methods("GET") sr.Handle("/create", ApiUserRequired(createChannel)).Methods("POST") sr.Handle("/create_direct", ApiUserRequired(createDirectChannel)).Methods("POST") sr.Handle("/update", ApiUserRequired(updateChannel)).Methods("POST") @@ -315,6 +316,22 @@ func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) { } } +func getChannelCounts(c *Context, w http.ResponseWriter, r *http.Request) { + + // user is already in the team + + if result := <-Srv.Store.Channel().GetChannelCounts(c.Session.TeamId, c.Session.UserId); result.Err != nil { + c.Err = model.NewAppError("getChannelCounts", "Unable to get channel counts from the database", result.Err.Message) + return + } else if HandleEtag(result.Data.(*model.ChannelCounts).Etag(), w, r) { + return + } else { + data := result.Data.(*model.ChannelCounts) + w.Header().Set(model.HEADER_ETAG_SERVER, data.Etag()) + w.Write([]byte(data.ToJson())) + } +} + func joinChannel(c *Context, w http.ResponseWriter, r *http.Request) { params := mux.Vars(r) |