From 8ced6ec0a86dc4bc160ed3c8632b4b69ae8f6657 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Mon, 15 Aug 2022 16:09:25 +0100
Subject: [PATCH] Don't pop chat screen if reporting fails

---
 Sources/ChatFeature/Controllers/SingleChatController.swift | 3 ++-
 Sources/ChatFeature/ViewModels/SingleChatViewModel.swift   | 6 +++---
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/Sources/ChatFeature/Controllers/SingleChatController.swift b/Sources/ChatFeature/Controllers/SingleChatController.swift
index f4206db0..3b8c60b9 100644
--- a/Sources/ChatFeature/Controllers/SingleChatController.swift
+++ b/Sources/ChatFeature/Controllers/SingleChatController.swift
@@ -433,7 +433,8 @@ public final class SingleChatController: UIViewController {
                     guard let self = self else { return }
                     self.drawerCancellables.removeAll()
                     let screenshot = try! self.makeAppScreenshot()
-                    self.viewModel.report(screenshot: screenshot) {
+                    self.viewModel.report(screenshot: screenshot) { success in
+                        guard success else { return }
                         self.navigationController?.popViewController(animated: true)
                     }
                 }
diff --git a/Sources/ChatFeature/ViewModels/SingleChatViewModel.swift b/Sources/ChatFeature/ViewModels/SingleChatViewModel.swift
index e4dae1d4..8ba933ad 100644
--- a/Sources/ChatFeature/ViewModels/SingleChatViewModel.swift
+++ b/Sources/ChatFeature/ViewModels/SingleChatViewModel.swift
@@ -255,7 +255,7 @@ final class SingleChatViewModel: NSObject {
         sectionsRelay.value.count > 0 ? sectionsRelay.value[index].model : nil
     }
 
-    func report(screenshot: UIImage, completion: @escaping () -> Void) {
+    func report(screenshot: UIImage, completion: @escaping (Bool) -> Void) {
         let report = Report(
             sender: .init(
                 userId: contact.id.base64EncodedString(),
@@ -275,7 +275,7 @@ final class SingleChatViewModel: NSObject {
             case .failure(let error):
                 DispatchQueue.main.async {
                     self.hudRelay.send(.error(.init(with: error)))
-                    completion()
+                    completion(false)
                 }
 
             case .success(_):
@@ -283,7 +283,7 @@ final class SingleChatViewModel: NSObject {
                 DispatchQueue.main.async {
                     self.hudRelay.send(.none)
                     self.presentReportConfirmation()
-                    completion()
+                    completion(true)
                 }
             }
         }
-- 
GitLab