fix history visibility boundary logic

This commit is contained in:
Sam Wedgwood 2023-08-22 18:11:51 +01:00
parent 5b8fb2cb23
commit 0c76e61e6b

View file

@ -163,7 +163,10 @@ func ApplyHistoryVisibilityFilter(
// by setting the effective evVis to the least restrictive
// of the old vs new.
// https://spec.matrix.org/v1.3/client-server-api/#server-behaviour-5
if hisVis, err := ev.HistoryVisibility(); err == nil {
if ev.Type() == spec.MRoomHistoryVisibility {
hisVis, err := ev.HistoryVisibility()
if err == nil && hisVis != "" {
prevHisVis := gjson.GetBytes(ev.Unsigned(), "prev_content.history_visibility").String()
oldPrio, ok := historyVisibilityPriority[gomatrixserverlib.HistoryVisibility(prevHisVis)]
// if we can't get the previous history visibility, default to shared.
@ -174,6 +177,9 @@ func ApplyHistoryVisibilityFilter(
newPrio := historyVisibilityPriority[hisVis]
if oldPrio < newPrio {
evVis.visibility = gomatrixserverlib.HistoryVisibility(prevHisVis)
} else {
evVis.visibility = hisVis
}
}
}
// do the actual check