Use membership check rather than referring to state directly

This commit is contained in:
Neil Alexander 2022-06-27 12:33:35 +01:00
parent f9e885025e
commit 7090283133
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -268,21 +268,19 @@ func (r *Joiner) performJoinRoomByID(
case nil: case nil:
// The room join is local. Send the new join event into the // The room join is local. Send the new join event into the
// roomserver. First of all check that the user isn't already // roomserver. First of all check that the user isn't already
// a member of the room. // a member of the room. This is best-effort (as in we won't
alreadyJoined := false // fail if we can't find the existing membership) because there
for _, se := range buildRes.StateEvents { // is really no harm in just sending another membership event.
if !se.StateKeyEquals(userID) { membershipReq := &api.QueryMembershipForUserRequest{
continue RoomID: req.RoomIDOrAlias,
} UserID: userID,
if membership, merr := se.Membership(); merr == nil {
alreadyJoined = (membership == gomatrixserverlib.Join)
break
}
} }
membershipRes := &api.QueryMembershipForUserResponse{}
_ = r.Queryer.QueryMembershipForUser(ctx, membershipReq, membershipRes)
// If we haven't already joined the room then send an event // If we haven't already joined the room then send an event
// into the room changing our membership status. // into the room changing our membership status.
if !alreadyJoined { if !membershipRes.RoomExists || !membershipRes.IsInRoom {
inputReq := rsAPI.InputRoomEventsRequest{ inputReq := rsAPI.InputRoomEventsRequest{
InputRoomEvents: []rsAPI.InputRoomEvent{ InputRoomEvents: []rsAPI.InputRoomEvent{
{ {