Actually only ignore user state events, ignore invites as well

This commit is contained in:
Till Faelligen 2023-04-26 19:23:13 +02:00
parent 26d1e3599a
commit 3c9665692f
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E
2 changed files with 21 additions and 8 deletions

View file

@ -355,7 +355,7 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
continue
}
if event.Type() == spec.MRoomMember && !event.StateKeyEquals(userID) {
// With the exception of bans and invites which we do want to copy, we
// With the exception of bans which we do want to copy, we
// should ignore membership events that aren't our own, as event auth will
// prevent us from being able to create membership events on behalf of other
// users anyway unless they are invites or bans.
@ -365,13 +365,13 @@ func (r *Upgrader) generateInitialEvents(ctx context.Context, oldRoom *api.Query
}
switch membership {
case spec.Ban:
case spec.Invite:
default:
continue
}
}
// skip events that rely on a specific user being present
if event.Type() != spec.MRoomMember && !event.StateKeyEquals("") {
sKey := *event.StateKey()
if event.Type() != spec.MRoomMember && len(sKey) > 0 && sKey[:1] == "@" {
continue
}
state[gomatrixserverlib.StateKeyTuple{EventType: event.Type(), StateKey: *event.StateKey()}] = event

View file

@ -764,6 +764,7 @@ func TestUpgrade(t *testing.T) {
charlie := test.NewUser(t)
ctx := context.Background()
spaceChild := test.NewRoom(t, alice)
validateTuples := []gomatrixserverlib.StateKeyTuple{
{EventType: spec.MRoomCreate},
{EventType: spec.MRoomPowerLevels},
@ -772,8 +773,8 @@ func TestUpgrade(t *testing.T) {
{EventType: spec.MRoomCanonicalAlias},
{EventType: "m.room.tombstone"},
{EventType: "m.custom.event"},
{EventType: "m.space.child", StateKey: spaceChild.ID},
{EventType: "m.custom.event", StateKey: alice.ID},
{EventType: spec.MRoomMember, StateKey: bob.ID}, // invite should be transferred
{EventType: spec.MRoomMember, StateKey: charlie.ID}, // ban should be transferred
}
@ -984,13 +985,10 @@ func TestUpgrade(t *testing.T) {
},
},
{
name: "invites/bans are transferred",
name: "bans are transferred",
upgradeUser: alice.ID,
roomFunc: func(rsAPI api.RoomserverInternalAPI) string {
r := test.NewRoom(t, alice)
r.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": spec.Invite,
}, test.WithStateKey(bob.ID))
r.CreateAndInsert(t, alice, spec.MRoomMember, map[string]interface{}{
"membership": spec.Ban,
}, test.WithStateKey(charlie.ID))
@ -1002,6 +1000,21 @@ func TestUpgrade(t *testing.T) {
wantNewRoom: true,
validateFunc: validate,
},
{
name: "space childs are transferred",
upgradeUser: alice.ID,
roomFunc: func(rsAPI api.RoomserverInternalAPI) string {
r := test.NewRoom(t, alice)
r.CreateAndInsert(t, alice, "m.space.child", map[string]interface{}{}, test.WithStateKey(spaceChild.ID))
if err := api.SendEvents(ctx, rsAPI, api.KindNew, r.Events(), "test", "test", "test", nil, false); err != nil {
t.Errorf("failed to send events: %v", err)
}
return r.ID
},
wantNewRoom: true,
validateFunc: validate,
},
{
name: "custom state is not taken to the new room", // https://github.com/matrix-org/dendrite/issues/2912
upgradeUser: charlie.ID,