mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-04-07 04:13:39 +00:00
Less restrictive visibility filtering
This commit is contained in:
parent
0231199cc8
commit
707f347f34
1 changed files with 21 additions and 1 deletions
|
@ -2,6 +2,7 @@ package streams
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/syncapi/types"
|
"github.com/matrix-org/dendrite/syncapi/types"
|
||||||
|
@ -249,7 +250,7 @@ func (p *PDUStreamProvider) getResponseForCompleteSync(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
recentStreamEvents, limited = p.filterStreamEventsAccordingToHistoryVisibility(recentStreamEvents, device, limited)
|
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.
|
||||||
|
@ -317,9 +318,28 @@ func (p *PDUStreamProvider) getLeaveResponseForCompleteSync(
|
||||||
// nolint:gocyclo
|
// nolint:gocyclo
|
||||||
func (p *PDUStreamProvider) filterStreamEventsAccordingToHistoryVisibility(
|
func (p *PDUStreamProvider) filterStreamEventsAccordingToHistoryVisibility(
|
||||||
recentStreamEvents []types.StreamEvent,
|
recentStreamEvents []types.StreamEvent,
|
||||||
|
stateEvents []*gomatrixserverlib.HeaderedEvent,
|
||||||
device *userapi.Device,
|
device *userapi.Device,
|
||||||
limited bool,
|
limited bool,
|
||||||
) ([]types.StreamEvent, bool) {
|
) ([]types.StreamEvent, bool) {
|
||||||
|
// If the history is world_readable or shared then don't filter.
|
||||||
|
for _, stateEvent := range stateEvents {
|
||||||
|
if stateEvent.Type() == gomatrixserverlib.MRoomHistoryVisibility {
|
||||||
|
var content struct {
|
||||||
|
HistoryVisibility string `json:"history_visibility"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(stateEvent.Content(), &content); err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
switch content.HistoryVisibility {
|
||||||
|
case "world_readable", "shared":
|
||||||
|
return recentStreamEvents, limited
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO FIXME: We don't fully implement history visibility yet. To avoid leaking events which the
|
// TODO FIXME: We don't fully implement history visibility yet. To avoid leaking events which the
|
||||||
// user shouldn't see, we check the recent events and remove any prior to the join event of the user
|
// user shouldn't see, we check the recent events and remove any prior to the join event of the user
|
||||||
// which is equiv to history_visibility: joined
|
// which is equiv to history_visibility: joined
|
||||||
|
|
Loading…
Reference in a new issue