diff --git a/federation/server_room.go b/federation/server_room.go index 61c40ed3..25cc18d8 100644 --- a/federation/server_room.go +++ b/federation/server_room.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "strconv" "sync" "time" @@ -333,15 +334,22 @@ func InitialRoomEvents(roomVer gomatrixserverlib.RoomVersion, creator string) [] Type: "m.room.create", StateKey: b.Ptr(""), Sender: creator, - Content: map[string]interface{}{ - "creator": creator, - "room_version": roomVer, - // We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond - // they will get the same room ID, clobbering internal data structures and causing extremely confusing - // behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their - // hashes will not be the same. - "complement_entropy": util.RandomString(18), - }, + Content: func() map[string]interface{} { + content := map[string]interface{}{ + "room_version": roomVer, + // We have to add randomness to the create event, else if you create 2x v12+ rooms in the same millisecond + // they will get the same room ID, clobbering internal data structures and causing extremely confusing + // behaviour. By adding this entropy, we ensure that even if rooms are created in the same millisecond, their + // hashes will not be the same. + "complement_entropy": util.RandomString(18), + } + // The creator field was removed in room version 11 (MSC4239). + n, err := strconv.Atoi(string(roomVer)) + if err != nil || n < 11 { + content["creator"] = creator + } + return content + }(), }, { Type: "m.room.member", diff --git a/tests/csapi/rooms_state_test.go b/tests/csapi/rooms_state_test.go index 2158cae1..4e56f6e9 100644 --- a/tests/csapi/rooms_state_test.go +++ b/tests/csapi/rooms_state_test.go @@ -4,6 +4,7 @@ package csapi_tests import ( + "strconv" "testing" "time" @@ -26,6 +27,8 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { LocalpartSuffix: "bob", Password: "bobpassword", }) + defaultVer := alice.GetDefaultRoomVersion(t) + defaultVerN, _ := strconv.Atoi(string(defaultVer)) roomID := alice.MustCreateRoom(t, map[string]interface{}{}) t.Run("parallel", func(t *testing.T) { @@ -38,7 +41,10 @@ func TestRoomCreationReportsEventsToMyself(t *testing.T) { return false } must.Equal(t, ev.Get("sender").Str, alice.UserID, "wrong sender") - must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator") + // The creator field was removed in room version 11 (MSC4239). + if defaultVerN < 11 { + must.Equal(t, ev.Get("content").Get("creator").Str, alice.UserID, "wrong content.creator") + } return true })) })