add error toast when failing to leave group/community

pull/1023/head
Ryan ZHAO 1 year ago
parent 5015301bad
commit 5f6edff65d

@ -668,7 +668,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
indexPath: indexPath, indexPath: indexPath,
tableView: tableView, tableView: tableView,
threadViewModel: threadViewModel, threadViewModel: threadViewModel,
viewController: self viewController: self,
navigatableStateHolder: viewModel
) )
) )
@ -689,7 +690,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
indexPath: indexPath, indexPath: indexPath,
tableView: tableView, tableView: tableView,
threadViewModel: threadViewModel, threadViewModel: threadViewModel,
viewController: self viewController: self,
navigatableStateHolder: viewModel
) )
) )
@ -735,7 +737,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
indexPath: indexPath, indexPath: indexPath,
tableView: tableView, tableView: tableView,
threadViewModel: threadViewModel, threadViewModel: threadViewModel,
viewController: self viewController: self,
navigatableStateHolder: viewModel
) )
) )

@ -7,7 +7,9 @@ import SignalUtilitiesKit
import SessionMessagingKit import SessionMessagingKit
import SessionUtilitiesKit import SessionUtilitiesKit
public class HomeViewModel { public class HomeViewModel: NavigatableStateHolder {
public let navigatableState: NavigatableState = NavigatableState()
public typealias SectionModel = ArraySection<Section, SessionThreadViewModel> public typealias SectionModel = ArraySection<Section, SessionThreadViewModel>
// MARK: - Section // MARK: - Section

@ -48,7 +48,8 @@ public extension UIContextualAction {
indexPath: IndexPath, indexPath: IndexPath,
tableView: UITableView, tableView: UITableView,
threadViewModel: SessionThreadViewModel, threadViewModel: SessionThreadViewModel,
viewController: UIViewController? viewController: UIViewController?,
navigatableStateHolder: NavigatableStateHolder?
) -> [UIContextualAction]? { ) -> [UIContextualAction]? {
guard !actions.isEmpty else { return nil } guard !actions.isEmpty else { return nil }
@ -406,6 +407,7 @@ public extension UIContextualAction {
dismissOnConfirm: true, dismissOnConfirm: true,
onConfirm: { _ in onConfirm: { _ in
Storage.shared.writeAsync { db in Storage.shared.writeAsync { db in
do {
try SessionThread.deleteOrLeave( try SessionThread.deleteOrLeave(
db, db,
threadId: threadViewModel.threadId, threadId: threadViewModel.threadId,
@ -413,6 +415,28 @@ public extension UIContextualAction {
groupLeaveType: .standard, groupLeaveType: .standard,
calledFromConfigHandling: false calledFromConfigHandling: false
) )
} catch {
DispatchQueue.main.async {
let toastBody: String = {
switch threadViewModel.threadVariant {
case .legacyGroup, .group:
return "groupLeaveErrorFailed"
.put(key: "groupname", value: threadViewModel.displayName)
.localized()
default:
return "communityLeaveError"
.put(key: "communityname", value: threadViewModel.displayName)
.localized()
}
}()
navigatableStateHolder?.showToast(
text: toastBody,
backgroundColor: .backgroundSecondary
)
}
}
} }
viewController?.dismiss(animated: true, completion: nil) viewController?.dismiss(animated: true, completion: nil)

Loading…
Cancel
Save