From 16b49c721f995eeb7fda6a376792a125a707b3f6 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Wed, 16 Mar 2022 09:38:40 +0100 Subject: [PATCH] Invite by email a new user failed (#479) --- Tchap/Managers/Invite/InviteService.swift | 11 +---------- .../ThirdPartyIDResolver/ThirdPartyIDResolver.swift | 4 ++-- changelog.d/479.bugfix | 1 + 3 files changed, 4 insertions(+), 12 deletions(-) create mode 100644 changelog.d/479.bugfix diff --git a/Tchap/Managers/Invite/InviteService.swift b/Tchap/Managers/Invite/InviteService.swift index 9bd687c825..88eb5e9881 100644 --- a/Tchap/Managers/Invite/InviteService.swift +++ b/Tchap/Managers/Invite/InviteService.swift @@ -28,7 +28,6 @@ final class InviteService: InviteServiceType { private let session: MXSession private let discussionFinder: DiscussionFinderType - private let identityService: MXIdentityService private let userService: UserServiceType private let roomService: RoomServiceType @@ -40,14 +39,6 @@ final class InviteService: InviteServiceType { self.discussionFinder = DiscussionFinder(session: session) self.userService = UserService(session: session) self.roomService = RoomService(session: session) - - let server = session.matrixRestClient.identityServer ?? session.matrixRestClient.homeserver - // swiftlint:disable force_unwrapping - let identityServerURL = URL(string: server!)! - // swiftlint:enable force_unwrapping - self.identityService = MXIdentityService(identityServer: identityServerURL, - accessToken: nil, - homeserverRestClient: self.session.matrixRestClient) } func sendEmailInvite(to email: String, completion: @escaping (MXResponse) -> Void) { @@ -120,7 +111,7 @@ final class InviteService: InviteServiceType { // Check whether a Tchap account has been created for this email. The closure returns a nil identifier when no account exists. private func discoverUser(with email: String, completion: @escaping (MXResponse) -> Void) { let pid = MX3PID(medium: .email, address: email) - _ = self.identityService.lookup3PIDs([pid]) { response in + _ = self.session.identityService.lookup3PIDs([pid]) { response in if let responseValue = response.value?[pid] { completion(MXResponse.success(.bound(userID: responseValue))) } else { diff --git a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift index a69475c625..a5b2137c58 100644 --- a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift +++ b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift @@ -40,9 +40,9 @@ final class ThirdPartyIDResolver: NSObject, ThirdPartyIDResolverType { guard let identityServerURL = URL(string: identityServer) else { return nil } - + let accessToken = session.credentials.accessToken let identityService = MXIdentityService(identityServer: identityServerURL, - accessToken: nil, + accessToken: accessToken, homeserverRestClient: self.session.matrixRestClient) let pids: [MX3PID]? = threepids.compactMap { tempPid in return MX3PID.threePidFromArray(tempPid) diff --git a/changelog.d/479.bugfix b/changelog.d/479.bugfix new file mode 100644 index 0000000000..12ef48b8ce --- /dev/null +++ b/changelog.d/479.bugfix @@ -0,0 +1 @@ +Fix Invite by email a new user failed