From 4f65e88d2a5b845cc789eeb1fbf9f1067b1e8ab9 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Thu, 12 Jan 2023 18:54:27 +0000 Subject: [PATCH 1/3] Use stable identifiers from MSC3706 (Faster joins) --- federationclient.go | 2 +- federationtypes.go | 8 ++++---- federationtypes_test.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/federationclient.go b/federationclient.go index 7cd8e0a0..9563b848 100644 --- a/federationclient.go +++ b/federationclient.go @@ -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) diff --git a/federationtypes.go b/federationtypes.go index 6cdde5d6..cc7e0ab5 100644 --- a/federationtypes.go +++ b/federationtypes.go @@ -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"` + PartialState 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 @@ -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"` + PartialState bool `json:"members_omitted"` + ServersInRoom []string `json:"servers_in_room"` } // ToRespState returns a new RespState with the same data from the given RespSendJoin diff --git a/federationtypes_test.go b/federationtypes_test.go index 391b49ed..2314f869 100644 --- a/federationtypes_test.go +++ b/federationtypes_test.go @@ -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 From d5bef8cccb7afc6694a6adb3f2429b74f266a98c Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 13 Jan 2023 14:26:14 +0000 Subject: [PATCH 2/3] Also rename internal field name (breaking change) --- federationtypes.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/federationtypes.go b/federationtypes.go index cc7e0ab5..57ce4b6d 100644 --- a/federationtypes.go +++ b/federationtypes.go @@ -443,8 +443,8 @@ type RespSendJoin struct { // The returned join event from the remote server. Used for restricted joins, // 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:"members_omitted"` + // true if m.room.member events have been omitted from StateEvents + MembersOmitted bool `json:"members_omitted"` // a list of servers in the room. Only returned if partial_state is set. ServersInRoom []string `json:"servers_in_room"` } From 41fb88cc9ce1b504fe58b77603e83bcf96190e65 Mon Sep 17 00:00:00 2001 From: David Robertson Date: Fri, 13 Jan 2023 14:34:23 +0000 Subject: [PATCH 3/3] ...and fixup the places I missed --- federationtypes.go | 10 +++++----- federationtypes_test.go | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/federationtypes.go b/federationtypes.go index 57ce4b6d..6b9530e4 100644 --- a/federationtypes.go +++ b/federationtypes.go @@ -443,7 +443,7 @@ type RespSendJoin struct { // The returned join event from the remote server. Used for restricted joins, // but not guaranteed to be present as it's only since MSC3083. Event RawJSON `json:"event,omitempty"` - // true if m.room.member events have been omitted from StateEvents + // true if the state is incomplete MembersOmitted bool `json:"members_omitted"` // a list of servers in the room. Only returned if partial_state is set. ServersInRoom []string `json:"servers_in_room"` @@ -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) @@ -517,8 +517,8 @@ type respSendJoinFields struct { // when the response has incomplete state. type respSendJoinPartialStateFields struct { respSendJoinFields - PartialState bool `json:"members_omitted"` - ServersInRoom []string `json:"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 diff --git a/federationtypes_test.go b/federationtypes_test.go index 2314f869..9400c8ad 100644 --- a/federationtypes_test.go +++ b/federationtypes_test.go @@ -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)