From afa93d3320ffb0862e3ac6aff602684cf4f81cf0 Mon Sep 17 00:00:00 2001 From: Morgan Pretty Date: Tue, 11 Jun 2024 18:05:17 +1000 Subject: [PATCH] Updated with latest libSession fixes, minor logging tweaks --- LibSession-Util | 2 +- Session.xcodeproj/project.pbxproj | 4 +-- .../Jobs/Types/FailedMessageSendsJob.swift | 36 +++++++++++-------- .../Pollers/CurrentUserPoller.swift | 2 +- .../LibSession/LibSession+Networking.swift | 6 +++- .../General/String+Utilities.swift | 8 +++-- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/LibSession-Util b/LibSession-Util index 702302626..714230c0c 160000 --- a/LibSession-Util +++ b/LibSession-Util @@ -1 +1 @@ -Subproject commit 702302626d401d6954e67b60b28805c785be7a7c +Subproject commit 714230c0c8867ac8662603fd6debb5b4c4369ef1 diff --git a/Session.xcodeproj/project.pbxproj b/Session.xcodeproj/project.pbxproj index 67b4be770..8536b6560 100644 --- a/Session.xcodeproj/project.pbxproj +++ b/Session.xcodeproj/project.pbxproj @@ -8034,7 +8034,7 @@ CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Developer"; - CURRENT_PROJECT_VERSION = 448; + CURRENT_PROJECT_VERSION = 449; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -8112,7 +8112,7 @@ CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = "iPhone Distribution"; - CURRENT_PROJECT_VERSION = 448; + CURRENT_PROJECT_VERSION = 449; ENABLE_BITCODE = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_NO_COMMON_BLOCKS = YES; diff --git a/SessionMessagingKit/Jobs/Types/FailedMessageSendsJob.swift b/SessionMessagingKit/Jobs/Types/FailedMessageSendsJob.swift index e458de633..a1d3490f0 100644 --- a/SessionMessagingKit/Jobs/Types/FailedMessageSendsJob.swift +++ b/SessionMessagingKit/Jobs/Types/FailedMessageSendsJob.swift @@ -21,20 +21,26 @@ public enum FailedMessageSendsJob: JobExecutor { var attachmentChangeCount: Int = -1 // Update all 'sending' message states to 'failed' - dependencies.storage.write { db in - let sendChangeCount: Int = try RecipientState - .filter(RecipientState.Columns.state == RecipientState.State.sending) - .updateAll(db, RecipientState.Columns.state.set(to: RecipientState.State.failed)) - let syncChangeCount: Int = try RecipientState - .filter(RecipientState.Columns.state == RecipientState.State.syncing) - .updateAll(db, RecipientState.Columns.state.set(to: RecipientState.State.failedToSync)) - attachmentChangeCount = try Attachment - .filter(Attachment.Columns.state == Attachment.State.uploading) - .updateAll(db, Attachment.Columns.state.set(to: Attachment.State.failedUpload)) - changeCount = (sendChangeCount + syncChangeCount) - } - - SNLog("[FailedMessageSendsJob] Marked \(changeCount) message\(changeCount == 1 ? "" : "s") as failed (\(attachmentChangeCount) upload\(attachmentChangeCount == 1 ? "" : "s") cancelled)") - success(job, false, dependencies) + dependencies.storage + .writePublisher(using: dependencies) { db in + let sendChangeCount: Int = try RecipientState + .filter(RecipientState.Columns.state == RecipientState.State.sending) + .updateAll(db, RecipientState.Columns.state.set(to: RecipientState.State.failed)) + let syncChangeCount: Int = try RecipientState + .filter(RecipientState.Columns.state == RecipientState.State.syncing) + .updateAll(db, RecipientState.Columns.state.set(to: RecipientState.State.failedToSync)) + attachmentChangeCount = try Attachment + .filter(Attachment.Columns.state == Attachment.State.uploading) + .updateAll(db, Attachment.Columns.state.set(to: Attachment.State.failedUpload)) + changeCount = (sendChangeCount + syncChangeCount) + } + .subscribe(on: queue, using: dependencies) + .receive(on: queue, using: dependencies) + .sinkUntilComplete( + receiveCompletion: { _ in + SNLog("[FailedMessageSendsJob] Marked \(changeCount) message\(changeCount == 1 ? "" : "s") as failed (\(attachmentChangeCount) upload\(attachmentChangeCount == 1 ? "" : "s") cancelled)") + success(job, false, dependencies) + } + ) } } diff --git a/SessionMessagingKit/Sending & Receiving/Pollers/CurrentUserPoller.swift b/SessionMessagingKit/Sending & Receiving/Pollers/CurrentUserPoller.swift index 7991ad0b6..827d29d2f 100644 --- a/SessionMessagingKit/Sending & Receiving/Pollers/CurrentUserPoller.swift +++ b/SessionMessagingKit/Sending & Receiving/Pollers/CurrentUserPoller.swift @@ -71,7 +71,7 @@ public final class CurrentUserPoller: Poller { let drainBehaviour: Atomic = drainBehaviour.wrappedValue[publicKey], case .limitedReuse(_, .some(let targetSnode), _, _, _) = drainBehaviour.wrappedValue { - SNLog("Main Poller polling \(targetSnode) failed with error: \(error); switching to next snode.") + SNLog("Main Poller polling \(targetSnode) failed with error: \(period: "\(error)"); switching to next snode.") drainBehaviour.mutate { $0 = $0.clearTargetSnode() } } else { diff --git a/SessionSnodeKit/LibSession/LibSession+Networking.swift b/SessionSnodeKit/LibSession/LibSession+Networking.swift index f14be2849..d755536c5 100644 --- a/SessionSnodeKit/LibSession/LibSession+Networking.swift +++ b/SessionSnodeKit/LibSession/LibSession+Networking.swift @@ -136,12 +136,16 @@ public extension LibSession { guard let network: UnsafeMutablePointer = networkCache.wrappedValue else { return } - network_close_connections(network) + network_suspend(network) } static func resumeNetworkAccess() { isSuspended.mutate { $0 = false } Log.info("[LibSession] resumeNetworkAccess called.") + + guard let network: UnsafeMutablePointer = networkCache.wrappedValue else { return } + + network_resume(network) } static func clearSnodeCache() { diff --git a/SessionUtilitiesKit/General/String+Utilities.swift b/SessionUtilitiesKit/General/String+Utilities.swift index 86017c571..92c7dc74f 100644 --- a/SessionUtilitiesKit/General/String+Utilities.swift +++ b/SessionUtilitiesKit/General/String+Utilities.swift @@ -79,11 +79,15 @@ public extension String { public extension String.StringInterpolation { mutating func appendInterpolation(plural value: Int) { - appendInterpolation(value == 1 ? "" : "s") + appendInterpolation(value == 1 ? "" : "s") // stringlint:disable + } + + public mutating func appendInterpolation(period value: String) { + appendInterpolation(value.hasSuffix(".") ? "" : ".") // stringlint:disable } mutating func appendInterpolation(_ value: TimeUnit, unit: TimeUnit.Unit, resolution: Int = 2) { - appendLiteral("\(TimeUnit(value, unit: unit, resolution: resolution))") + appendLiteral("\(TimeUnit(value, unit: unit, resolution: resolution))") // stringlint:disable } mutating func appendInterpolation(_ value: Int, format: String) {