diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-11-29 10:12:59 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-11-29 10:12:59 -0500 |
commit | 02d581c1599c5d50cc507bd2633f1e3c34b1cc84 (patch) | |
tree | 73437f73a8031b8c792e4b6652d1eb2428c6f2d7 /api/user.go | |
parent | ad52183248512b9aafa59b4429364c75e024cf6f (diff) | |
download | chat-02d581c1599c5d50cc507bd2633f1e3c34b1cc84.tar.gz chat-02d581c1599c5d50cc507bd2633f1e3c34b1cc84.tar.bz2 chat-02d581c1599c5d50cc507bd2633f1e3c34b1cc84.zip |
PLT-4697 Update channel switcher to autocomplete all users on the system (#4624)
* Add autocomplete API for system-wide users
* Update channel switcher to autocomplete all users on the system
Diffstat (limited to 'api/user.go')
-rw-r--r-- | api/user.go | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/api/user.go b/api/user.go index 26066dabc..f5f2582b3 100644 --- a/api/user.go +++ b/api/user.go @@ -59,6 +59,7 @@ func InitUser() { BaseRoutes.NeedChannel.Handle("/users/not_in_channel/{offset:[0-9]+}/{limit:[0-9]+}", ApiUserRequired(getProfilesNotInChannel)).Methods("GET") BaseRoutes.Users.Handle("/search", ApiUserRequired(searchUsers)).Methods("POST") BaseRoutes.Users.Handle("/ids", ApiUserRequired(getProfilesByIds)).Methods("POST") + BaseRoutes.Users.Handle("/autocomplete", ApiUserRequired(autocompleteUsers)).Methods("GET") BaseRoutes.NeedTeam.Handle("/users/autocomplete", ApiUserRequired(autocompleteUsersInTeam)).Methods("GET") BaseRoutes.NeedChannel.Handle("/users/autocomplete", ApiUserRequired(autocompleteUsersInChannel)).Methods("GET") @@ -2780,3 +2781,24 @@ func autocompleteUsersInTeam(c *Context, w http.ResponseWriter, r *http.Request) w.Write([]byte(autocomplete.ToJson())) } + +func autocompleteUsers(c *Context, w http.ResponseWriter, r *http.Request) { + term := r.URL.Query().Get("term") + + uchan := Srv.Store.User().Search("", term, map[string]bool{}) + + var profiles []*model.User + + if result := <-uchan; result.Err != nil { + c.Err = result.Err + return + } else { + profiles = result.Data.([]*model.User) + + for _, p := range profiles { + sanitizeProfile(c, p) + } + } + + w.Write([]byte(model.UserListToJson(profiles))) +} |