Changed post searching to allow searching by multiple users/channels
Этот коммит содержится в:
42
api/post.go
42
api/post.go
@@ -820,45 +820,23 @@ func searchPosts(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
plainSearchParams, hashtagSearchParams := model.ParseSearchParams(terms)
|
||||
paramsList := model.ParseSearchParams(terms)
|
||||
channels := []store.StoreChannel{}
|
||||
|
||||
var hchan store.StoreChannel
|
||||
if hashtagSearchParams != nil {
|
||||
hchan = Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, hashtagSearchParams)
|
||||
for _, params := range paramsList {
|
||||
channels = append(channels, Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, params))
|
||||
}
|
||||
|
||||
var pchan store.StoreChannel
|
||||
if plainSearchParams != nil {
|
||||
pchan = Srv.Store.Post().Search(c.Session.TeamId, c.Session.UserId, plainSearchParams)
|
||||
}
|
||||
|
||||
mainList := &model.PostList{}
|
||||
if hchan != nil {
|
||||
if result := <-hchan; result.Err != nil {
|
||||
posts := &model.PostList{}
|
||||
for _, channel := range channels {
|
||||
if result := <-channel; result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
mainList = result.Data.(*model.PostList)
|
||||
data := result.Data.(*model.PostList)
|
||||
posts.Extend(data)
|
||||
}
|
||||
}
|
||||
|
||||
plainList := &model.PostList{}
|
||||
if pchan != nil {
|
||||
if result := <-pchan; result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
} else {
|
||||
plainList = result.Data.(*model.PostList)
|
||||
}
|
||||
}
|
||||
|
||||
for _, postId := range plainList.Order {
|
||||
if _, ok := mainList.Posts[postId]; !ok {
|
||||
mainList.AddPost(plainList.Posts[postId])
|
||||
mainList.AddOrder(postId)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
w.Write([]byte(mainList.ToJson()))
|
||||
w.Write([]byte(posts.ToJson()))
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user