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,
tableView: tableView,
threadViewModel: threadViewModel,
viewController: self
viewController: self,
navigatableStateHolder: viewModel
)
)
@ -689,7 +690,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
indexPath: indexPath,
tableView: tableView,
threadViewModel: threadViewModel,
viewController: self
viewController: self,
navigatableStateHolder: viewModel
)
)
@ -735,7 +737,8 @@ final class HomeVC: BaseVC, SessionUtilRespondingViewController, UITableViewData
indexPath: indexPath,
tableView: tableView,
threadViewModel: threadViewModel,
viewController: self
viewController: self,
navigatableStateHolder: viewModel
)
)

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

@ -48,7 +48,8 @@ public extension UIContextualAction {
indexPath: IndexPath,
tableView: UITableView,
threadViewModel: SessionThreadViewModel,
viewController: UIViewController?
viewController: UIViewController?,
navigatableStateHolder: NavigatableStateHolder?
) -> [UIContextualAction]? {
guard !actions.isEmpty else { return nil }
@ -406,13 +407,36 @@ public extension UIContextualAction {
dismissOnConfirm: true,
onConfirm: { _ in
Storage.shared.writeAsync { db in
try SessionThread.deleteOrLeave(
db,
threadId: threadViewModel.threadId,
threadVariant: threadViewModel.threadVariant,
groupLeaveType: .standard,
calledFromConfigHandling: false
)
do {
try SessionThread.deleteOrLeave(
db,
threadId: threadViewModel.threadId,
threadVariant: threadViewModel.threadVariant,
groupLeaveType: .standard,
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)

Loading…
Cancel
Save