Files

52 lines
2.2 KiB
Swift

// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
import Foundation
public extension Network.PushNotification {
struct UnsubscribeResponse: Codable {
public struct SubResponse: Codable {
/// Flag indicating the success of the registration
public let success: Bool?
/// Value is `true` upon an initial registration
public let added: Bool?
/// Value is `true` upon a renewal/update registration
public let updated: Bool?
/// This will be one of the errors found here:
/// https://github.com/jagerman/session-push-notification-server/blob/spns-v2/spns/hive/subscription.hpp#L21
///
/// Values at the time of writing are:
/// OK = 0 // Great Success!
/// BAD_INPUT = 1 // Unparseable, invalid values, missing required arguments, etc. (details in the string)
/// SERVICE_NOT_AVAILABLE = 2 // The requested service name isn't currently available
/// SERVICE_TIMEOUT = 3 // The backend service did not response
/// ERROR = 4 // There was some other error processing the subscription (details in the string)
/// INTERNAL_ERROR = 5 // An internal program error occured processing the request
public let error: Int?
/// Includes additional information about the error
public let message: String?
}
public let subResponses: [SubResponse]
public init(subResponses: [SubResponse]) {
self.subResponses = subResponses
}
public init(from decoder: Decoder) throws {
guard
let container: SingleValueDecodingContainer = try? decoder.singleValueContainer(),
let subResponses: [SubResponse] = try? container.decode([SubResponse].self)
else {
self.subResponses = [try SubResponse(from: decoder)]
return
}
self.subResponses = subResponses
}
}
}