diff --git a/Tchap/Managers/Invite/InviteService.swift b/Tchap/Managers/Invite/InviteService.swift index 9bd687c825..062bf568e7 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) { @@ -119,13 +110,17 @@ 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) { + guard let identityService = self.session.identityService else { + MXLog.debug("[InviteService] discoverUser failed") + completion(MXResponse.failure(InviteServiceError.unknown)) + return + } let pid = MX3PID(medium: .email, address: email) - _ = self.identityService.lookup3PIDs([pid]) { response in + _ = identityService.lookup3PIDs([pid]) { response in if let responseValue = response.value?[pid] { completion(MXResponse.success(.bound(userID: responseValue))) } else { - MXLog.debug("[InviteService] discoverUser failed") - completion(MXResponse.failure(InviteServiceError.unknown)) + completion(MXResponse.success(.unbound)) } } } diff --git a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift index a69475c625..6b440194ac 100644 --- a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift +++ b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolver.swift @@ -33,17 +33,13 @@ final class ThirdPartyIDResolver: NSObject, ThirdPartyIDResolverType { // MARK: - Public @objc func bulkLookup(threepids: [[String]], - identityServer: String, success: @escaping (([[String]]) -> Void), failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? { - guard let identityServerURL = URL(string: identityServer) else { + guard let identityService = session.identityService else { return nil } - let identityService = MXIdentityService(identityServer: identityServerURL, - accessToken: nil, - homeserverRestClient: self.session.matrixRestClient) let pids: [MX3PID]? = threepids.compactMap { tempPid in return MX3PID.threePidFromArray(tempPid) } diff --git a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolverType.swift b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolverType.swift index 1ebf0b813e..783034c2a9 100644 --- a/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolverType.swift +++ b/Tchap/Managers/ThirdPartyIDResolver/ThirdPartyIDResolverType.swift @@ -30,10 +30,11 @@ protocol ThirdPartyIDResolverType { /// /// - Parameters: /// - threepids: the list of 3rd party ids - /// - identityServer: the url of the identity server to proxy the request to if the homeserver is allowed to do so /// - success: A block object called when the operation succeeded. /// - failure: A block object called when the operation failed. /// /// - returns: a `MXHTTPOperation` instance. - func bulkLookup(threepids: [[String]], identityServer: String, success: @escaping (([[String]]) -> Void), failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? + func bulkLookup(threepids: [[String]], + success: @escaping (([[String]]) -> Void), + failure: @escaping ((Error) -> Void)) -> MXHTTPOperation? } diff --git a/Tchap/Modules/Contacts/DataSources/ContactsDataSource.m b/Tchap/Modules/Contacts/DataSources/ContactsDataSource.m index ea663e2743..de54f68a26 100644 --- a/Tchap/Modules/Contacts/DataSources/ContactsDataSource.m +++ b/Tchap/Modules/Contacts/DataSources/ContactsDataSource.m @@ -690,10 +690,7 @@ - (void)updateDirectTchapContacts } }; - // Tchap: Consider the homeserver if the identity server is missing (this was the old behavior in Riot) - NSString *identityServer = self.mxSession.matrixRestClient.identityServer ? self.mxSession.matrixRestClient.identityServer : self.mxSession.matrixRestClient.homeserver; self->lookup3pidsOperation = [thirdPartyIDResolver bulkLookupWithThreepids:lookup3pidsArray - identityServer:identityServer success:success failure:^(NSError *error) { NSLog(@"[ContactsDataSource] lookup3pids failed"); diff --git a/Tchap/Modules/Home/HomeCoordinator.swift b/Tchap/Modules/Home/HomeCoordinator.swift index e820e1e76b..3beb52281b 100644 --- a/Tchap/Modules/Home/HomeCoordinator.swift +++ b/Tchap/Modules/Home/HomeCoordinator.swift @@ -190,7 +190,6 @@ final class HomeCoordinator: NSObject, HomeCoordinatorType { } _ = self.thirdPartyIDResolver.bulkLookup(threepids: threepids, - identityServer: self.identityServer, success: success, failure: failure) } 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