Skip to content

Commit

Permalink
Use stable identifiers from MSC3706 (Faster joins) (#350)
Browse files Browse the repository at this point in the history
I haven't made any effort to maintain backwards compatibility (unlike in
matrix-org/synapse#14832). I'm happy to do so if
needed, but might need some guidance.

Synapse issue: matrix-org/synapse#14828
Synapse PR: matrix-org/synapse#14832
Complement PR: matrix-org/complement#583
GMSL PR: #350
MSC: matrix-org/matrix-spec-proposals#3706
Spec diff: matrix-org/matrix-spec#1393

### Pull Request Checklist

* [x] Pull request includes a [sign
off](https://github.com/matrix-org/dendrite/blob/master/docs/CONTRIBUTING.md#sign-off)

Signed-off-by: `David Robertson <davidr@element.io>`
  • Loading branch information
DMRobertson authored Jan 13, 2023
1 parent c6b15eb commit 67e0601
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion federationclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (ac *FederationClient) sendJoin(
url.PathEscape(event.RoomID()) + "/" +
url.PathEscape(event.EventID())
if partialState {
path += "?org.matrix.msc3706.partial_state=true"
path += "?omit_members=true"
}

req := NewFederationRequest("PUT", origin, s, path)
Expand Down
12 changes: 6 additions & 6 deletions federationtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,9 @@ type RespSendJoin struct {
// but not guaranteed to be present as it's only since MSC3083.
Event RawJSON `json:"event,omitempty"`
// true if the state is incomplete
PartialState bool `json:"org.matrix.msc3706.partial_state"`
MembersOmitted bool `json:"members_omitted"`
// a list of servers in the room. Only returned if partial_state is set.
ServersInRoom []string `json:"org.matrix.msc3706.servers_in_room"`
ServersInRoom []string `json:"servers_in_room"`
}

// MarshalJSON implements json.Marshaller
Expand All @@ -464,13 +464,13 @@ func (r RespSendJoin) MarshalJSON() ([]byte, error) {
fields.StateEvents = EventJSONs{}
}

if !r.PartialState {
if !r.MembersOmitted {
return json.Marshal(fields)
}

partialJoinFields := respSendJoinPartialStateFields{
respSendJoinFields: fields,
PartialState: true,
MembersOmitted: true,
ServersInRoom: r.ServersInRoom,
}
return json.Marshal(partialJoinFields)
Expand Down Expand Up @@ -517,8 +517,8 @@ type respSendJoinFields struct {
// when the response has incomplete state.
type respSendJoinPartialStateFields struct {
respSendJoinFields
PartialState bool `json:"org.matrix.msc3706.partial_state"`
ServersInRoom []string `json:"org.matrix.msc3706.servers_in_room"`
MembersOmitted bool `json:"members_omitted"`
ServersInRoom []string `json:"servers_in_room"`
}

// ToRespState returns a new RespState with the same data from the given RespSendJoin
Expand Down
14 changes: 7 additions & 7 deletions federationtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ func TestRespSendJoinMarshalJSON(t *testing.T) {
func TestRespSendJoinMarshalJSONPartialState(t *testing.T) {
inputData := `{
"state":[],"auth_chain":[],"origin":"o1",
"org.matrix.msc3706.partial_state":true,
"org.matrix.msc3706.servers_in_room":["s1", "s2"]
"members_omitted":true,
"servers_in_room":["s1", "s2"]
}`

var input RespSendJoin
Expand All @@ -133,11 +133,11 @@ func TestRespSendJoinMarshalJSONPartialState(t *testing.T) {
}

want := RespSendJoin{
StateEvents: []RawJSON{},
AuthEvents: []RawJSON{},
Origin: "o1",
PartialState: true,
ServersInRoom: []string{"s1", "s2"},
StateEvents: []RawJSON{},
AuthEvents: []RawJSON{},
Origin: "o1",
MembersOmitted: true,
ServersInRoom: []string{"s1", "s2"},
}
if !cmp.Equal(input, want, cmp.AllowUnexported(RespSendJoin{})) {
t.Errorf("json.Unmarshal(%s): wanted %+v, got %+v", inputData, want, input)
Expand Down

0 comments on commit 67e0601

Please sign in to comment.