mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-29 17:51:56 -06:00
Use existing current room state if we have it
This commit is contained in:
parent
804653e551
commit
5819b4a7ce
|
@ -304,7 +304,7 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Applies the history visibility rules
|
// Applies the history visibility rules
|
||||||
events, err := applyHistoryVisibilityFilter(ctx, p.DB, p.rsAPI, delta.RoomID, device.UserID, eventFilter.Limit, recentEvents)
|
events, err := applyHistoryVisibilityFilter(ctx, p.DB, p.rsAPI, delta.RoomID, device.UserID, eventFilter.Limit, recentEvents, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("unable to apply history visibility filter")
|
logrus.WithError(err).Error("unable to apply history visibility filter")
|
||||||
}
|
}
|
||||||
|
@ -364,16 +364,20 @@ func applyHistoryVisibilityFilter(
|
||||||
rsAPI roomserverAPI.SyncRoomserverAPI,
|
rsAPI roomserverAPI.SyncRoomserverAPI,
|
||||||
roomID, userID string,
|
roomID, userID string,
|
||||||
limit int,
|
limit int,
|
||||||
|
stateEvents []*gomatrixserverlib.HeaderedEvent,
|
||||||
recentEvents []*gomatrixserverlib.HeaderedEvent,
|
recentEvents []*gomatrixserverlib.HeaderedEvent,
|
||||||
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
) ([]*gomatrixserverlib.HeaderedEvent, error) {
|
||||||
// We need to make sure we always include the latest states events, if they are in the timeline.
|
// We need to make sure we always include the latest states events, if they are in the timeline.
|
||||||
// We grep at least limit * 2 events, to ensure we really get the needed events.
|
// We grep at least limit * 2 events, to ensure we really get the needed events.
|
||||||
stateEvents, err := db.CurrentState(ctx, roomID, &gomatrixserverlib.StateFilter{Limit: limit * 2}, nil)
|
if stateEvents == nil {
|
||||||
|
var err error
|
||||||
|
stateEvents, err = db.CurrentState(ctx, roomID, &gomatrixserverlib.StateFilter{Limit: limit * 2}, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Not a fatal error, we can continue without the stateEvents,
|
// Not a fatal error, we can continue without the stateEvents,
|
||||||
// they are only needed if there are state events in the timeline.
|
// they are only needed if there are state events in the timeline.
|
||||||
logrus.WithError(err).Warnf("failed to get current room state")
|
logrus.WithError(err).Warnf("failed to get current room state")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
alwaysIncludeIDs := make(map[string]struct{}, len(stateEvents))
|
alwaysIncludeIDs := make(map[string]struct{}, len(stateEvents))
|
||||||
for _, ev := range stateEvents {
|
for _, ev := range stateEvents {
|
||||||
alwaysIncludeIDs[ev.EventID()] = struct{}{}
|
alwaysIncludeIDs[ev.EventID()] = struct{}{}
|
||||||
|
@ -499,7 +503,7 @@ func (p *PDUStreamProvider) getJoinResponseForCompleteSync(
|
||||||
events := recentEvents
|
events := recentEvents
|
||||||
// Only apply history visibility checks if the response is for joined rooms
|
// Only apply history visibility checks if the response is for joined rooms
|
||||||
if !isPeek {
|
if !isPeek {
|
||||||
events, err = applyHistoryVisibilityFilter(ctx, p.DB, p.rsAPI, roomID, device.UserID, eventFilter.Limit, recentEvents)
|
events, err = applyHistoryVisibilityFilter(ctx, p.DB, p.rsAPI, roomID, device.UserID, eventFilter.Limit, recentEvents, stateEvents)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Error("unable to apply history visibility filter")
|
logrus.WithError(err).Error("unable to apply history visibility filter")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue