summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-11-24 09:35:09 -0500
committerHarrison Healey <harrisonmhealey@gmail.com>2016-11-24 09:35:09 -0500
commit981ea33b8e10456bc279f36235c814305d01b243 (patch)
tree00fb6119d9ef16f60d4c0dbdaad1bd6dfbc347ed /model
parentc96ecae6da31aceabf29586cde872876b81d11d9 (diff)
downloadchat-981ea33b8e10456bc279f36235c814305d01b243.tar.gz
chat-981ea33b8e10456bc279f36235c814305d01b243.tar.bz2
chat-981ea33b8e10456bc279f36235c814305d01b243.zip
PLT-4403 Add server-based channel autocomplete, search and paging (#4585)
* Add more channel paging API * Add channel paging support to client * Add DB channel search functions * Add API for searching more channels * Add more channel search functionality to client * Add API for autocompleting channels * Add channel autocomplete functionality to the client * Move to be deprecated APIs to their own file * Final clean-up * Fixes related to feedback * Localization changes * Add unit as suffix to timeout constants
Diffstat (limited to 'model')
-rw-r--r--model/channel_search.go35
-rw-r--r--model/channel_search_test.go19
-rw-r--r--model/client.go38
-rw-r--r--model/user_autocomplete.go (renamed from model/autocomplete.go)0
4 files changed, 92 insertions, 0 deletions
diff --git a/model/channel_search.go b/model/channel_search.go
new file mode 100644
index 000000000..2c041503d
--- /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 000000000..f7f6d66f7
--- /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 32532508f..30eba99f8 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
index b7449a792..b7449a792 100644
--- a/model/autocomplete.go
+++ b/model/user_autocomplete.go