Skip to content

Commit

Permalink
Merge pull request #482 from tchapgouv/phlpro/479
Browse files Browse the repository at this point in the history
Invite by email a new user failed (#479)
  • Loading branch information
Phl-Pro authored Mar 18, 2022
2 parents aa155fa + f483757 commit 6d56050
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 23 deletions.
19 changes: 7 additions & 12 deletions Tchap/Managers/Invite/InviteService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<InviteServiceResult>) -> Void) {
Expand Down Expand Up @@ -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<InviteServiceDiscoverUserResult>) -> 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))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
}
3 changes: 0 additions & 3 deletions Tchap/Modules/Contacts/DataSources/ContactsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
1 change: 0 additions & 1 deletion Tchap/Modules/Home/HomeCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ final class HomeCoordinator: NSObject, HomeCoordinatorType {
}

_ = self.thirdPartyIDResolver.bulkLookup(threepids: threepids,
identityServer: self.identityServer,
success: success,
failure: failure)
}
Expand Down
1 change: 1 addition & 0 deletions changelog.d/479.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix Invite by email a new user failed

0 comments on commit 6d56050

Please sign in to comment.