From bf697c722a441500e93c971cb13c9ef0915fbcf1 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sun, 4 Aug 2024 20:48:54 +0100 Subject: [PATCH] ios: update messages in share extension alert when message sending is slow (#4578) --- apps/ios/Shared/Views/Chat/ChatView.swift | 6 +++--- apps/ios/Shared/Views/Chat/ReverseList.swift | 10 +++++----- apps/ios/SimpleX SE/ShareModel.swift | 12 ++++++------ apps/ios/SimpleX SE/ShareView.swift | 4 ++-- apps/ios/SimpleXChat/ImageUtils.swift | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/apps/ios/Shared/Views/Chat/ChatView.swift b/apps/ios/Shared/Views/Chat/ChatView.swift index aa033203dc..9b770c06fc 100644 --- a/apps/ios/Shared/Views/Chat/ChatView.swift +++ b/apps/ios/Shared/Views/Chat/ChatView.swift @@ -376,7 +376,7 @@ struct ChatView: View { reversedChatItems .enumerated() .filter { (index, chatItem) in - if let mergeCategory = chatItem.mergeCategory, index > .zero { + if let mergeCategory = chatItem.mergeCategory, index > 0 { mergeCategory != reversedChatItems[index - 1].mergeCategory } else { true @@ -456,7 +456,7 @@ struct ChatView: View { init() { unreadChatItemCounts = UnreadChatItemCounts( isNearBottom: true, - unreadBelow: .zero + unreadBelow: 0 ) events .receive(on: DispatchQueue.global(qos: .background)) @@ -1098,7 +1098,7 @@ struct ChatView: View { } func reactions(from: Int? = nil, till: Int? = nil) -> some View { - ForEach(availableReactions[(from ?? .zero)..<(till ?? availableReactions.count)]) { reaction in + ForEach(availableReactions[(from ?? 0)..<(till ?? availableReactions.count)]) { reaction in Button(reaction.text) { setReaction(chatItem, add: true, reaction: reaction) } diff --git a/apps/ios/Shared/Views/Chat/ReverseList.swift b/apps/ios/Shared/Views/Chat/ReverseList.swift index a3f485cb5e..1f504fb5c1 100644 --- a/apps/ios/Shared/Views/Chat/ReverseList.swift +++ b/apps/ios/Shared/Views/Chat/ReverseList.swift @@ -33,7 +33,7 @@ struct ReverseList: UIV case let .item(id): controller.scroll(to: items.firstIndex(where: { $0.id == id }), position: .bottom) case .bottom: - controller.scroll(to: .zero, position: .top) + controller.scroll(to: 0, position: .top) } } else { controller.update(items: items) @@ -45,7 +45,7 @@ struct ReverseList: UIV private enum Section { case main } private let representer: ReverseList private var dataSource: UITableViewDiffableDataSource! - private var itemCount: Int = .zero + private var itemCount: Int = 0 private var bag = Set() init(representer: ReverseList) { @@ -80,7 +80,7 @@ struct ReverseList: UIV let cell = tableView.dequeueReusableCell(withIdentifier: cellReuseId, for: indexPath) if #available(iOS 16.0, *) { cell.contentConfiguration = UIHostingConfiguration { self.representer.content(item) } - .margins(.all, .zero) + .margins(.all, 0) .minSize(height: 1) // Passing zero will result in system default of 44 points being used } else { if let cell = cell as? HostingCell { @@ -153,7 +153,7 @@ struct ReverseList: UIV animated = true } tableView.scrollToRow( - at: IndexPath(row: index, section: .zero), + at: IndexPath(row: index, section: 0), at: position, animated: animated ) @@ -168,7 +168,7 @@ struct ReverseList: UIV dataSource.defaultRowAnimation = .none dataSource.apply( snapshot, - animatingDifferences: itemCount != .zero && abs(items.count - itemCount) == 1 + animatingDifferences: itemCount != 0 && abs(items.count - itemCount) == 1 ) itemCount = items.count } diff --git a/apps/ios/SimpleX SE/ShareModel.swift b/apps/ios/SimpleX SE/ShareModel.swift index 0297aa6557..f591de104f 100644 --- a/apps/ios/SimpleX SE/ShareModel.swift +++ b/apps/ios/SimpleX SE/ShareModel.swift @@ -29,6 +29,7 @@ class ShareModel: ObservableObject { @Published var errorAlert: ErrorAlert? @Published var hasSimplexLink = false @Published var alertRequiresPassword = false + var networkTimeout = CFAbsoluteTimeGetCurrent() enum BottomBar { case sendButton @@ -148,7 +149,7 @@ class ShareModel: ObservableObject { if selected.chatInfo.chatType == .local { completion() } else { - await MainActor.run { self.bottomBar = .loadingBar(progress: .zero) } + await MainActor.run { self.bottomBar = .loadingBar(progress: 0) } if let e = await handleEvents( isGroupChat: ci.chatInfo.chatType == .group, isWithoutFile: sharedContent.cryptoFile == nil, @@ -290,14 +291,13 @@ class ShareModel: ObservableObject { CompletionHandler.isEventLoopEnabled = true let ch = CompletionHandler() if isWithoutFile { await ch.completeFile() } - var networkTimeout = CFAbsoluteTimeGetCurrent() + networkTimeout = CFAbsoluteTimeGetCurrent() while await ch.isRunning { if CFAbsoluteTimeGetCurrent() - networkTimeout > 30 { - networkTimeout = CFAbsoluteTimeGetCurrent() await MainActor.run { - self.errorAlert = ErrorAlert(title: "No network connection") { - Button("Keep Trying", role: .cancel) { } - Button("Dismiss Sheet", role: .destructive) { self.completion() } + self.errorAlert = ErrorAlert(title: "Slow network?", message: "Sending a message takes longer than expected.") { + Button("Wait", role: .cancel) { self.networkTimeout = CFAbsoluteTimeGetCurrent() } + Button("Cancel", role: .destructive) { self.completion() } } } } diff --git a/apps/ios/SimpleX SE/ShareView.swift b/apps/ios/SimpleX SE/ShareView.swift index dcdeae2b82..51a2f1f3a4 100644 --- a/apps/ios/SimpleX SE/ShareView.swift +++ b/apps/ios/SimpleX SE/ShareView.swift @@ -85,7 +85,7 @@ struct ShareView: View { } private func compose(isLoading: Bool) -> some View { - VStack(spacing: .zero) { + VStack(spacing: 0) { Divider() if let content = model.sharedContent { itemPreview(content) @@ -179,7 +179,7 @@ struct ShareView: View { private func loadingBar(progress: Double) -> some View { VStack { - Text("Sending File") + Text("Sending message…") ProgressView(value: progress) } .padding() diff --git a/apps/ios/SimpleXChat/ImageUtils.swift b/apps/ios/SimpleXChat/ImageUtils.swift index 7a62d863e6..ef34c2308e 100644 --- a/apps/ios/SimpleXChat/ImageUtils.swift +++ b/apps/ios/SimpleXChat/ImageUtils.swift @@ -174,7 +174,7 @@ public func downsampleImage(at url: URL, to size: Int64) -> UIImage? { if let source = CGImageSourceCreateWithURL(url as CFURL, nil) { CGImageSourceCreateThumbnailAtIndex( source, - Int.zero, + 0, [ kCGImageSourceCreateThumbnailFromImageAlways: true, kCGImageSourceShouldCacheImmediately: true,