session-ios/SessionMessagingKit/Jobs/Types/FailedMessageSendsJob.swift
Morgan Pretty 3344e58716 Cleaned up some logic around sync messages
Added logic to indicate when a sync message failed to send (and the ability to retry)
Added the retry/resync button to the long press message menu
Updated sync messages to run via the MessageSendJob
Updated the delivery status to always show on the last outgoing message
Updated the logic to update the delivery status when retrying to send a failed message
Removed the convoluted recursion logic for turning self-send messages into sync messages
2023-02-14 13:41:24 +11:00

39 lines
1.7 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SignalCoreKit
import SessionUtilitiesKit
public enum FailedMessageSendsJob: JobExecutor {
public static let maxFailureCount: Int = -1
public static let requiresThreadId: Bool = false
public static let requiresInteractionId: Bool = false
public static func run(
_ job: Job,
queue: DispatchQueue,
success: @escaping (Job, Bool) -> (),
failure: @escaping (Job, Error?, Bool) -> (),
deferred: @escaping (Job) -> ()
) {
// Update all 'sending' message states to 'failed'
Storage.shared.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))
let attachmentChangeCount: Int = try Attachment
.filter(Attachment.Columns.state == Attachment.State.uploading)
.updateAll(db, Attachment.Columns.state.set(to: Attachment.State.failedUpload))
let changeCount: Int = (sendChangeCount + syncChangeCount)
SNLog("Marked \(changeCount) message\(changeCount == 1 ? "" : "s") as failed (\(attachmentChangeCount) upload\(attachmentChangeCount == 1 ? "" : "s") cancelled)")
}
success(job, false)
}
}