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
pull/784/head
Morgan Pretty 2 years ago
parent 9a25688146
commit d020a7a05f

@ -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(

@ -3,6 +3,7 @@
import UIKit
import SessionUIKit
import SessionMessagingKit
import SessionUtilitiesKit
final class InputView: UIView, InputViewButtonDelegate, InputTextViewDelegate, MentionSelectionViewDelegate {
// MARK: - Variables

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -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";

@ -3,6 +3,7 @@
import UIKit
import Reachability
import SessionUIKit
import SessionSnodeKit
final class PathStatusView: UIView {
enum Size {

@ -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))
}
}

@ -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 {

@ -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 {

@ -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 }

Loading…
Cancel
Save