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

Update message forwarding from Element changes #437

Merged
merged 2 commits into from
Dec 21, 2021
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
5 changes: 0 additions & 5 deletions Tchap/Generated/Storyboards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<Tchap.ForgotPasswordVerifyEmailViewController>(storyboard: ForgotPasswordVerifyEmailViewController.self)
}
internal enum ForwardViewController: StoryboardType {
internal static let storyboardName = "ForwardViewController"

internal static let initialScene = InitialSceneType<Tchap.ForwardViewController>(storyboard: ForwardViewController.self)
}
internal enum HomeViewController: StoryboardType {
internal static let storyboardName = "HomeViewController"

Expand Down
87 changes: 15 additions & 72 deletions Tchap/Modules/Forward/ForwardCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,37 @@ import Foundation
final class ForwardCoordinator: NSObject, ForwardCoordinatorType {

private let router: NavigationRouterType
private let forwardViewController: ForwardViewController
private let session: MXSession
private let content: [AnyHashable: Any]
private let shareItemProvider: SimpleShareItemProvider
private var errorPresenter: ErrorPresenter!
private var recentsViewController: ForwardRecentListViewController!
private var shareManager: ShareManager

var childCoordinators: [Coordinator] = []

// MARK: - Setup

init(session: MXSession, content: [AnyHashable: Any]) {
self.router = NavigationRouter(navigationController: RiotNavigationController())
init(session: MXSession, shareItemProvider: SimpleShareItemProvider) {
let navController = RiotNavigationController()
navController.navigationBar.isHidden = true
self.router = NavigationRouter(navigationController: navController)
self.session = session
self.content = content
let recentsViewController = ForwardRecentListViewController()
recentsViewController.displayList(ForwardDataSource(matrixSession: session))
self.recentsViewController = recentsViewController

let viewController = ForwardViewController.instantiate()
self.forwardViewController = viewController
self.shareItemProvider = shareItemProvider

self.shareManager = ShareManager(shareItemProvider: shareItemProvider, type: .forward)

self.errorPresenter = AlertErrorPresenter(viewControllerPresenter: shareManager.mainViewController())

self.errorPresenter = AlertErrorPresenter(viewControllerPresenter: viewController)

super.init()

viewController.delegate = self
recentsViewController.delegate = self
self.shareManager.completionCallback = { result in
self.router.dismissModule(animated: true, completion: nil)
}
}

// MARK: - Public

func start() {
self.forwardViewController.recentsViewController = self.recentsViewController

self.router.setRootModule(forwardViewController)
self.router.setRootModule(shareManager.mainViewController())
}

func toPresentable() -> UIViewController {
Expand All @@ -77,56 +73,3 @@ final class ForwardCoordinator: NSObject, ForwardCoordinatorType {
return ErrorPresentableImpl(title: errorTitle, message: errorMessage)
}
}

// MARK: - ForwardViewControllerDelegate

extension ForwardCoordinator: ForwardViewControllerDelegate {
func forwardControllerCancelButtonClicked(_ viewController: ForwardViewController) {
self.router.dismissModule(animated: true, completion: nil)
}

func forwardController(_ viewController: ForwardViewController, searchBar: UISearchBar, textDidChange searchText: String) {
let patterns = searchText.isEmpty ? nil : [searchText]
self.recentsViewController.dataSource.search(withPatterns: patterns)
}

func forwardController(_ viewController: ForwardViewController, searchBarCancelButtonClicked searchBar: UISearchBar) {
searchBar.text = ""
self.recentsViewController.dataSource.search(withPatterns: nil)
searchBar.resignFirstResponder()
}
}

// MARK: - MXKRecentListViewControllerDelegate

extension ForwardCoordinator: MXKRecentListViewControllerDelegate {
func recentListViewController(_ recentListViewController: MXKRecentListViewController!, didSelectRoom roomId: String!, inMatrixSession mxSession: MXSession!) {
MXKRoomDataSourceManager.sharedManager(forMatrixSession: session)?.roomDataSource(forRoom: roomId, create: true, onComplete: { (dataSource) in
if let dataSource = dataSource {
self.forwardViewController.startActivityIndicator()
dataSource.sendMessage(withContent: self.content) { (response) in
self.didForwardTo(roomId, response: response)
} failure: { (error) in
self.didForwardTo(roomId, error: error)
}
} else {
let error = NSError(domain: "ForwardCoordinatorErrorDomain", code: 0)
self.didForwardTo(roomId, error: error)
}
})
}

private func didForwardTo(_ roomId: String, response: String? = nil, error: Error? = nil) {
self.forwardViewController.stopActivityIndicator()

if let error = error {
self.errorPresenter.present(errorPresentable: errorPresentable(from: error), animated: true)
} else {
self.router.dismissModule(animated: true, completion: nil)
}
}

func recentListViewController(_ recentListViewController: MXKRecentListViewController!, didSelectSuggestedRoom childInfo: MXSpaceChildInfo!) {
// FIXME: Missing implementation
}
}
124 changes: 0 additions & 124 deletions Tchap/Modules/Forward/ForwardDataSource.swift

This file was deleted.

57 changes: 0 additions & 57 deletions Tchap/Modules/Forward/ForwardRecentListViewController.swift

This file was deleted.

Loading