diff --git a/api/api.go b/api/api.go
index eea70c9b56..3af23b9e0d 100644
--- a/api/api.go
+++ b/api/api.go
@@ -103,6 +103,7 @@ func InitApi() {
InitEmoji()
InitStatus()
InitWebrtc()
+ InitDeprecated()
// 404 on any api route before web.go has a chance to serve it
Srv.Router.Handle("/api/{anything:.*}", http.HandlerFunc(Handle404))
diff --git a/api/channel.go b/api/channel.go
index 9ec556fe68..0ffe9a668c 100644
--- a/api/channel.go
+++ b/api/channel.go
@@ -6,6 +6,7 @@ package api
import (
"fmt"
"net/http"
+ "strconv"
"strings"
l4g "github.com/alecthomas/log4go"
@@ -19,7 +20,8 @@ func InitChannel() {
l4g.Debug(utils.T("api.channel.init.debug"))
BaseRoutes.Channels.Handle("/", ApiUserRequired(getChannels)).Methods("GET")
- BaseRoutes.Channels.Handle("/more", ApiUserRequired(getMoreChannels)).Methods("GET")
+ BaseRoutes.Channels.Handle("/more/{offset:[0-9]+}/{limit:[0-9]+}", ApiUserRequired(getMoreChannelsPage)).Methods("GET")
+ BaseRoutes.Channels.Handle("/more/search", ApiUserRequired(searchMoreChannels)).Methods("POST")
BaseRoutes.Channels.Handle("/counts", ApiUserRequired(getChannelCounts)).Methods("GET")
BaseRoutes.Channels.Handle("/members", ApiUserRequired(getMyChannelMembers)).Methods("GET")
BaseRoutes.Channels.Handle("/create", ApiUserRequired(createChannel)).Methods("POST")
@@ -28,6 +30,7 @@ func InitChannel() {
BaseRoutes.Channels.Handle("/update_header", ApiUserRequired(updateChannelHeader)).Methods("POST")
BaseRoutes.Channels.Handle("/update_purpose", ApiUserRequired(updateChannelPurpose)).Methods("POST")
BaseRoutes.Channels.Handle("/update_notify_props", ApiUserRequired(updateNotifyProps)).Methods("POST")
+ BaseRoutes.Channels.Handle("/autocomplete", ApiUserRequired(autocompleteChannels)).Methods("GET")
BaseRoutes.NeedChannelName.Handle("/join", ApiUserRequired(join)).Methods("POST")
@@ -41,6 +44,7 @@ func InitChannel() {
BaseRoutes.NeedChannel.Handle("/remove", ApiUserRequired(removeMember)).Methods("POST")
BaseRoutes.NeedChannel.Handle("/update_last_viewed_at", ApiUserRequired(updateLastViewedAt)).Methods("POST")
BaseRoutes.NeedChannel.Handle("/set_last_viewed_at", ApiUserRequired(setLastViewedAt)).Methods("POST")
+
}
func createChannel(c *Context, w http.ResponseWriter, r *http.Request) {
@@ -416,18 +420,29 @@ func getChannels(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
-func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
+func getMoreChannelsPage(c *Context, w http.ResponseWriter, r *http.Request) {
+ params := mux.Vars(r)
+
+ offset, err := strconv.Atoi(params["offset"])
+ if err != nil {
+ c.SetInvalidParam("getProfiles", "offset")
+ return
+ }
+
+ limit, err := strconv.Atoi(params["limit"])
+ if err != nil {
+ c.SetInvalidParam("getProfiles", "limit")
+ return
+ }
// user is already in the team
if !HasPermissionToTeamContext(c, c.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
return
}
- if result := <-Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId, offset, limit); result.Err != nil {
c.Err = result.Err
return
- } else if HandleEtag(result.Data.(*model.ChannelList).Etag(), w, r) {
- return
} else {
data := result.Data.(*model.ChannelList)
w.Header().Set(model.HEADER_ETAG_SERVER, data.Etag())
@@ -1182,3 +1197,51 @@ func updateNotifyProps(c *Context, w http.ResponseWriter, r *http.Request) {
}
}
+
+func searchMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
+ props := model.ChannelSearchFromJson(r.Body)
+ if props == nil {
+ c.SetInvalidParam("searchMoreChannels", "")
+ return
+ }
+
+ if c.Session.GetTeamByTeamId(c.TeamId) == nil {
+ if !HasPermissionToContext(c, model.PERMISSION_MANAGE_SYSTEM) {
+ return
+ }
+ }
+
+ if len(props.Term) == 0 {
+ c.SetInvalidParam("searchMoreChannels", "term")
+ return
+ }
+
+ if result := <-Srv.Store.Channel().SearchMore(c.Session.UserId, c.TeamId, props.Term); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ w.Write([]byte(channels.ToJson()))
+ }
+}
+
+func autocompleteChannels(c *Context, w http.ResponseWriter, r *http.Request) {
+ term := r.URL.Query().Get("term")
+
+ if c.Session.GetTeamByTeamId(c.TeamId) == nil {
+ if !HasPermissionToContext(c, model.PERMISSION_MANAGE_SYSTEM) {
+ return
+ }
+ }
+
+ var channels *model.ChannelList
+
+ if result := <-Srv.Store.Channel().SearchInTeam(c.TeamId, term); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else {
+ channels = result.Data.(*model.ChannelList)
+ }
+
+ w.Write([]byte(channels.ToJson()))
+}
diff --git a/api/channel_test.go b/api/channel_test.go
index 4b0ce9509b..611fa93397 100644
--- a/api/channel_test.go
+++ b/api/channel_test.go
@@ -705,7 +705,7 @@ func TestGetChannel(t *testing.T) {
}
}
-func TestGetMoreChannel(t *testing.T) {
+func TestGetMoreChannelsPage(t *testing.T) {
th := Setup().InitBasic()
Client := th.BasicClient
team := th.BasicTeam
@@ -713,28 +713,64 @@ func TestGetMoreChannel(t *testing.T) {
channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
- channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "b" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+ channel3 := &model.Channel{DisplayName: "C Test API Name", Name: "c" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
+ channel3 = Client.Must(Client.CreateChannel(channel3)).Data.(*model.Channel)
+
th.LoginBasic2()
- rget := Client.Must(Client.GetMoreChannels(""))
- channels := rget.Data.(*model.ChannelList)
-
- if (*channels)[0].DisplayName != channel1.DisplayName {
- t.Fatal("full name didn't match")
- }
-
- if (*channels)[1].DisplayName != channel2.DisplayName {
- t.Fatal("full name didn't match")
- }
-
- // test etag caching
- if cache_result, err := Client.GetMoreChannels(rget.Etag); err != nil {
+ if r, err := Client.GetMoreChannelsPage(0, 100); err != nil {
t.Fatal(err)
- } else if cache_result.Data.(*model.ChannelList) != nil {
- t.Log(cache_result.Data)
- t.Fatal("cache should be empty")
+ } else {
+ channels := r.Data.(*model.ChannelList)
+
+ // 1 for BasicChannel, 2 for open channels created above
+ if len(*channels) != 3 {
+ t.Fatal("wrong length")
+ }
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+
+ if (*channels)[1].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if r, err := Client.GetMoreChannelsPage(0, 1); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := r.Data.(*model.ChannelList)
+
+ if len(*channels) != 1 {
+ t.Fatal("wrong length")
+ }
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if r, err := Client.GetMoreChannelsPage(1, 1); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := r.Data.(*model.ChannelList)
+
+ if len(*channels) != 1 {
+ t.Fatal("wrong length")
+ }
+
+ if (*channels)[0].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ Client.SetTeamId("junk")
+ if _, err := Client.GetMoreChannelsPage(0, 1); err == nil {
+ t.Fatal("should have failed - bad team id")
}
}
@@ -1448,3 +1484,148 @@ func TestGetChannelMember(t *testing.T) {
t.Fatal("should have failed - bad channel and user id")
}
}
+
+func TestSearchMoreChannels(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+ team := th.BasicTeam
+
+ channel1 := &model.Channel{DisplayName: "TestAPINameA", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+
+ channel2 := &model.Channel{DisplayName: "TestAPINameB", Name: "b" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+
+ th.LoginBasic2()
+
+ if result, err := Client.SearchMoreChannels(model.ChannelSearch{Term: "TestAPIName"}); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+
+ if (*channels)[1].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if result, err := Client.SearchMoreChannels(model.ChannelSearch{Term: "TestAPINameA"}); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if result, err := Client.SearchMoreChannels(model.ChannelSearch{Term: "TestAPINameB"}); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if result, err := Client.SearchMoreChannels(model.ChannelSearch{Term: channel1.Name}); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if _, err := Client.SearchMoreChannels(model.ChannelSearch{Term: ""}); err == nil {
+ t.Fatal("should have errored - empty term")
+ }
+
+ if result, err := Client.SearchMoreChannels(model.ChannelSearch{Term: "blargh"}); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if len(*channels) != 0 {
+ t.Fatal("should have no channels")
+ }
+ }
+
+ Client.SetTeamId("junk")
+ if _, err := Client.SearchMoreChannels(model.ChannelSearch{Term: "blargh"}); err == nil {
+ t.Fatal("should have errored - bad team id")
+ }
+}
+
+func TestAutocompleteChannels(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ Client := th.BasicClient
+ team := th.BasicTeam
+
+ channel1 := &model.Channel{DisplayName: "TestAPINameA", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+
+ channel2 := &model.Channel{DisplayName: "TestAPINameB", Name: "b" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+
+ channel3 := &model.Channel{DisplayName: "BadChannelC", Name: "c" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: model.NewId()}
+ channel3 = th.SystemAdminClient.Must(th.SystemAdminClient.CreateChannel(channel3)).Data.(*model.Channel)
+
+ channel4 := &model.Channel{DisplayName: "BadChannelD", Name: "d" + model.NewId() + "a", Type: model.CHANNEL_PRIVATE, TeamId: team.Id}
+ channel4 = Client.Must(Client.CreateChannel(channel4)).Data.(*model.Channel)
+
+ if result, err := Client.AutocompleteChannels("TestAPIName"); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+
+ if (*channels)[1].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if result, err := Client.AutocompleteChannels(channel1.Name); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+ }
+
+ if result, err := Client.AutocompleteChannels("BadChannelC"); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if len(*channels) != 0 {
+ t.Fatal("should have been empty")
+ }
+ }
+
+ if result, err := Client.AutocompleteChannels("BadChannelD"); err != nil {
+ t.Fatal(err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+
+ if len(*channels) != 0 {
+ t.Fatal("should have been empty")
+ }
+ }
+
+ Client.SetTeamId("junk")
+
+ if _, err := Client.AutocompleteChannels("BadChannelD"); err == nil {
+ t.Fatal("should have failed - bad team id")
+ }
+}
diff --git a/api/command_join.go b/api/command_join.go
index 2aba1bbd52..0499d503d8 100644
--- a/api/command_join.go
+++ b/api/command_join.go
@@ -33,25 +33,22 @@ func (me *JoinProvider) GetCommand(c *Context) *model.Command {
}
func (me *JoinProvider) DoCommand(c *Context, channelId string, message string) *model.CommandResponse {
- if result := <-Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId); result.Err != nil {
+ if result := <-Srv.Store.Channel().GetByName(c.TeamId, message); result.Err != nil {
return &model.CommandResponse{Text: c.T("api.command_join.list.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
} else {
- channels := result.Data.(*model.ChannelList)
+ channel := result.Data.(*model.Channel)
- for _, v := range *channels {
+ if channel.Name == message {
- if v.Name == message {
-
- if v.Type != model.CHANNEL_OPEN {
- return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
- }
-
- if err, _ := JoinChannelById(c, c.Session.UserId, v.Id); err != nil {
- return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
- }
-
- return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + v.Name, Text: c.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ if channel.Type != model.CHANNEL_OPEN {
+ return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
+
+ if err, _ := JoinChannelById(c, c.Session.UserId, channel.Id); err != nil {
+ return &model.CommandResponse{Text: c.T("api.command_join.fail.app_error"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
+ }
+
+ return &model.CommandResponse{GotoLocation: c.GetTeamURL() + "/channels/" + channel.Name, Text: c.T("api.command_join.success"), ResponseType: model.COMMAND_RESPONSE_TYPE_EPHEMERAL}
}
}
diff --git a/api/deprecated.go b/api/deprecated.go
new file mode 100644
index 0000000000..955613faba
--- /dev/null
+++ b/api/deprecated.go
@@ -0,0 +1,39 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api
+
+import (
+ "net/http"
+
+ l4g "github.com/alecthomas/log4go"
+ "github.com/mattermost/platform/model"
+ "github.com/mattermost/platform/utils"
+)
+
+// ONLY FOR APIs SCHEDULED TO BE DEPRECATED
+
+func InitDeprecated() {
+ l4g.Debug(utils.T("api.channel.init.debug"))
+
+ BaseRoutes.Channels.Handle("/more", ApiUserRequired(getMoreChannels)).Methods("GET") // SCHEDULED FOR DEPRECATION IN 3.7
+}
+
+func getMoreChannels(c *Context, w http.ResponseWriter, r *http.Request) {
+
+ // user is already in the team
+ if !HasPermissionToTeamContext(c, c.TeamId, model.PERMISSION_LIST_TEAM_CHANNELS) {
+ return
+ }
+
+ if result := <-Srv.Store.Channel().GetMoreChannels(c.TeamId, c.Session.UserId, 0, 100000); result.Err != nil {
+ c.Err = result.Err
+ return
+ } else if HandleEtag(result.Data.(*model.ChannelList).Etag(), w, r) {
+ return
+ } else {
+ data := result.Data.(*model.ChannelList)
+ w.Header().Set(model.HEADER_ETAG_SERVER, data.Etag())
+ w.Write([]byte(data.ToJson()))
+ }
+}
diff --git a/api/deprecated_test.go b/api/deprecated_test.go
new file mode 100644
index 0000000000..000b3950d8
--- /dev/null
+++ b/api/deprecated_test.go
@@ -0,0 +1,43 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package api
+
+import (
+ "testing"
+
+ "github.com/mattermost/platform/model"
+)
+
+func TestGetMoreChannel(t *testing.T) {
+ th := Setup().InitBasic()
+ Client := th.BasicClient
+ team := th.BasicTeam
+
+ channel1 := &model.Channel{DisplayName: "A Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
+
+ channel2 := &model.Channel{DisplayName: "B Test API Name", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
+ channel2 = Client.Must(Client.CreateChannel(channel2)).Data.(*model.Channel)
+
+ th.LoginBasic2()
+
+ rget := Client.Must(Client.GetMoreChannels(""))
+ channels := rget.Data.(*model.ChannelList)
+
+ if (*channels)[0].DisplayName != channel1.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+
+ if (*channels)[1].DisplayName != channel2.DisplayName {
+ t.Fatal("full name didn't match")
+ }
+
+ // test etag caching
+ if cache_result, err := Client.GetMoreChannels(rget.Etag); err != nil {
+ t.Fatal(err)
+ } else if cache_result.Data.(*model.ChannelList) != nil {
+ t.Log(cache_result.Data)
+ t.Fatal("cache should be empty")
+ }
+}
diff --git a/api/user.go b/api/user.go
index 3a303bee42..26066dabc8 100644
--- a/api/user.go
+++ b/api/user.go
@@ -2712,8 +2712,8 @@ func autocompleteUsersInChannel(c *Context, w http.ResponseWriter, r *http.Reque
searchOptions := map[string]bool{}
searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true
- uchan := Srv.Store.User().SearchInChannel(channelId, term, map[string]bool{})
- nuchan := Srv.Store.User().SearchNotInChannel(teamId, channelId, term, map[string]bool{})
+ uchan := Srv.Store.User().SearchInChannel(channelId, term, searchOptions)
+ nuchan := Srv.Store.User().SearchNotInChannel(teamId, channelId, term, searchOptions)
autocomplete := &model.UserAutocompleteInChannel{}
@@ -2758,7 +2758,10 @@ func autocompleteUsersInTeam(c *Context, w http.ResponseWriter, r *http.Request)
}
}
- uchan := Srv.Store.User().Search(teamId, term, map[string]bool{})
+ searchOptions := map[string]bool{}
+ searchOptions[store.USER_SEARCH_OPTION_NAMES_ONLY] = true
+
+ uchan := Srv.Store.User().Search(teamId, term, searchOptions)
autocomplete := &model.UserAutocompleteInTeam{}
diff --git a/i18n/en.json b/i18n/en.json
index 734145e75a..6f82c9c163 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -4035,6 +4035,10 @@
"id": "store.sql_channel.analytics_type_count.app_error",
"translation": "We couldn't get channel type counts"
},
+ {
+ "id": "store.sql_channel.search.app_error",
+ "translation": "We encountered an error searching channels"
+ },
{
"id": "store.sql_channel.check_open_channel_permissions.app_error",
"translation": "We couldn't check the permissions"
diff --git a/model/channel_search.go b/model/channel_search.go
new file mode 100644
index 0000000000..2c041503d8
--- /dev/null
+++ b/model/channel_search.go
@@ -0,0 +1,35 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "encoding/json"
+ "io"
+)
+
+type ChannelSearch struct {
+ Term string `json:"term"`
+}
+
+// ToJson convert a Channel to a json string
+func (c *ChannelSearch) ToJson() string {
+ b, err := json.Marshal(c)
+ if err != nil {
+ return ""
+ } else {
+ return string(b)
+ }
+}
+
+// ChannelSearchFromJson will decode the input and return a Channel
+func ChannelSearchFromJson(data io.Reader) *ChannelSearch {
+ decoder := json.NewDecoder(data)
+ var cs ChannelSearch
+ err := decoder.Decode(&cs)
+ if err == nil {
+ return &cs
+ } else {
+ return nil
+ }
+}
diff --git a/model/channel_search_test.go b/model/channel_search_test.go
new file mode 100644
index 0000000000..f7f6d66f75
--- /dev/null
+++ b/model/channel_search_test.go
@@ -0,0 +1,19 @@
+// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+package model
+
+import (
+ "strings"
+ "testing"
+)
+
+func TestChannelSearchJson(t *testing.T) {
+ channelSearch := ChannelSearch{Term: NewId()}
+ json := channelSearch.ToJson()
+ rchannelSearch := ChannelSearchFromJson(strings.NewReader(json))
+
+ if channelSearch.Term != rchannelSearch.Term {
+ t.Fatal("Terms do not match")
+ }
+}
diff --git a/model/client.go b/model/client.go
index 32532508f8..30eba99f8b 100644
--- a/model/client.go
+++ b/model/client.go
@@ -1164,6 +1164,7 @@ func (c *Client) GetChannel(id, etag string) (*Result, *AppError) {
}
}
+// SCHEDULED FOR DEPRECATION IN 3.7 - use GetMoreChannelsPage instead
func (c *Client) GetMoreChannels(etag string) (*Result, *AppError) {
if r, err := c.DoApiGet(c.GetTeamRoute()+"/channels/more", "", etag); err != nil {
return nil, err
@@ -1174,6 +1175,43 @@ func (c *Client) GetMoreChannels(etag string) (*Result, *AppError) {
}
}
+// GetMoreChannelsPage will return a page of open channels the user is not in based on
+// the provided offset and limit. Must be authenticated.
+func (c *Client) GetMoreChannelsPage(offset int, limit int) (*Result, *AppError) {
+ if r, err := c.DoApiGet(fmt.Sprintf(c.GetTeamRoute()+"/channels/more/%v/%v", offset, limit), "", ""); err != nil {
+ return nil, err
+ } else {
+ defer closeBody(r)
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), ChannelListFromJson(r.Body)}, nil
+ }
+}
+
+// SearchMoreChannels will return a list of open channels the user is not in, that matches
+// the search criteria provided. Must be authenticated.
+func (c *Client) SearchMoreChannels(channelSearch ChannelSearch) (*Result, *AppError) {
+ if r, err := c.DoApiPost(c.GetTeamRoute()+"/channels/more/search", channelSearch.ToJson()); err != nil {
+ return nil, err
+ } else {
+ defer closeBody(r)
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), ChannelListFromJson(r.Body)}, nil
+ }
+}
+
+// AutocompleteChannels will return a list of open channels that match the provided
+// string. Must be authenticated.
+func (c *Client) AutocompleteChannels(term string) (*Result, *AppError) {
+ url := fmt.Sprintf("%s/channels/autocomplete?term=%s", c.GetTeamRoute(), url.QueryEscape(term))
+ if r, err := c.DoApiGet(url, "", ""); err != nil {
+ return nil, err
+ } else {
+ defer closeBody(r)
+ return &Result{r.Header.Get(HEADER_REQUEST_ID),
+ r.Header.Get(HEADER_ETAG_SERVER), ChannelListFromJson(r.Body)}, nil
+ }
+}
+
func (c *Client) GetChannelCounts(etag string) (*Result, *AppError) {
if r, err := c.DoApiGet(c.GetTeamRoute()+"/channels/counts", "", etag); err != nil {
return nil, err
diff --git a/model/autocomplete.go b/model/user_autocomplete.go
similarity index 100%
rename from model/autocomplete.go
rename to model/user_autocomplete.go
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 2074845321..4c3eff6e2b 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -5,6 +5,8 @@ package store
import (
"database/sql"
+ "fmt"
+ "strings"
l4g "github.com/alecthomas/log4go"
"github.com/go-gorp/gorp"
@@ -65,6 +67,8 @@ func (s SqlChannelStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_channelmembers_channel_id", "ChannelMembers", "ChannelId")
s.CreateIndexIfNotExists("idx_channelmembers_user_id", "ChannelMembers", "UserId")
+
+ s.CreateFullTextIndexIfNotExists("idx_channels_txt", "Channels", "Name, DisplayName")
}
func (s SqlChannelStore) Save(channel *model.Channel) StoreChannel {
@@ -392,7 +396,7 @@ func (s SqlChannelStore) GetChannels(teamId string, userId string) StoreChannel
return storeChannel
}
-func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChannel {
+func (s SqlChannelStore) GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel, 1)
go func() {
@@ -418,8 +422,10 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
AND TeamId = :TeamId2
AND UserId = :UserId
AND DeleteAt = 0)
- ORDER BY DisplayName`,
- map[string]interface{}{"TeamId1": teamId, "TeamId2": teamId, "UserId": userId})
+ ORDER BY DisplayName
+ LIMIT :Limit
+ OFFSET :Offset`,
+ map[string]interface{}{"TeamId1": teamId, "TeamId2": teamId, "UserId": userId, "Limit": limit, "Offset": offset})
if err != nil {
result.Err = model.NewLocAppError("SqlChannelStore.GetMoreChannels", "store.sql_channel.get_more_channels.get.app_error", nil, "teamId="+teamId+", userId="+userId+", err="+err.Error())
@@ -1104,3 +1110,110 @@ func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) StoreCh
return storeChannel
}
+
+func (s SqlChannelStore) SearchInTeam(teamId string, term string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ searchQuery := `
+ SELECT
+ *
+ FROM
+ Channels
+ WHERE
+ TeamId = :TeamId
+ AND Type = 'O'
+ AND DeleteAt = 0
+ SEARCH_CLAUSE
+ ORDER BY DisplayName
+ LIMIT 100`
+
+ storeChannel <- s.performSearch(searchQuery, term, map[string]interface{}{"TeamId": teamId})
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlChannelStore) SearchMore(userId string, teamId string, term string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ searchQuery := `
+ SELECT
+ *
+ FROM
+ Channels
+ WHERE
+ TeamId = :TeamId
+ AND Type = 'O'
+ AND DeleteAt = 0
+ AND Id NOT IN (SELECT
+ Channels.Id
+ FROM
+ Channels,
+ ChannelMembers
+ WHERE
+ Id = ChannelId
+ AND TeamId = :TeamId
+ AND UserId = :UserId
+ AND DeleteAt = 0)
+ SEARCH_CLAUSE
+ ORDER BY DisplayName
+ LIMIT 100`
+
+ storeChannel <- s.performSearch(searchQuery, term, map[string]interface{}{"TeamId": teamId, "UserId": userId})
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlChannelStore) performSearch(searchQuery string, term string, parameters map[string]interface{}) StoreResult {
+ result := StoreResult{}
+
+ // these chars have special meaning and can be treated as spaces
+ for _, c := range specialSearchChar {
+ term = strings.Replace(term, c, " ", -1)
+ }
+
+ if term == "" {
+ searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", "", 1)
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
+ splitTerm := strings.Fields(term)
+ for i, t := range strings.Fields(term) {
+ if i == len(splitTerm)-1 {
+ splitTerm[i] = t + ":*"
+ } else {
+ splitTerm[i] = t + ":* &"
+ }
+ }
+
+ term = strings.Join(splitTerm, " ")
+
+ searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery('simple', :Term)", "Name || ' ' || DisplayName")
+ searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
+ } else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
+ splitTerm := strings.Fields(term)
+ for i, t := range strings.Fields(term) {
+ splitTerm[i] = "+" + t + "*"
+ }
+
+ term = strings.Join(splitTerm, " ")
+
+ searchClause := fmt.Sprintf("AND MATCH(%s) AGAINST (:Term IN BOOLEAN MODE)", "Name, DisplayName")
+ searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
+ }
+
+ var channels model.ChannelList
+
+ parameters["Term"] = term
+
+ if _, err := s.GetReplica().Select(&channels, searchQuery, parameters); err != nil {
+ result.Err = model.NewLocAppError("SqlChannelStore.Search", "store.sql_channel.search.app_error", nil, "term="+term+", "+", "+err.Error())
+ } else {
+ result.Data = &channels
+ }
+
+ return result
+}
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 6776a438b1..9b77639b0f 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -309,7 +309,7 @@ func TestChannelStoreDelete(t *testing.T) {
t.Fatal("invalid number of channels")
}
- cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
list = cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
@@ -621,7 +621,10 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
o5.Type = model.CHANNEL_PRIVATE
Must(store.Channel().Save(&o5))
- cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId)
+ cresult := <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
+ if cresult.Err != nil {
+ t.Fatal(cresult.Err)
+ }
list := cresult.Data.(*model.ChannelList)
if len(*list) != 1 {
@@ -632,10 +635,38 @@ func TestChannelStoreGetMoreChannels(t *testing.T) {
t.Fatal("missing channel")
}
+ o6 := model.Channel{}
+ o6.TeamId = o1.TeamId
+ o6.DisplayName = "ChannelA"
+ o6.Name = "a" + model.NewId() + "b"
+ o6.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o6))
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 100)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 2 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 0, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
+ cresult = <-store.Channel().GetMoreChannels(o1.TeamId, m1.UserId, 1, 1)
+ list = cresult.Data.(*model.ChannelList)
+
+ if len(*list) != 1 {
+ t.Fatal("wrong list length")
+ }
+
if r1 := <-store.Channel().AnalyticsTypeCount(o1.TeamId, model.CHANNEL_OPEN); r1.Err != nil {
t.Fatal(r1.Err)
} else {
- if r1.Data.(int64) != 2 {
+ if r1.Data.(int64) != 3 {
t.Log(r1.Data)
t.Fatal("wrong value")
}
@@ -1055,3 +1086,180 @@ func TestUpdateExtrasByUser(t *testing.T) {
t.Fatal("failed to update extras by user: %v", result.Err)
}
}
+
+func TestChannelStoreSearchMore(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "ChannelA"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o1))
+
+ o2 := model.Channel{}
+ o2.TeamId = model.NewId()
+ o2.DisplayName = "Channel2"
+ o2.Name = "a" + model.NewId() + "b"
+ o2.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o2))
+
+ m1 := model.ChannelMember{}
+ m1.ChannelId = o1.Id
+ m1.UserId = model.NewId()
+ m1.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m1))
+
+ m2 := model.ChannelMember{}
+ m2.ChannelId = o1.Id
+ m2.UserId = model.NewId()
+ m2.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m2))
+
+ m3 := model.ChannelMember{}
+ m3.ChannelId = o2.Id
+ m3.UserId = model.NewId()
+ m3.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m3))
+
+ o3 := model.Channel{}
+ o3.TeamId = o1.TeamId
+ o3.DisplayName = "ChannelA"
+ o3.Name = "a" + model.NewId() + "b"
+ o3.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o3))
+
+ o4 := model.Channel{}
+ o4.TeamId = o1.TeamId
+ o4.DisplayName = "ChannelB"
+ o4.Name = "a" + model.NewId() + "b"
+ o4.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o4))
+
+ o5 := model.Channel{}
+ o5.TeamId = o1.TeamId
+ o5.DisplayName = "ChannelC"
+ o5.Name = "a" + model.NewId() + "b"
+ o5.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o5))
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, "ChannelA"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+
+ if (*channels)[0].Name != o3.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, o4.Name); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Fatal("should be empty")
+ }
+ }
+
+ if result := <-store.Channel().SearchMore(m1.UserId, o1.TeamId, o3.Name); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+
+ if (*channels)[0].Name != o3.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
+}
+
+func TestChannelStoreSearchInTeam(t *testing.T) {
+ Setup()
+
+ o1 := model.Channel{}
+ o1.TeamId = model.NewId()
+ o1.DisplayName = "ChannelA"
+ o1.Name = "a" + model.NewId() + "b"
+ o1.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o1))
+
+ o2 := model.Channel{}
+ o2.TeamId = model.NewId()
+ o2.DisplayName = "Channel2"
+ o2.Name = "a" + model.NewId() + "b"
+ o2.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o2))
+
+ m1 := model.ChannelMember{}
+ m1.ChannelId = o1.Id
+ m1.UserId = model.NewId()
+ m1.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m1))
+
+ m2 := model.ChannelMember{}
+ m2.ChannelId = o1.Id
+ m2.UserId = model.NewId()
+ m2.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m2))
+
+ m3 := model.ChannelMember{}
+ m3.ChannelId = o2.Id
+ m3.UserId = model.NewId()
+ m3.NotifyProps = model.GetDefaultChannelNotifyProps()
+ Must(store.Channel().SaveMember(&m3))
+
+ o3 := model.Channel{}
+ o3.TeamId = o1.TeamId
+ o3.DisplayName = "ChannelA"
+ o3.Name = "a" + model.NewId() + "b"
+ o3.Type = model.CHANNEL_OPEN
+ Must(store.Channel().Save(&o3))
+
+ o4 := model.Channel{}
+ o4.TeamId = o1.TeamId
+ o4.DisplayName = "ChannelB"
+ o4.Name = "a" + model.NewId() + "b"
+ o4.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o4))
+
+ o5 := model.Channel{}
+ o5.TeamId = o1.TeamId
+ o5.DisplayName = "ChannelC"
+ o5.Name = "a" + model.NewId() + "b"
+ o5.Type = model.CHANNEL_PRIVATE
+ Must(store.Channel().Save(&o5))
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, "ChannelA"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 2 {
+ t.Fatal("wrong length")
+ }
+ }
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, ""); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) == 0 {
+ t.Fatal("should not be empty")
+ }
+ }
+
+ if result := <-store.Channel().SearchInTeam(o1.TeamId, "blargh"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 0 {
+ t.Fatal("should be empty")
+ }
+ }
+}
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 1a38e89e8e..b09b479a93 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -1120,7 +1120,7 @@ func (us SqlUserStore) Search(teamId string, term string, options map[string]boo
SEARCH_CLAUSE
INACTIVE_CLAUSE
ORDER BY Username ASC
- LIMIT 50`
+ LIMIT 100`
} else {
searchQuery = `
SELECT
@@ -1264,7 +1264,7 @@ func (us SqlUserStore) performSearch(searchQuery string, term string, options ma
term = strings.Join(splitTerm, " ")
searchType = convertMySQLFullTextColumnsToPostgres(searchType)
- searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery(:Term)", searchType)
+ searchClause := fmt.Sprintf("AND (%s) @@ to_tsquery('simple', :Term)", searchType)
searchQuery = strings.Replace(searchQuery, "SEARCH_CLAUSE", searchClause, 1)
} else if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_MYSQL {
splitTerm := strings.Fields(term)
diff --git a/store/store.go b/store/store.go
index 94c8416bd1..ae938a7979 100644
--- a/store/store.go
+++ b/store/store.go
@@ -90,7 +90,7 @@ type ChannelStore interface {
PermanentDeleteByTeam(teamId string) StoreChannel
GetByName(team_id string, domain string) StoreChannel
GetChannels(teamId string, userId string) StoreChannel
- GetMoreChannels(teamId string, userId string) StoreChannel
+ GetMoreChannels(teamId string, userId string, offset int, limit int) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel
@@ -113,6 +113,8 @@ type ChannelStore interface {
AnalyticsTypeCount(teamId string, channelType string) StoreChannel
ExtraUpdateByUser(userId string, time int64) StoreChannel
GetMembersForUser(teamId string, userId string) StoreChannel
+ SearchInTeam(teamId string, term string) StoreChannel
+ SearchMore(userId string, teamId string, term string) StoreChannel
}
type PostStore interface {
diff --git a/webapp/actions/channel_actions.jsx b/webapp/actions/channel_actions.jsx
index 5003d65308..ae32a481b7 100644
--- a/webapp/actions/channel_actions.jsx
+++ b/webapp/actions/channel_actions.jsx
@@ -191,3 +191,55 @@ export function loadChannelsForCurrentUser() {
AsyncClient.getChannels();
AsyncClient.getMyChannelMembers();
}
+
+export function joinChannel(channel, success, error) {
+ Client.joinChannel(
+ channel.id,
+ () => {
+ ChannelStore.removeMoreChannel(channel.id);
+
+ if (success) {
+ success();
+ }
+ },
+ () => {
+ if (error) {
+ error();
+ }
+ }
+ );
+}
+
+export function searchMoreChannels(term, success, error) {
+ Client.searchMoreChannels(
+ term,
+ (data) => {
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
+
+export function autocompleteChannels(term, success, error) {
+ Client.autocompleteChannels(
+ term,
+ (data) => {
+ if (success) {
+ success(data);
+ }
+ },
+ (err) => {
+ AsyncClient.dispatchError(err, 'autocompleteChannels');
+
+ if (error) {
+ error(err);
+ }
+ }
+ );
+}
diff --git a/webapp/actions/global_actions.jsx b/webapp/actions/global_actions.jsx
index 9337595afe..d743b787bc 100644
--- a/webapp/actions/global_actions.jsx
+++ b/webapp/actions/global_actions.jsx
@@ -482,14 +482,6 @@ export function emitUserLoggedOutEvent(redirectTo = '/', shouldSignalLogout = tr
);
}
-export function emitJoinChannelEvent(channel, success, failure) {
- Client.joinChannel(
- channel.id,
- success,
- failure
- );
-}
-
export function emitSearchMentionsEvent(user) {
let terms = '';
if (user.notify_props && user.notify_props.mention_keys) {
diff --git a/webapp/client/client.jsx b/webapp/client/client.jsx
index a7d7a5c8a5..38cc2f111d 100644
--- a/webapp/client/client.jsx
+++ b/webapp/client/client.jsx
@@ -1362,6 +1362,7 @@ export default class Client {
this.track('api', 'api_channel_get');
}
+ // SCHEDULED FOR DEPRECATION IN 3.7 - use getMoreChannelsPage instead
getMoreChannels(success, error) {
request.
get(`${this.getChannelsRoute()}/more`).
@@ -1371,6 +1372,34 @@ export default class Client {
end(this.handleResponse.bind(this, 'getMoreChannels', success, error));
}
+ getMoreChannelsPage(offset, limit, success, error) {
+ request.
+ get(`${this.getChannelsRoute()}/more/${offset}/${limit}`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ end(this.handleResponse.bind(this, 'getMoreChannelsPage', success, error));
+ }
+
+ searchMoreChannels(term, success, error) {
+ request.
+ post(`${this.getChannelsRoute()}/more/search`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ send({term}).
+ end(this.handleResponse.bind(this, 'searchMoreChannels', success, error));
+ }
+
+ autocompleteChannels(term, success, error) {
+ request.
+ get(`${this.getChannelsRoute()}/autocomplete?term=${encodeURIComponent(term)}`).
+ set(this.defaultHeaders).
+ type('application/json').
+ accept('application/json').
+ end(this.handleResponse.bind(this, 'autocompleteChannels', success, error));
+ }
+
getChannelCounts(success, error) {
request.
get(`${this.getChannelsRoute()}/counts`).
diff --git a/webapp/components/filtered_channel_list.jsx b/webapp/components/filtered_channel_list.jsx
deleted file mode 100644
index 64d033bc51..0000000000
--- a/webapp/components/filtered_channel_list.jsx
+++ /dev/null
@@ -1,180 +0,0 @@
-// Copyright (c) 2016 Mattermost, Inc. All Rights Reserved.
-// See License.txt for license information.
-
-import $ from 'jquery';
-import ReactDOM from 'react-dom';
-import * as UserAgent from 'utils/user_agent.jsx';
-
-import {localizeMessage} from 'utils/utils.jsx';
-import {FormattedMessage} from 'react-intl';
-
-import React from 'react';
-import loadingGif from 'images/load.gif';
-
-export default class FilteredChannelList extends React.Component {
- constructor(props) {
- super(props);
-
- this.handleFilterChange = this.handleFilterChange.bind(this);
- this.createChannelRow = this.createChannelRow.bind(this);
- this.filterChannels = this.filterChannels.bind(this);
-
- this.state = {
- filter: '',
- joiningChannel: '',
- channels: this.filterChannels(props.channels)
- };
- }
-
- componentWillReceiveProps(nextProps) {
- // assume the channel list is immutable
- if (this.props.channels !== nextProps.channels) {
- this.setState({
- channels: this.filterChannels(nextProps.channels)
- });
- }
- }
-
- componentDidMount() {
- // only focus the search box on desktop so that we don't cause the keyboard to open on mobile
- if (!UserAgent.isMobile()) {
- ReactDOM.findDOMNode(this.refs.filter).focus();
- }
- }
-
- componentDidUpdate(prevProps, prevState) {
- if (prevState.filter !== this.state.filter) {
- $(ReactDOM.findDOMNode(this.refs.channelList)).scrollTop(0);
- }
- }
-
- handleJoin(channel) {
- this.setState({joiningChannel: channel.id});
- this.props.handleJoin(
- channel,
- () => {
- this.setState({joiningChannel: ''});
- });
- }
-
- createChannelRow(channel) {
- let joinButton;
- if (this.state.joiningChannel === channel.id) {
- joinButton = (
-
- );
- } else {
- joinButton = (
-
- );
- }
-
- return (
-
{channel.display_name}
-{channel.purpose}
-
-
{channel.display_name}
+{channel.purpose}
+
+