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 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
3 changes: 0 additions & 3 deletions Riot/Modules/Application/AppCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -573,9 +573,6 @@ extension AppCoordinator: SplitViewCoordinatorDelegate {
// MARK: - SideMenuCoordinatorDelegate
extension AppCoordinator: SideMenuCoordinatorDelegate {
func sideMenuCoordinator(_ coordinator: SideMenuCoordinatorType, didTapMenuItem menuItem: SideMenuItem, fromSourceView sourceView: UIView) {
if menuItem == .inviteFriends {
self.splitViewCoordinator?.presentInvitePeople()
}
}
}

Expand Down
95 changes: 9 additions & 86 deletions Riot/Modules/Home/AllChats/AllChatsCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ class AllChatsCoordinatorParameters {
}

class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
func presentInvitePeople() {
//
}


// MARK: Properties

// MARK: Private
Expand Down Expand Up @@ -80,8 +75,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 +353,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 @@ -644,17 +637,14 @@ class AllChatsCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
// }

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)
}

// Tchap: commented because Tchap now uses Element Direct Message mechanism

// let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""
//
// let inviteFriendsPresenter = InviteFriendsPresenter()
// inviteFriendsPresenter.present(for: myUserId, from: self.navigationRouter.toPresentable(), sourceView: sourceView, animated: true)
}

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

Expand Down Expand Up @@ -909,73 +899,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
2 changes: 2 additions & 0 deletions Riot/Modules/SideMenu/SideMenuCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ final class SideMenuCoordinator: NSObject, SideMenuCoordinatorType {
}

private func showInviteFriends(from sourceView: UIView?) {
// Tchap: commented because Tchap now uses Element Direct Message mechanism

// let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""
//
// let inviteFriendsPresenter = InviteFriendsPresenter()
Expand Down
4 changes: 0 additions & 4 deletions Riot/Modules/SplitView/SplitViewCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ final class SplitViewCoordinator: NSObject, SplitViewCoordinatorType {
func showAppStateIndicator(with text: String, icon: UIImage?) {
masterCoordinator?.showAppStateIndicator(with: text, icon: icon)
}

func presentInvitePeople() {
masterCoordinator?.presentInvitePeople()
}

// MARK: - Private methods

Expand Down
4 changes: 0 additions & 4 deletions Riot/Modules/SplitView/SplitViewCoordinatorType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,4 @@ protocol SplitViewCoordinatorType: Coordinator, Presentable {

/// Hide the message related to the application state currently displayed.
func hideAppStateIndicator()

// Tchap: redirect to invite people alert
/// Present invite people alert (with textField)
func presentInvitePeople()
}
4 changes: 0 additions & 4 deletions Riot/Modules/TabBar/SplitViewMasterCoordinatorProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,4 @@ protocol SplitViewMasterCoordinatorProtocol: Coordinator, SplitViewMasterPresent

/// Hide the message related to the application state currently displayed.
func hideAppStateIndicator()

// Tchap: redirect to invite people alert
/// Present invite people alert (with textField)
func presentInvitePeople()
}
87 changes: 7 additions & 80 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 @@ -238,12 +236,6 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
appSateIndicator = nil
}

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

// MARK: - SplitViewMasterPresentable

var selectedNavigationRouter: NavigationRouterType? {
Expand All @@ -262,10 +254,12 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
}

private func showInviteFriends(from sourceView: UIView?) {
let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""

let inviteFriendsPresenter = InviteFriendsPresenter()
inviteFriendsPresenter.present(for: myUserId, from: self.navigationRouter.toPresentable(), sourceView: sourceView, animated: true)
// Tchap: commented because Tchap now uses Element Direct Message mechanism

// let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""
//
// let inviteFriendsPresenter = InviteFriendsPresenter()
// inviteFriendsPresenter.present(for: myUserId, from: self.navigationRouter.toPresentable(), sourceView: sourceView, animated: true)
}

private func showBugReport() {
Expand Down Expand Up @@ -797,7 +791,7 @@ final class TabBarCoordinator: NSObject, SplitViewMasterCoordinatorProtocol {
var subMenuActions: [UIAction] = []
if BuildSettings.sideMenuShowInviteFriends {
subMenuActions.append(UIAction(title: VectorL10n.inviteTo(AppInfo.current.displayName), image: UIImage(systemName: "envelope")) { [weak self] action in
self?.showInviteFriends(from: nil)
self?.showInviteFriends(from: nil)
})
}

Expand Down Expand Up @@ -1018,73 +1012,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