We should port over whatever Rich did in https://github.com/matrix-org/synapse/pull/13639
We should port over whatever Rich did in matrix-org/synapse#13639