mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.4 KiB
Swift
48 lines
1.4 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import PromiseKit
|
|
import SessionSnodeKit
|
|
import SessionUtilitiesKit
|
|
|
|
public enum NotifyPushServerJob: JobExecutor {
|
|
public static var maxFailureCount: Int = 20
|
|
public static var 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) -> ()
|
|
) {
|
|
guard
|
|
let detailsData: Data = job.details,
|
|
let details: Details = try? JSONDecoder().decode(Details.self, from: detailsData)
|
|
else {
|
|
failure(job, JobRunnerError.missingRequiredDetails, false)
|
|
return
|
|
}
|
|
|
|
PushNotificationAPI
|
|
.notify(
|
|
recipient: details.message.recipient,
|
|
with: details.message.data,
|
|
maxRetryCount: 4,
|
|
queue: queue
|
|
)
|
|
.done(on: queue) { _ in success(job, false) }
|
|
.catch(on: queue) { error in failure(job, error, false) }
|
|
.retainUntilComplete()
|
|
}
|
|
}
|
|
|
|
// MARK: - NotifyPushServerJob.Details
|
|
|
|
extension NotifyPushServerJob {
|
|
public struct Details: Codable {
|
|
public let message: SnodeMessage
|
|
}
|
|
}
|