diff --git a/clientapi/routing/membership.go b/clientapi/routing/membership.go index c6744ed855..60b120b9ce 100644 --- a/clientapi/routing/membership.go +++ b/clientapi/routing/membership.go @@ -454,25 +454,6 @@ func buildMembershipEvent( return nil, err } - // If we're inviting a local user, we can generate the needed key here. - if targetSenderID == "" && cfg.Matrix.IsLocalServerName(targetID.Domain()) { // todo: remove - var roomVersion gomatrixserverlib.RoomVersion - roomVersion, err = rsAPI.QueryRoomVersionForRoom(ctx, roomID) - if err != nil { - return nil, err - } - switch roomVersion { - case gomatrixserverlib.RoomVersionPseudoIDs: - var key ed25519.PrivateKey - key, err = rsAPI.GetOrCreateUserRoomPrivateKey(ctx, *targetID, *validRoomID) - if err != nil { - return nil, err - } - targetSenderID = spec.SenderIDFromPseudoIDKey(key) - } - - } - identity, err := rsAPI.SigningIdentityFor(ctx, *validRoomID, *userID) if err != nil { return nil, err diff --git a/roomserver/internal/perform/perform_invite.go b/roomserver/internal/perform/perform_invite.go index babd5f8123..f19a508a3a 100644 --- a/roomserver/internal/perform/perform_invite.go +++ b/roomserver/internal/perform/perform_invite.go @@ -153,6 +153,23 @@ func (r *Inviter) PerformInvite( } isTargetLocal := r.Cfg.Matrix.IsLocalServerName(invitedUser.Domain()) + // If we're inviting a local user, we can generate the needed pseudoID key here. (if needed) + if isTargetLocal { + var roomVersion gomatrixserverlib.RoomVersion + roomVersion, err = r.DB.GetRoomVersion(ctx, event.RoomID()) + if err != nil { + return err + } + + switch roomVersion { + case gomatrixserverlib.RoomVersionPseudoIDs: + _, err = r.RSAPI.GetOrCreateUserRoomPrivateKey(ctx, *invitedUser, *validRoomID) + if err != nil { + return err + } + } + } + invitedSenderID, err := r.RSAPI.QuerySenderIDForUser(ctx, *validRoomID, *invitedUser) if err != nil { return fmt.Errorf("failed looking up senderID for invited user")