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

837 inviter a rejoindre tchap erreur avec le mainlining 1 83 #891

Merged
Show file tree
Hide file tree
Changes from 3 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
83 changes: 1 addition & 82 deletions Riot/Modules/Home/AllChats/AllChatsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {

private var indicators = [UserIndicator]()
private var signOutFlowPresenter: SignOutFlowPresenter?
// Tchap: Add invite service for user invitation
private var inviteService: InviteServiceType?
private var errorPresenter: ErrorPresenter?
private weak var currentAlertController: UIAlertController?

Expand Down Expand Up @@ -360,7 +358,7 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
!UserService.isExternalUser(for: userID) {
subMenuActions.append(UIAction(title: TchapL10n.sideMenuActionInviteFriends, image: UIImage(systemName: "square.and.arrow.up.fill")) { [weak self] action in
guard let self = self else { return }
self.showInviteFriends(from: self.avatarMenuButton)
self.allChatsViewController.startChat()
})
}
}
Expand Down Expand Up @@ -643,18 +641,6 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
// return versionCheckCoordinator
// }

private func showInviteFriends(from sourceView: UIView?) {
// Tchap: Use Tchap specific mechanism.
promptUserToFillAnEmailToInvite { [weak self] email in
self?.sendEmailInvite(to: email)
}

// let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""
//
// let inviteFriendsPresenter = InviteFriendsPresenter()
// inviteFriendsPresenter.present(for: myUserId, from: self.navigationRouter.toPresentable(), sourceView: sourceView, animated: true)
}
yostyle marked this conversation as resolved.
Show resolved Hide resolved

private func showBugReport() {
let bugReportViewController = BugReportViewController()

Expand Down Expand Up @@ -909,73 +895,6 @@ extension AllChatsCoordinator {

self.navigationRouter.toPresentable().present(alertController, animated: true)
}

private func sendEmailInvite(to email: String) {
guard let session = self.currentMatrixSession else { return }
if self.inviteService == nil {
self.inviteService = InviteService(session: session)
}
guard let inviteService = self.inviteService else { return }

self.activityIndicatorPresenter.presentActivityIndicator(on: self.navigationRouter.toPresentable().view, animated: true)
inviteService.sendEmailInvite(to: email) { [weak self] (response) in
guard let sself = self else {
return
}

sself.activityIndicatorPresenter.removeCurrentActivityIndicator(animated: true)
switch response {
case .success(let result):
var message: String
var discoveredUserID: String?
switch result {
case .inviteHasBeenSent(roomID: _):
message = TchapL10n.inviteSendingSucceeded
case .inviteAlreadySent(roomID: _):
message = TchapL10n.inviteAlreadySentByEmail(email)
yostyle marked this conversation as resolved.
Show resolved Hide resolved
case .inviteIgnoredForDiscoveredUser(userID: let userID):
yostyle marked this conversation as resolved.
Show resolved Hide resolved
discoveredUserID = userID
message = TchapL10n.inviteNotSentForDiscoveredUser
case .inviteIgnoredForUnauthorizedEmail:
message = TchapL10n.inviteNotSentForUnauthorizedEmail(email)
}

sself.currentAlertController?.dismiss(animated: false)

let alert = UIAlertController(title: TchapL10n.inviteInformationTitle, message: message, preferredStyle: .alert)

let okTitle = VectorL10n.ok
let okAction = UIAlertAction(title: okTitle, style: .default, handler: { action in
if let userID = discoveredUserID {
// Open the discussion
AppDelegate.theDelegate().startDirectChat(withUserId: userID, completion: nil)
}
})
alert.addAction(okAction)
sself.currentAlertController = alert

sself.navigationRouter.toPresentable().present(alert, animated: true, completion: nil)
case .failure(let error):
let errorPresentable = sself.inviteErrorPresentable(from: error)
sself.errorPresenter?.present(errorPresentable: errorPresentable, animated: true)
}
}
}

private func inviteErrorPresentable(from error: Error) -> ErrorPresentable {
let errorTitle = TchapL10n.inviteSendingFailedTitle
let errorMessage: String

let nsError = error as NSError

if let message = nsError.userInfo[NSLocalizedDescriptionKey] as? String {
errorMessage = message
} else {
errorMessage = TchapL10n.errorMessageDefault
}

return ErrorPresentableImpl(title: errorTitle, message: errorMessage)
}
}

// Tchap: Add delegate for Room Preview
Expand Down
71 changes: 1 addition & 70 deletions Riot/Modules/TabBar/TabBarCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
}

private var indicators = [UserIndicator]()
// Tchap: Add invite service for user invitation
private var inviteService: InviteServiceType?
private var errorPresenter: ErrorPresenter?
private weak var currentAlertController: UIAlertController?

Expand Down Expand Up @@ -240,7 +238,7 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {

func presentInvitePeople() {
promptUserToFillAnEmailToInvite { [weak self] email in
self?.sendEmailInvite(to: email)
yostyle marked this conversation as resolved.
Show resolved Hide resolved

}
}

Expand Down Expand Up @@ -1018,73 +1016,6 @@ extension TabBarCoordinator {

masterTabBarController.present(alertController, animated: true)
}

private func sendEmailInvite(to email: String) {
guard let session = self.currentMatrixSession else { return }
if self.inviteService == nil {
self.inviteService = InviteService(session: session)
}
guard let inviteService = self.inviteService else { return }

self.activityIndicatorPresenter.presentActivityIndicator(on: masterTabBarController.view, animated: true)
inviteService.sendEmailInvite(to: email) { [weak self] (response) in
guard let sself = self else {
return
}

sself.activityIndicatorPresenter.removeCurrentActivityIndicator(animated: true)
switch response {
case .success(let result):
var message: String
var discoveredUserID: String?
switch result {
case .inviteHasBeenSent(roomID: _):
message = TchapL10n.inviteSendingSucceeded
case .inviteAlreadySent(roomID: _):
message = TchapL10n.inviteAlreadySentByEmail(email)
case .inviteIgnoredForDiscoveredUser(userID: let userID):
discoveredUserID = userID
message = TchapL10n.inviteNotSentForDiscoveredUser
case .inviteIgnoredForUnauthorizedEmail:
message = TchapL10n.inviteNotSentForUnauthorizedEmail(email)
}

sself.currentAlertController?.dismiss(animated: false)

let alert = UIAlertController(title: TchapL10n.inviteInformationTitle, message: message, preferredStyle: .alert)

let okTitle = VectorL10n.ok
let okAction = UIAlertAction(title: okTitle, style: .default, handler: { action in
if let userID = discoveredUserID {
// Open the discussion
AppDelegate.theDelegate().startDirectChat(withUserId: userID, completion: nil)
}
})
alert.addAction(okAction)
sself.currentAlertController = alert

sself.masterTabBarController.present(alert, animated: true, completion: nil)
case .failure(let error):
let errorPresentable = sself.inviteErrorPresentable(from: error)
sself.errorPresenter?.present(errorPresentable: errorPresentable, animated: true)
}
}
}

private func inviteErrorPresentable(from error: Error) -> ErrorPresentable {
let errorTitle = TchapL10n.inviteSendingFailedTitle
let errorMessage: String

let nsError = error as NSError

if let message = nsError.userInfo[NSLocalizedDescriptionKey] as? String {
errorMessage = message
} else {
errorMessage = TchapL10n.errorMessageDefault
}

return ErrorPresentableImpl(title: errorTitle, message: errorMessage)
}
}

// MARK: - MasterTabBarControllerDelegate
Expand Down
Loading
Loading