From d020a7a05f0fe6544de8e8fbe640b4325522a400 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Fri, 10 Feb 2023 17:36:40 +1100 Subject: [PATCH] Fixed a couple of reachability oddities and bugs Updated the PathVC to indicate the network reachability Updated messages sent to 'Note to Self' to properly indicate whether they were sent to the swarm Fixed an issue where 'Note to Self' messages weren't actually getting sent to the swarm --- .../ConversationVC+Interaction.swift | 14 +++- .../Conversations/Input View/InputView.swift | 1 + .../Translations/de.lproj/Localizable.strings | 1 + .../Translations/en.lproj/Localizable.strings | 1 + .../Translations/es.lproj/Localizable.strings | 1 + .../Translations/fa.lproj/Localizable.strings | 1 + .../Translations/fi.lproj/Localizable.strings | 1 + .../Translations/fr.lproj/Localizable.strings | 1 + .../Translations/hi.lproj/Localizable.strings | 1 + .../Translations/hr.lproj/Localizable.strings | 1 + .../id-ID.lproj/Localizable.strings | 1 + .../Translations/it.lproj/Localizable.strings | 1 + .../Translations/ja.lproj/Localizable.strings | 1 + .../Translations/nl.lproj/Localizable.strings | 1 + .../Translations/pl.lproj/Localizable.strings | 1 + .../pt_BR.lproj/Localizable.strings | 1 + .../Translations/ru.lproj/Localizable.strings | 1 + .../Translations/si.lproj/Localizable.strings | 1 + .../Translations/sk.lproj/Localizable.strings | 1 + .../Translations/sv.lproj/Localizable.strings | 1 + .../Translations/th.lproj/Localizable.strings | 1 + .../vi-VN.lproj/Localizable.strings | 1 + .../zh-Hant.lproj/Localizable.strings | 1 + .../zh_CN.lproj/Localizable.strings | 1 + Session/Path/PathStatusView.swift | 1 + Session/Path/PathVC.swift | 76 ++++++++++++++++++- SessionMessagingKit/Messages/Message.swift | 3 + .../MessageReceiver+VisibleMessages.swift | 7 ++ .../Sending & Receiving/MessageSender.swift | 3 +- 29 files changed, 119 insertions(+), 8 deletions(-) diff --git a/Session/Conversations/ConversationVC+Interaction.swift b/Session/Conversations/ConversationVC+Interaction.swift index c6794329a..3b1f3e89c 100644 --- a/Session/Conversations/ConversationVC+Interaction.swift +++ b/Session/Conversations/ConversationVC+Interaction.swift @@ -1826,10 +1826,16 @@ extension ConversationVC: }) actionSheet.addAction(UIAlertAction( - title: (cellViewModel.threadVariant == .closedGroup ? - "delete_message_for_everyone".localized() : - String(format: "delete_message_for_me_and_recipient".localized(), threadName) - ), + title: { + switch cellViewModel.threadVariant { + case .closedGroup: return "delete_message_for_everyone".localized() + default: + return (cellViewModel.threadId == userPublicKey ? + "delete_message_for_me_and_my_devices".localized() : + String(format: "delete_message_for_me_and_recipient".localized(), threadName) + ) + } + }(), style: .destructive ) { [weak self] _ in deleteRemotely( diff --git a/Session/Conversations/Input View/InputView.swift b/Session/Conversations/Input View/InputView.swift index b1b40c892..5ea587eba 100644 --- a/Session/Conversations/Input View/InputView.swift +++ b/Session/Conversations/Input View/InputView.swift @@ -3,6 +3,7 @@ import UIKit import SessionUIKit import SessionMessagingKit +import SessionUtilitiesKit final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, MentionSelectionViewDelegate { // MARK: - Variables diff --git a/Session/Meta/Translations/de.lproj/Localizable.strings b/Session/Meta/Translations/de.lproj/Localizable.strings index f78f8bea5..49bb4222d 100644 --- a/Session/Meta/Translations/de.lproj/Localizable.strings +++ b/Session/Meta/Translations/de.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/en.lproj/Localizable.strings b/Session/Meta/Translations/en.lproj/Localizable.strings index a48be8c05..6035cb094 100644 --- a/Session/Meta/Translations/en.lproj/Localizable.strings +++ b/Session/Meta/Translations/en.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/es.lproj/Localizable.strings b/Session/Meta/Translations/es.lproj/Localizable.strings index b821c73d7..66ac26c54 100644 --- a/Session/Meta/Translations/es.lproj/Localizable.strings +++ b/Session/Meta/Translations/es.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/fa.lproj/Localizable.strings b/Session/Meta/Translations/fa.lproj/Localizable.strings index c3310be12..cd8ce41a3 100644 --- a/Session/Meta/Translations/fa.lproj/Localizable.strings +++ b/Session/Meta/Translations/fa.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/fi.lproj/Localizable.strings b/Session/Meta/Translations/fi.lproj/Localizable.strings index 36eb30b77..a25d2809a 100644 --- a/Session/Meta/Translations/fi.lproj/Localizable.strings +++ b/Session/Meta/Translations/fi.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/fr.lproj/Localizable.strings b/Session/Meta/Translations/fr.lproj/Localizable.strings index 5a3b51d7a..f72ff557f 100644 --- a/Session/Meta/Translations/fr.lproj/Localizable.strings +++ b/Session/Meta/Translations/fr.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/hi.lproj/Localizable.strings b/Session/Meta/Translations/hi.lproj/Localizable.strings index 3d29a1e30..ef84e37b3 100644 --- a/Session/Meta/Translations/hi.lproj/Localizable.strings +++ b/Session/Meta/Translations/hi.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/hr.lproj/Localizable.strings b/Session/Meta/Translations/hr.lproj/Localizable.strings index facd36892..13a38e591 100644 --- a/Session/Meta/Translations/hr.lproj/Localizable.strings +++ b/Session/Meta/Translations/hr.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/id-ID.lproj/Localizable.strings b/Session/Meta/Translations/id-ID.lproj/Localizable.strings index 2ad901a50..23d363a58 100644 --- a/Session/Meta/Translations/id-ID.lproj/Localizable.strings +++ b/Session/Meta/Translations/id-ID.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/it.lproj/Localizable.strings b/Session/Meta/Translations/it.lproj/Localizable.strings index 28e2d7ba4..6c0cf9c3b 100644 --- a/Session/Meta/Translations/it.lproj/Localizable.strings +++ b/Session/Meta/Translations/it.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/ja.lproj/Localizable.strings b/Session/Meta/Translations/ja.lproj/Localizable.strings index 76c151cd7..64b5f7da4 100644 --- a/Session/Meta/Translations/ja.lproj/Localizable.strings +++ b/Session/Meta/Translations/ja.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/nl.lproj/Localizable.strings b/Session/Meta/Translations/nl.lproj/Localizable.strings index 7889ee1b9..ad817674a 100644 --- a/Session/Meta/Translations/nl.lproj/Localizable.strings +++ b/Session/Meta/Translations/nl.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/pl.lproj/Localizable.strings b/Session/Meta/Translations/pl.lproj/Localizable.strings index 29f3a0fa1..afc0cd8a5 100644 --- a/Session/Meta/Translations/pl.lproj/Localizable.strings +++ b/Session/Meta/Translations/pl.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings index f833144bf..c289ab6d2 100644 --- a/Session/Meta/Translations/pt_BR.lproj/Localizable.strings +++ b/Session/Meta/Translations/pt_BR.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/ru.lproj/Localizable.strings b/Session/Meta/Translations/ru.lproj/Localizable.strings index a268d3598..fc3fb38c9 100644 --- a/Session/Meta/Translations/ru.lproj/Localizable.strings +++ b/Session/Meta/Translations/ru.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/si.lproj/Localizable.strings b/Session/Meta/Translations/si.lproj/Localizable.strings index 42673e0d0..39fd64261 100644 --- a/Session/Meta/Translations/si.lproj/Localizable.strings +++ b/Session/Meta/Translations/si.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/sk.lproj/Localizable.strings b/Session/Meta/Translations/sk.lproj/Localizable.strings index 5815b0cb6..56ac501a1 100644 --- a/Session/Meta/Translations/sk.lproj/Localizable.strings +++ b/Session/Meta/Translations/sk.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/sv.lproj/Localizable.strings b/Session/Meta/Translations/sv.lproj/Localizable.strings index eebfc3140..d2ac71190 100644 --- a/Session/Meta/Translations/sv.lproj/Localizable.strings +++ b/Session/Meta/Translations/sv.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/th.lproj/Localizable.strings b/Session/Meta/Translations/th.lproj/Localizable.strings index 6921bf21e..ca9af2694 100644 --- a/Session/Meta/Translations/th.lproj/Localizable.strings +++ b/Session/Meta/Translations/th.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings index 410798536..7b4ee536d 100644 --- a/Session/Meta/Translations/vi-VN.lproj/Localizable.strings +++ b/Session/Meta/Translations/vi-VN.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings index 381e074e1..9dae80736 100644 --- a/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh-Hant.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings index 862b7d3d0..90d6d85f6 100644 --- a/Session/Meta/Translations/zh_CN.lproj/Localizable.strings +++ b/Session/Meta/Translations/zh_CN.lproj/Localizable.strings @@ -600,3 +600,4 @@ "MESSAGE_DELIVERY_STATUS_SENT" = "Sent"; "MESSAGE_DELIVERY_STATUS_READ" = "Read"; "MESSAGE_DELIVERY_STATUS_FAILED" = "Failed to send"; +"delete_message_for_me_and_my_devices" = "Delete from all of my devices"; diff --git a/Session/Path/PathStatusView.swift b/Session/Path/PathStatusView.swift index 0f8326a1e..c606b3268 100644 --- a/Session/Path/PathStatusView.swift +++ b/Session/Path/PathStatusView.swift @@ -3,6 +3,7 @@ import UIKit import Reachability import SessionUIKit +import SessionSnodeKit final class PathStatusView: UIView { enum Size { diff --git a/Session/Path/PathVC.swift b/Session/Path/PathVC.swift index da1dd5875..1b641f43f 100644 --- a/Session/Path/PathVC.swift +++ b/Session/Path/PathVC.swift @@ -1,9 +1,11 @@ // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved. import UIKit +import Reachability import NVActivityIndicatorView import SessionMessagingKit import SessionUIKit +import SessionSnodeKit final class PathVC: BaseVC { public static let dotSize: CGFloat = 8 @@ -239,6 +241,7 @@ private final class LineView: UIView { private var dotViewWidthConstraint: NSLayoutConstraint! private var dotViewHeightConstraint: NSLayoutConstraint! private var dotViewAnimationTimer: Timer! + private let reachability: Reachability = Reachability.forInternetConnection() enum Location { case top, middle, bottom @@ -273,6 +276,7 @@ private final class LineView: UIView { super.init(frame: CGRect.zero) setUpViewHierarchy() + registerObservers() } override init(frame: CGRect) { @@ -283,6 +287,12 @@ private final class LineView: UIView { preconditionFailure("Use init(location:dotAnimationStartDelay:dotAnimationRepeatInterval:) instead.") } + deinit { + NotificationCenter.default.removeObserver(self) + + dotViewAnimationTimer?.invalidate() + } + private func setUpViewHierarchy() { let lineView = UIView() lineView.set(.width, to: Values.separatorThickness) @@ -315,10 +325,33 @@ private final class LineView: UIView { self?.animate() } } + + switch (reachability.isReachable(), OnionRequestAPI.paths.isEmpty) { + case (false, _): setStatus(to: .error) + case (true, true): setStatus(to: .connecting) + case (true, false): setStatus(to: .connected) + } } - - deinit { - dotViewAnimationTimer?.invalidate() + + private func registerObservers() { + NotificationCenter.default.addObserver( + self, + selector: #selector(handleBuildingPathsNotification), + name: .buildingPaths, + object: nil + ) + NotificationCenter.default.addObserver( + self, + selector: #selector(handlePathsBuiltNotification), + name: .pathsBuilt, + object: nil + ) + NotificationCenter.default.addObserver( + self, + selector: #selector(reachabilityChanged), + name: .reachabilityChanged, + object: nil + ) } private func animate() { @@ -340,4 +373,41 @@ private final class LineView: UIView { self?.dotView.transform = CGAffineTransform.scale(1) } } + + private func setStatus(to status: PathStatusView.Status) { + dotView.themeBackgroundColor = status.themeColor + dotView.layer.themeShadowColor = status.themeColor + } + + @objc private func handleBuildingPathsNotification() { + guard reachability.isReachable() else { + setStatus(to: .error) + return + } + + setStatus(to: .connecting) + } + + @objc private func handlePathsBuiltNotification() { + guard reachability.isReachable() else { + setStatus(to: .error) + return + } + + setStatus(to: .connected) + } + + @objc private func reachabilityChanged() { + guard Thread.isMainThread else { + DispatchQueue.main.async { [weak self] in self?.reachabilityChanged() } + return + } + + guard reachability.isReachable() else { + setStatus(to: .error) + return + } + + setStatus(to: (!OnionRequestAPI.paths.isEmpty ? .connected : .connecting)) + } } diff --git a/SessionMessagingKit/Messages/Message.swift b/SessionMessagingKit/Messages/Message.swift index 1f239920c..6719ac4ae 100644 --- a/SessionMessagingKit/Messages/Message.swift +++ b/SessionMessagingKit/Messages/Message.swift @@ -177,6 +177,9 @@ public extension Message { } static func shouldSync(message: Message) -> Bool { + // For 'Note to Self' messages we always want to sync the message + guard message.sender != message.recipient else { return true } + switch message { case let controlMessage as ClosedGroupControlMessage: switch controlMessage.kind { diff --git a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift index 73006ac67..2cfb8f433 100644 --- a/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift +++ b/SessionMessagingKit/Sending & Receiving/Message Handling/MessageReceiver+VisibleMessages.swift @@ -139,6 +139,13 @@ extension MessageReceiver { return recipientParts[2] }() ).inserted(db) + + // If the message was an outgoing message then immediately update the recipient state to 'sent' + if variant == .standardOutgoing, let interactionId: Int64 = interaction.id { + _ = try? RecipientState + .filter(RecipientState.Columns.interactionId == interactionId) + .updateAll(db, RecipientState.Columns.state.set(to: RecipientState.State.sent)) + } } catch { switch error { diff --git a/SessionMessagingKit/Sending & Receiving/MessageSender.swift b/SessionMessagingKit/Sending & Receiving/MessageSender.swift index 5cf680554..ed2aceaac 100644 --- a/SessionMessagingKit/Sending & Receiving/MessageSender.swift +++ b/SessionMessagingKit/Sending & Receiving/MessageSender.swift @@ -647,8 +647,9 @@ public final class MessageSender { // • it's a visible message or an expiration timer update // • the destination was a contact // • we didn't sync it already + // • it wasn't set to 'Note to Self' let userPublicKey = getUserHexEncodedPublicKey(db) - if case .contact(let publicKey) = destination, !isSyncMessage { + if case .contact(let publicKey) = destination, !isSyncMessage, publicKey != userPublicKey { if let message = message as? VisibleMessage { message.syncTarget = publicKey } if let message = message as? ExpirationTimerUpdate { message.syncTarget = publicKey }