From 5a7d36d1b3166632763c34fac35bf55c2c3d8353 Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Wed, 12 Jul 2023 14:48:44 +0200 Subject: [PATCH] Only leave/kick if the redacted event is the current state event --- roomserver/internal/input/input_events.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/roomserver/internal/input/input_events.go b/roomserver/internal/input/input_events.go index 81e2e2b9d..db3cd1986 100644 --- a/roomserver/internal/input/input_events.go +++ b/roomserver/internal/input/input_events.go @@ -526,8 +526,19 @@ func (r *Inputer) processRoomEvent( // leavePseudoIDRoom leaves/kicks a user in the event of a membership event redaction. // TODO: This doesn't play well with users re-joining rooms, as in this case we have multiple join events with a mxid_mapping. func (r *Inputer) leavePseudoIDRoom(ctx context.Context, roomID spec.RoomID, originalRedactedEvent, redactionEvent gomatrixserverlib.PDU) error { + + stateKey := originalRedactedEvent.StateKey() + currentStateEvent, err := r.DB.GetStateEvent(ctx, roomID.String(), originalRedactedEvent.Type(), *stateKey) + if err != nil { + return err + } + // If the redacted event is NOT the current state event, do nothing + if currentStateEvent.EventID() != originalRedactedEvent.EventID() { + return nil + } + var memberContent gomatrixserverlib.MemberContent - if err := json.Unmarshal(originalRedactedEvent.Content(), &memberContent); err != nil { + if err = json.Unmarshal(originalRedactedEvent.Content(), &memberContent); err != nil { return err } if memberContent.Membership != spec.Join { @@ -549,9 +560,6 @@ func (r *Inputer) leavePseudoIDRoom(ctx context.Context, roomID spec.RoomID, ori return nil } - // check that the redacted event is the _current_ membership event - stateKey := originalRedactedEvent.StateKey() - signingIdentity, err := r.SigningIdentity(ctx, roomID, *userID) if err != nil { return err