Skip to content
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
8 changes: 4 additions & 4 deletions FlowCrypt/App/AppContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AppContext {
let keyService = KeyService(
storage: encryptedStorage,
passPhraseService: passPhraseService,
currentUserEmail: { encryptedStorage.activeUser?.email }
currentUserEmail: { try? encryptedStorage.activeUser?.email }
)
let clientConfigurationService = ClientConfigurationService(
local: LocalClientConfiguration(
Expand All @@ -58,10 +58,10 @@ class AppContext {
return AppContext(
encryptedStorage: encryptedStorage,
session: nil, // will be set later. But would be nice to already set here, if available
userAccountService: SessionService(
userAccountService: try SessionService(
encryptedStorage: encryptedStorage,
googleService: GoogleUserService(
currentUserEmail: encryptedStorage.activeUser?.email,
currentUserEmail: try encryptedStorage.activeUser?.email,
appDelegateGoogleSessionContainer: UIApplication.shared.delegate as? AppDelegate
)
),
Expand Down Expand Up @@ -98,7 +98,7 @@ class AppContext {
@MainActor
func getOptionalMailProvider() -> MailProvider? {
guard
let currentUser = encryptedStorage.activeUser,
let currentUser = try? encryptedStorage.activeUser,
let currentAuthType = currentUser.authType
else { return nil }

Expand Down
16 changes: 10 additions & 6 deletions FlowCrypt/Controllers/Compose/ComposeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ final class ComposeViewController: TableNodeViewController {
filesManager: FilesManagerType = FilesManager(),
photosManager: PhotosManagerType = PhotosManager(),
keyMethods: KeyMethodsType = KeyMethods()
) {
) throws {
self.appContext = appContext
self.email = appContext.user.email
self.notificationCenter = notificationCenter
self.input = input
self.decorator = decorator
let clientConfiguration = appContext.clientConfigurationService.getSaved(for: appContext.user.email)
let clientConfiguration = try appContext.clientConfigurationService.getSaved(for: appContext.user.email)
self.contactsService = contactsService ?? ContactsService(
localContactsProvider: LocalContactsProvider(
encryptedStorage: appContext.encryptedStorage
Expand Down Expand Up @@ -942,10 +942,14 @@ extension ComposeViewController {
extension ComposeViewController {
private func searchEmail(with query: String) {
Task {
let localEmails = contactsService.searchLocalContacts(query: query)
let cloudEmails = try? await service.searchContacts(query: query)
let emails = Set([localEmails, cloudEmails].compactMap { $0 }.flatMap { $0 })
updateState(with: .searchEmails(Array(emails)))
do {
let localEmails = try contactsService.searchLocalContacts(query: query)
let cloudEmails = try? await service.searchContacts(query: query)
let emails = Set([localEmails, cloudEmails].compactMap { $0 }.flatMap { $0 })
updateState(with: .searchEmails(Array(emails)))
} catch {
showAlert(message: error.localizedDescription)
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions FlowCrypt/Controllers/Inbox/InboxViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,13 @@ extension InboxViewController {
}

private func btnComposeTap() {
TapTicFeedback.generate(.light)
let composeVc = ComposeViewController(appContext: appContext)
navigationController?.pushViewController(composeVc, animated: true)
do {
TapTicFeedback.generate(.light)
let composeVc = try ComposeViewController(appContext: appContext)
navigationController?.pushViewController(composeVc, animated: true)
} catch {
showAlert(message: error.localizedDescription)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ extension MsgListViewController where Self: UIViewController {

// TODO: uncomment in "sent message from draft" feature
private func openDraft(appContext: AppContextWithUser, with message: Message) {
let controller = ComposeViewController(appContext: appContext)
controller.update(with: message)
navigationController?.pushViewController(controller, animated: true)
do {
let controller = try ComposeViewController(appContext: appContext)
controller.update(with: message)
navigationController?.pushViewController(controller, animated: true)
} catch {
showAlert(message: error.localizedDescription)
}
}

private func openMsg(appContext: AppContextWithUser, with message: Message, path: String) {
Expand All @@ -47,13 +51,17 @@ extension MsgListViewController where Self: UIViewController {
}

private func openThread(with thread: MessageThread, appContext: AppContextWithUser) {
let viewController = ThreadDetailsViewController(
appContext: appContext,
thread: thread
) { [weak self] (action, message) in
self?.handleMessageOperation(with: message, action: action)
do {
let viewController = try ThreadDetailsViewController(
appContext: appContext,
thread: thread
) { [weak self] (action, message) in
self?.handleMessageOperation(with: message, action: action)
}
navigationController?.pushViewController(viewController, animated: true)
} catch {
showAlert(message: error.localizedDescription)
}
navigationController?.pushViewController(viewController, animated: true)
}

// MARK: Operation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ final class KeySettingsViewController: TableNodeViewController {
init(
appContext: AppContextWithUser,
decorator: KeySettingsViewDecorator = KeySettingsViewDecorator()
) {
) throws {
self.appContext = appContext
self.decorator = decorator
self.isUsingKeyManager = appContext.clientConfigurationService.getSaved(for: appContext.user.email).isUsingKeyManager
self.isUsingKeyManager = try appContext.clientConfigurationService.getSaved(for: appContext.user.email).isUsingKeyManager
super.init(node: TableNode())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ final class SettingsViewController: TableNodeViewController {
init(
appContext: AppContextWithUser,
decorator: SettingsViewDecorator = SettingsViewDecorator()
) {
) throws {
self.appContext = appContext
self.decorator = decorator
self.clientConfiguration = appContext.clientConfigurationService.getSaved(for: appContext.user.email)
self.clientConfiguration = try appContext.clientConfigurationService.getSaved(for: appContext.user.email)
self.rows = SettingsMenuItem.filtered(with: clientConfiguration)
super.init(node: TableNode())
}
Expand Down Expand Up @@ -113,7 +113,12 @@ extension SettingsViewController {

switch setting {
case .keys:
viewController = KeySettingsViewController(appContext: appContext)
do {
viewController = try KeySettingsViewController(appContext: appContext)
} catch {
viewController = nil
showAlert(message: error.localizedDescription)
}
case .legal:
viewController = LegalViewController()
case .contacts:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ final class SetupGenerateKeyViewController: SetupCreatePassphraseAbstractViewCon
init(
appContext: AppContextWithUser,
decorator: SetupViewDecorator = SetupViewDecorator()
) {
) throws {
self.attester = AttesterApi(
clientConfiguration: appContext.clientConfigurationService.getSaved(for: appContext.user.email)
clientConfiguration: try appContext.clientConfigurationService.getSaved(for: appContext.user.email)
)
self.service = Service(
appContext: appContext,
Expand Down
12 changes: 8 additions & 4 deletions FlowCrypt/Controllers/Setup/SetupInitialViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ final class SetupInitialViewController: TableNodeViewController {
appContext: AppContextWithUser,
decorator: SetupViewDecorator = SetupViewDecorator(),
emailKeyManagerApi: EmailKeyManagerApiType? = nil
) {
) throws {
self.appContext = appContext
self.service = ServiceActor(backupService: appContext.getBackupService())
self.decorator = decorator
let clientConfiguration = appContext.clientConfigurationService.getSaved(for: appContext.user.email)
let clientConfiguration = try appContext.clientConfigurationService.getSaved(for: appContext.user.email)
self.emailKeyManagerApi = emailKeyManagerApi ?? EmailKeyManagerApi(clientConfiguration: clientConfiguration)
self.clientConfiguration = clientConfiguration
super.init(node: TableNode())
Expand Down Expand Up @@ -328,8 +328,12 @@ extension SetupInitialViewController {
}

private func proceedToCreatingNewKey() {
let viewController = SetupGenerateKeyViewController(appContext: appContext)
navigationController?.pushViewController(viewController, animated: true)
do {
let viewController = try SetupGenerateKeyViewController(appContext: appContext)
navigationController?.pushViewController(viewController, animated: true)
} catch {
showAlert(message: error.localizedDescription)
}
}

private func proceedToSetupWithEKMKeys(keys: [KeyDetails]) {
Expand Down
17 changes: 13 additions & 4 deletions FlowCrypt/Controllers/SideMenu/Menu/MyMenuViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ final class MyMenuViewController: ViewController {
private var folders: [FolderViewModel] = []
private var serviceItems: [FolderViewModel] { FolderViewModel.menuItems }
private var accounts: [User] {
appContext.encryptedStorage.getAllUsers()
.filter { $0.email != appContext.user.email }
.filter { appContext.encryptedStorage.doesAnyKeypairExist(for: $0.email) }
do {
return try appContext.encryptedStorage.getAllUsers()
.filter { $0.email != appContext.user.email }
.filter { try appContext.encryptedStorage.doesAnyKeypairExist(for: $0.email) }
} catch {
showAlert(message: error.localizedDescription)
return []
}
}

private let tableNode: ASTableNode
Expand Down Expand Up @@ -294,7 +299,11 @@ extension MyMenuViewController {
sideMenuController()?.sideMenu?.hideSideMenu()
return
}
sideMenuController()?.setContentViewController(SettingsViewController(appContext: appContext))
do {
sideMenuController()?.setContentViewController(try SettingsViewController(appContext: appContext))
} catch {
showAlert(message: error.localizedDescription)
}
case .logOut:
do {
try appContext.globalRouter.signOut(appContext: appContext)
Expand Down
16 changes: 10 additions & 6 deletions FlowCrypt/Controllers/Threads/ThreadDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ final class ThreadDetailsViewController: TableNodeViewController {
messageService: MessageService? = nil,
thread: MessageThread,
completion: @escaping MessageActionCompletion
) {
) throws {
self.appContext = appContext
let clientConfiguration = appContext.clientConfigurationService.getSaved(for: appContext.user.email)
let clientConfiguration = try appContext.clientConfigurationService.getSaved(for: appContext.user.email)
self.messageService = messageService ?? MessageService(
contactsService: ContactsService(
localContactsProvider: LocalContactsProvider(
Expand Down Expand Up @@ -259,10 +259,14 @@ extension ThreadDetailsViewController {
}()

let composeInput = ComposeMessageInput(type: composeType)
navigationController?.pushViewController(
ComposeViewController(appContext: appContext, input: composeInput),
animated: true
)
do {
navigationController?.pushViewController(
try ComposeViewController(appContext: appContext, input: composeInput),
animated: true
)
} catch {
showAlert(message: error.localizedDescription)
}
}

private func markAsRead(at index: Int) {
Expand Down
Loading