mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-28 16:08:27 +00:00
Derive state events from already filtered events
This commit is contained in:
parent
370b3d981e
commit
fe7acc63fa
1 changed files with 19 additions and 14 deletions
|
@ -244,10 +244,6 @@ func (p *PDUStreamProvider) getResponseForCompleteSync(
|
||||||
recentEvents, stateEvents []*gomatrixserverlib.HeaderedEvent,
|
recentEvents, stateEvents []*gomatrixserverlib.HeaderedEvent,
|
||||||
prevBatch *types.TopologyToken, limited bool, err error,
|
prevBatch *types.TopologyToken, limited bool, err error,
|
||||||
) {
|
) {
|
||||||
stateEvents, err = p.DB.CurrentState(ctx, roomID, &filter.Room.State)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// TODO: When filters are added, we may need to call this multiple times to get enough events.
|
// TODO: When filters are added, we may need to call this multiple times to get enough events.
|
||||||
// See: https://github.com/matrix-org/synapse/blob/v0.19.3/synapse/handlers/sync.py#L316
|
// See: https://github.com/matrix-org/synapse/blob/v0.19.3/synapse/handlers/sync.py#L316
|
||||||
var recentStreamEvents []types.StreamEvent
|
var recentStreamEvents []types.StreamEvent
|
||||||
|
@ -257,18 +253,24 @@ func (p *PDUStreamProvider) getResponseForCompleteSync(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
recentStreamEvents, limited = p.filterStreamEventsAccordingToHistoryVisibility(recentStreamEvents, stateEvents, device, limited)
|
||||||
|
|
||||||
events := make([]string, len(recentStreamEvents))
|
// TODO: How do we apply filter.Room.State to this as well?
|
||||||
for i, v := range recentStreamEvents {
|
// Is there a generic function where we can pass a list of events and filter and get the result?
|
||||||
events[i] = string(v.HeaderedEvent.Event.JSON())
|
// This is based off of Synapse where we derive the state from the resultant timeline events
|
||||||
|
// https://github.com/matrix-org/synapse/blob/14950a45d6ff3a5ea737322af1096a49b079f2eb/synapse/handlers/sync.py#L791-L795
|
||||||
|
for _, event := range recentStreamEvents {
|
||||||
|
if event.HeaderedEvent.Event.StateKey() != nil {
|
||||||
|
stateEvents = append(stateEvents, event.HeaderedEvent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.WithFields(logrus.Fields{
|
// Note: I feel like this is flawed. We only want stateEvents in the events we filtered already
|
||||||
"filter.Room.Timeline.Limit": filter.Room.Timeline.Limit,
|
// so I've opted with the option above to derive the `stateEvents`
|
||||||
"recentStreamEvents": fmt.Sprintf("%+v", events),
|
// stateEvents, err = p.DB.CurrentState(ctx, roomID, &filter.Room.State)
|
||||||
}).Info("getResponseForCompleteSync")
|
// if err != nil {
|
||||||
|
// return
|
||||||
recentStreamEvents, limited = p.filterStreamEventsAccordingToHistoryVisibility(recentStreamEvents, stateEvents, device, limited)
|
// }
|
||||||
|
|
||||||
// Retrieve the backward topology position, i.e. the position of the
|
// Retrieve the backward topology position, i.e. the position of the
|
||||||
// oldest event in the room's topology.
|
// oldest event in the room's topology.
|
||||||
|
@ -351,6 +353,9 @@ func (p *PDUStreamProvider) filterStreamEventsAccordingToHistoryVisibility(
|
||||||
}
|
}
|
||||||
switch content.HistoryVisibility {
|
switch content.HistoryVisibility {
|
||||||
case "world_readable", "shared":
|
case "world_readable", "shared":
|
||||||
|
logrus.WithFields(logrus.Fields{
|
||||||
|
"content.HistoryVisibility": content.HistoryVisibility,
|
||||||
|
}).Info("filterStreamEventsAccordingToHistoryVisibility: No filtering needed for these events")
|
||||||
return recentStreamEvents, limited
|
return recentStreamEvents, limited
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
|
@ -409,7 +414,7 @@ func (p *PDUStreamProvider) filterStreamEventsAccordingToHistoryVisibility(
|
||||||
"sliceStart": sliceStart,
|
"sliceStart": sliceStart,
|
||||||
"sliceEnd": sliceEnd,
|
"sliceEnd": sliceEnd,
|
||||||
"before recentStreamEvents": fmt.Sprintf("%+v", events),
|
"before recentStreamEvents": fmt.Sprintf("%+v", events),
|
||||||
}).Info("cutting down the events")
|
}).Info("filterStreamEventsAccordingToHistoryVisibility: cutting down the events")
|
||||||
|
|
||||||
return recentStreamEvents[sliceStart:sliceEnd], limited
|
return recentStreamEvents[sliceStart:sliceEnd], limited
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue