diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/client4.go | 11 | ||||
-rw-r--r-- | model/post_search_results.go | 40 |
2 files changed, 51 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go index f5a856835..3a93a9541 100644 --- a/model/client4.go +++ b/model/client4.go @@ -2127,6 +2127,17 @@ func (c *Client4) SearchPosts(teamId string, terms string, isOrSearch bool) (*Po } } +// SearchPosts returns any posts with matching terms string, including . +func (c *Client4) SearchPostsWithMatches(teamId string, terms string, isOrSearch bool) (*PostSearchResults, *Response) { + requestBody := map[string]interface{}{"terms": terms, "is_or_search": isOrSearch} + if r, err := c.DoApiPost(c.GetTeamRoute(teamId)+"/posts/search", StringInterfaceToJson(requestBody)); err != nil { + return nil, BuildErrorResponse(r, err) + } else { + defer closeBody(r) + return PostSearchResultsFromJson(r.Body), BuildResponse(r) + } +} + // DoPostAction performs a post action. func (c *Client4) DoPostAction(postId, actionId string) (bool, *Response) { if r, err := c.DoApiPost(c.GetPostRoute(postId)+"/actions/"+actionId, ""); err != nil { diff --git a/model/post_search_results.go b/model/post_search_results.go new file mode 100644 index 000000000..2317f1831 --- /dev/null +++ b/model/post_search_results.go @@ -0,0 +1,40 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See License.txt for license information. + +package model + +import ( + "encoding/json" + "io" +) + +type PostSearchMatches map[string][]string + +type PostSearchResults struct { + *PostList + Matches PostSearchMatches `json:"matches"` +} + +func MakePostSearchResults(posts *PostList, matches PostSearchMatches) *PostSearchResults { + return &PostSearchResults{ + posts, + matches, + } +} + +func (o *PostSearchResults) ToJson() string { + copy := *o + copy.PostList.StripActionIntegrations() + b, err := json.Marshal(©) + if err != nil { + return "" + } else { + return string(b) + } +} + +func PostSearchResultsFromJson(data io.Reader) *PostSearchResults { + var o *PostSearchResults + json.NewDecoder(data).Decode(&o) + return o +} |