github.com/crspeller/mattermost-server@v0.0.0-20190328001957-a200beb3d111/model/post_search_results.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package model
     5  
     6  import (
     7  	"encoding/json"
     8  	"io"
     9  )
    10  
    11  type PostSearchMatches map[string][]string
    12  
    13  type PostSearchResults struct {
    14  	*PostList
    15  	Matches PostSearchMatches `json:"matches"`
    16  }
    17  
    18  func MakePostSearchResults(posts *PostList, matches PostSearchMatches) *PostSearchResults {
    19  	return &PostSearchResults{
    20  		posts,
    21  		matches,
    22  	}
    23  }
    24  
    25  func (o *PostSearchResults) ToJson() string {
    26  	copy := *o
    27  	copy.PostList.StripActionIntegrations()
    28  	b, err := json.Marshal(&copy)
    29  	if err != nil {
    30  		return ""
    31  	} else {
    32  		return string(b)
    33  	}
    34  }
    35  
    36  func PostSearchResultsFromJson(data io.Reader) *PostSearchResults {
    37  	var o *PostSearchResults
    38  	json.NewDecoder(data).Decode(&o)
    39  	return o
    40  }