summaryrefslogtreecommitdiffstats
path: root/api4
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-09-11 22:45:31 +0200
committerGitHub <noreply@github.com>2018-09-11 22:45:31 +0200
commite32581aef3253bb0691d6fd678fbf01e86f2c10c (patch)
tree895aff7c6cc2e43a5209bb3c7b19384f13c5b105 /api4
parentd585f9d9a3bd7c272a02e1d3d52990bc6ecb37a3 (diff)
downloadchat-e32581aef3253bb0691d6fd678fbf01e86f2c10c.tar.gz
chat-e32581aef3253bb0691d6fd678fbf01e86f2c10c.tar.bz2
chat-e32581aef3253bb0691d6fd678fbf01e86f2c10c.zip
MM-11725: Add specific autocomplete endpoint for search autocomplete (#9337)
Diffstat (limited to 'api4')
-rw-r--r--api4/channel.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/api4/channel.go b/api4/channel.go
index d497c9793..b29d2a94c 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -22,6 +22,7 @@ func (api *API) InitChannel() {
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.ChannelsForTeam.Handle("/search_autocomplete", api.ApiSessionRequired(autocompleteChannelsForTeamForSearch)).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")
@@ -642,6 +643,30 @@ func autocompleteChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Requ
w.Write([]byte(channels.ToJson()))
}
+func autocompleteChannelsForTeamForSearch(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")
+
+ channels, err := c.App.AutocompleteChannelsForSearch(c.Params.TeamId, c.Session.UserId, name)
+ if err != nil {
+ c.Err = err
+ return
+ }
+
+ // Don't fill in channels props, since unused by client and potentially expensive.
+
+ w.Write([]byte(channels.ToJson()))
+}
+
func searchChannelsForTeam(c *Context, w http.ResponseWriter, r *http.Request) {
c.RequireTeamId()
if c.Err != nil {