mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -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"
|
||||||
"github.com/blevesearch/bleve/v2/mapping"
|
"github.com/blevesearch/bleve/v2/mapping"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
|
||||||
|
"github.com/matrix-org/dendrite/setup/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Search contains all existing bleve.Index
|
// Search contains all existing bleve.Index
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/getsentry/sentry-go"
|
"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/internal/fulltext"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/setup/config"
|
"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/producers"
|
||||||
"github.com/matrix-org/dendrite/syncapi/storage"
|
"github.com/matrix-org/dendrite/syncapi/storage"
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"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.
|
// 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 {
|
func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent, pduPosition types.StreamPosition) error {
|
||||||
|
if !s.cfg.Fulltext.Enabled {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
e := fulltext.IndexElement{
|
e := fulltext.IndexElement{
|
||||||
EventID: ev.EventID(),
|
EventID: ev.EventID(),
|
||||||
RoomID: ev.RoomID(),
|
RoomID: ev.RoomID(),
|
||||||
|
|
@ -493,6 +497,7 @@ func (s *OutputRoomEventConsumer) writeFTS(ev *gomatrixserverlib.HeaderedEvent,
|
||||||
if err := s.fts.Delete(ev.Redacts()); err != nil {
|
if err := s.fts.Delete(ev.Redacts()); err != nil {
|
||||||
return fmt.Errorf("failed to delete entry from fulltext index: %w", err)
|
return fmt.Errorf("failed to delete entry from fulltext index: %w", err)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
default:
|
default:
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
gotStateForRooms := make(map[string]struct{})
|
stateForRooms := make(map[string][]gomatrixserverlib.ClientEvent)
|
||||||
var allStates []gomatrixserverlib.ClientEvent
|
|
||||||
for _, event := range evs {
|
for _, event := range evs {
|
||||||
eventsBefore, eventsAfter, err := contextEvents(ctx, syncDB, event, roomFilter, searchReq)
|
eventsBefore, eventsAfter, err := contextEvents(ctx, syncDB, event, roomFilter, searchReq)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -208,15 +207,14 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
roomGroup := groups[event.RoomID()]
|
roomGroup := groups[event.RoomID()]
|
||||||
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
roomGroup.Results = append(roomGroup.Results, event.EventID())
|
||||||
groups[event.RoomID()] = roomGroup
|
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()
|
stateFilter := gomatrixserverlib.DefaultStateFilter()
|
||||||
state, err := syncDB.CurrentState(ctx, event.RoomID(), &stateFilter, nil)
|
state, err := syncDB.CurrentState(ctx, event.RoomID(), &stateFilter, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("unable to get current state")
|
logrus.WithError(err).Error("unable to get current state")
|
||||||
return jsonerror.InternalServerError()
|
return jsonerror.InternalServerError()
|
||||||
}
|
}
|
||||||
gotStateForRooms[event.RoomID()] = struct{}{}
|
stateForRooms[event.RoomID()] = gomatrixserverlib.HeaderedToClientEvents(state, gomatrixserverlib.FormatSync)
|
||||||
allStates = append(allStates, gomatrixserverlib.HeaderedToClientEvents(state, gomatrixserverlib.FormatSync)...)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -233,7 +231,7 @@ func Search(req *http.Request, device *api.Device, syncDB storage.Database, fts
|
||||||
Results: results,
|
Results: results,
|
||||||
NextBatch: &nb,
|
NextBatch: &nb,
|
||||||
Highlights: strings.Split(searchReq.SearchCategories.RoomEvents.SearchTerm, " "),
|
Highlights: strings.Split(searchReq.SearchCategories.RoomEvents.SearchTerm, " "),
|
||||||
State: allStates,
|
State: stateForRooms,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -334,7 +332,7 @@ type RoomEvents struct {
|
||||||
Highlights []string `json:"highlights"`
|
Highlights []string `json:"highlights"`
|
||||||
NextBatch *string `json:"next_batch,omitempty"`
|
NextBatch *string `json:"next_batch,omitempty"`
|
||||||
Results []Result `json:"results"`
|
Results []Result `json:"results"`
|
||||||
State []gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
State map[string][]gomatrixserverlib.ClientEvent `json:"state,omitempty"`
|
||||||
}
|
}
|
||||||
type SearchCategories struct {
|
type SearchCategories struct {
|
||||||
RoomEvents RoomEvents `json:"room_events"`
|
RoomEvents RoomEvents `json:"room_events"`
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue