mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-11 16:13:10 -06:00
Fix wrong returned state
This commit is contained in:
parent
ba8e842a72
commit
6c969b6c9d
|
|
@ -22,8 +22,9 @@ import (
|
|||
|
||||
"github.com/blevesearch/bleve/v2"
|
||||
"github.com/blevesearch/bleve/v2/mapping"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
)
|
||||
|
||||
// Search contains all existing bleve.Index
|
||||
|
|
|
|||
|
|
@ -21,6 +21,11 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/nats-io/nats.go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
"github.com/matrix-org/dendrite/internal/fulltext"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
|
|
@ -30,10 +35,6 @@ import (
|
|||
"github.com/matrix-org/dendrite/syncapi/producers"
|
||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||
"github.com/matrix-org/dendrite/syncapi/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/nats-io/nats.go"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
|
|
@ -474,6 +475,9 @@ func (s *OutputRoomEventConsumer) updateStateEvent(event *gomatrixserverlib.Head
|
|||
}
|
||||
|
||||
func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent, pduPosition types.StreamPosition) error {
|
||||
if !s.cfg.Fulltext.Enabled {
|
||||
return nil
|
||||
}
|
||||
e := fulltext.IndexElement{
|
||||
EventID: ev.EventID(),
|
||||
RoomID: ev.RoomID(),
|
||||
|
|
@ -493,6 +497,7 @@ func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent,
|
|||
if err := s.fts.Delete(ev.Redacts()); err != nil {
|
||||
return fmt.Errorf("failed to delete entry from fulltext index: %w", err)
|
||||
}
|
||||
return nil
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -159,8 +159,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
})
|
||||
}
|
||||
|
||||
gotStateForRooms := make(map[string]struct{})
|
||||
var allStates []gomatrixserverlib.ClientEvent
|
||||
stateForRooms := make(map[string][]gomatrixserverlib.ClientEvent)
|
||||
for _, event := range evs {
|
||||
eventsBefore, eventsAfter, err := contextEvents(ctx, syncDB, event, roomFilter, searchReq)
|
||||
if err != nil {
|
||||
|
|
@ -208,15 +207,14 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
roomGroup := groups[event.RoomID()]
|
||||
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
||||
groups[event.RoomID()] = roomGroup
|
||||
if _, ok := gotStateForRooms[event.RoomID()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
|
||||
if _, ok := stateForRooms[event.RoomID()]; searchReq.SearchCategories.RoomEvents.IncludeState && !ok {
|
||||
stateFilter := gomatrixserverlib.DefaultStateFilter()
|
||||
state, err := syncDB.CurrentState(ctx, event.RoomID(), &stateFilter, nil)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("unable to get current state")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
gotStateForRooms[event.RoomID()] = struct{}{}
|
||||
allStates = append(allStates, gomatrixserverlib.HeaderedToClientEvents(state, gomatrixserverlib.FormatSync)...)
|
||||
stateForRooms[event.RoomID()] = gomatrixserverlib.HeaderedToClientEvents(state, gomatrixserverlib.FormatSync)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -233,7 +231,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
|||
Results: results,
|
||||
NextBatch: &nb,
|
||||
Highlights: strings.Split(searchReq.SearchCategories.RoomEvents.SearchTerm, " "),
|
||||
State: allStates,
|
||||
State: stateForRooms,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
@ -329,12 +327,12 @@ type ProfileInfo struct {
|
|||
}
|
||||
|
||||
type RoomEvents struct {
|
||||
Count int `json:"count"`
|
||||
Groups Groups `json:"groups"`
|
||||
Highlights []string `json:"highlights"`
|
||||
NextBatch *string `json:"next_batch,omitempty"`
|
||||
Results []Result `json:"results"`
|
||||
State []gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||
Count int `json:"count"`
|
||||
Groups Groups `json:"groups"`
|
||||
Highlights []string `json:"highlights"`
|
||||
NextBatch *string `json:"next_batch,omitempty"`
|
||||
Results []Result `json:"results"`
|
||||
State map[string][]gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||
}
|
||||
type SearchCategories struct {
|
||||
RoomEvents RoomEvents `json:"room_events"`
|
||||
|
|
|
|||
Loading…
Reference in a new issue