Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invite by email a new user failed (#479) #482

Merged
merged 3 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a good practice, we would move the guard let as the first position of the block
(let pid... should be archived after the guard let)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this on the last commit.

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