diff options
author | Chris <ccbrown112@gmail.com> | 2018-01-31 08:26:40 -0600 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-01-31 09:26:40 -0500 |
commit | e0ee73ef9963ab398bcc6011795ad23e8e003147 (patch) | |
tree | 37c773074588792a3badd2a68dfbbdbfa459164d /api4/channel.go | |
parent | 0c8968fb8df4ce302c928118cd81e75f5bef2861 (diff) | |
download | chat-e0ee73ef9963ab398bcc6011795ad23e8e003147.tar.gz chat-e0ee73ef9963ab398bcc6011795ad23e8e003147.tar.bz2 chat-e0ee73ef9963ab398bcc6011795ad23e8e003147.zip |
ABC-79: Optimize channel autocomplete query (#8163)
* optimize channel autocomplete query
* move to new autocomplete endpoint
Diffstat (limited to 'api4/channel.go')
-rw-r--r-- | api4/channel.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go index 9801c9dc0..29dff883f 100644 --- a/api4/channel.go +++ b/api4/channel.go @@ -20,6 +20,7 @@ func (api *API) InitChannel() { api.BaseRoutes.ChannelsForTeam.Handle("/deleted", api.ApiSessionRequired(getDeletedChannelsForTeam)).Methods("GET") api.BaseRoutes.ChannelsForTeam.Handle("/ids", api.ApiSessionRequired(getPublicChannelsByIdsForTeam)).Methods("POST") api.BaseRoutes.ChannelsForTeam.Handle("/search", api.ApiSessionRequired(searchChannelsForTeam)).Methods("POST") + api.BaseRoutes.ChannelsForTeam.Handle("/autocomplete", api.ApiSessionRequired(autocompleteChannelsForTeam)).Methods("GET") api.BaseRoutes.User.Handle("/teams/{team_id:[A-Za-z0-9]+}/channels", api.ApiSessionRequired(getChannelsForTeamForUser)).Methods("GET") api.BaseRoutes.Channel.Handle("", api.ApiSessionRequired(getChannel)).Methods("GET") @@ -489,6 +490,27 @@ func getChannelsForTeamForUser(c *Context, w http.ResponseWriter, r *http.Reques } } +func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { + c.RequireTeamId() + if c.Err != nil { + return + } + + if !c.App.SessionHasPermissionToTeam(c.Session, c.Params.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) { + c.SetPermissionError(model.PERMISSION_LIST_TEAM_CHANNELS) + return + } + + name := r.URL.Query().Get("name") + + if channels, err := c.App.AutocompleteChannels(c.Params.TeamId, name); err != nil { + c.Err = err + return + } else { + w.Write([]byte(channels.ToJson())) + } +} + func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) { c.RequireTeamId() if c.Err != nil { |