Skip to content

Commit

Permalink
Make config datamodel equatable and rename FCMApnsAlertOrString helpe…
Browse files Browse the repository at this point in the history
…rs (#15)

* Make all payloads data model as struct and Equatable
* Rename FCMApnsAlertOrString helpers with better names
* Fix indentation
  • Loading branch information
FredericRuaudel authored and MihaelIsaev committed Nov 29, 2019
1 parent bf42d59 commit def50eb
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Sources/FCM/FCMAndroidConfig/FCMAndroidConfig.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct FCMAndroidConfig: Codable {
public struct FCMAndroidConfig: Codable, Equatable {
/// An identifier of a group of messages that can be collapsed, so that only the last message gets sent when delivery can be resumed.
/// A maximum of 4 different collapse keys is allowed at any given time.
public var collapse_key: String?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public enum FCMAndroidMessagePriority: String, Codable {
public enum FCMAndroidMessagePriority: String, Codable, Equatable {
/// Default priority for data messages.
/// Normal priority messages won't open network connections on a sleeping device,
/// and their delivery may be delayed to conserve the battery.
Expand Down
2 changes: 1 addition & 1 deletion Sources/FCM/FCMAndroidConfig/FCMAndroidNotification.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct FCMAndroidNotification: Codable {
public struct FCMAndroidNotification: Codable, Equatable {
/// The notification's title.
/// If present, it will override FCMNotification.title.
public var title: String?
Expand Down
2 changes: 1 addition & 1 deletion Sources/FCM/FCMApnsConfig/FCMApnsAlert.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
public struct FCMApnsAlert: Codable {
public struct FCMApnsAlert: Codable, Equatable {
/// The title of the notification.
/// Apple Watch displays this string in the short look notification interface.
/// Specify a string that is quickly understood by the user.
Expand Down
6 changes: 3 additions & 3 deletions Sources/FCM/FCMApnsConfig/FCMApnsAlertOrString.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/// Internal helper for different alert payload types
public enum FCMApnsAlertOrString: Codable {
public enum FCMApnsAlertOrString: Codable, Equatable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
if let string = try? container.decode(String.self) {
Expand Down Expand Up @@ -30,14 +30,14 @@ public enum FCMApnsAlertOrString: Codable {
return .string(v)
}

public var alertPayload: FCMApnsAlert? {
public var asPayload: FCMApnsAlert? {
if case let .alert(payload) = self {
return payload
}
return nil
}

public var alertMessage: String? {
public var asMessage: String? {
if case let .string(message) = self {
return message
}
Expand Down
30 changes: 15 additions & 15 deletions Sources/FCM/FCMApnsConfig/FCMApnsApsObject.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// The following struct is based on
// https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification
public class FCMApnsApsObject: Codable {
public struct FCMApnsApsObject: Codable, Equatable {
/// The information for displaying an alert.
/// A dictionary is recommended.
/// If you specify a string, the alert displays your string as the body text.
Expand Down Expand Up @@ -79,13 +79,13 @@ public class FCMApnsApsObject: Codable {
return FCMApnsApsObject(alertString: nil, sound: "default")
}

public convenience init(alertString: String?,
badge: Int? = nil,
sound: String?,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
public init(alertString: String?,
badge: Int? = nil,
sound: String?,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
self.init(config: Config(alert: FCMApnsAlertOrString.fromRaw(alertString),
badge: badge,
sound: sound,
Expand All @@ -95,13 +95,13 @@ public class FCMApnsApsObject: Codable {
mutableContent: mutableContent))
}

public convenience init(alert: FCMApnsAlert? = nil,
badge: Int? = nil,
sound: String?,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
public init(alert: FCMApnsAlert? = nil,
badge: Int? = nil,
sound: String?,
contentAvailable: Bool? = nil,
category: String? = nil,
threadId: String? = nil,
mutableContent: Bool? = nil) {
self.init(config: Config(alert: FCMApnsAlertOrString.fromRaw(alert),
badge: badge,
sound: sound,
Expand Down
4 changes: 2 additions & 2 deletions Sources/FCM/FCMApnsConfig/FCMApnsPayload.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// Default APNS payload class
/// Default APNS payload model
/// it contains aps dictionary inside
/// you can use your own custom payload class
/// it just should conform to FCMApnsPayloadProtocol
public class FCMApnsPayload: FCMApnsPayloadProtocol {
public struct FCMApnsPayload: FCMApnsPayloadProtocol, Equatable {
/// The APS object, primary alert
public var aps: FCMApnsApsObject

Expand Down
6 changes: 3 additions & 3 deletions Sources/FCM/FCMApnsConfig/FCMApnsPayloadProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// Use it for your custom payload class
/// Use it for your custom payload model
///
/// Example code:
/// class MyCustomPayload: FCMApnsPayloadProtocol {
/// struct MyCustomPayload: FCMApnsPayloadProtocol {
/// var aps: FCMApnsApsObject
/// var myCustomKey: String
///
Expand All @@ -10,6 +10,6 @@
/// self.myCustomKey = myCustomKey
/// }
/// }
public protocol FCMApnsPayloadProtocol: Codable {
public protocol FCMApnsPayloadProtocol: Codable, Equatable {
var aps: FCMApnsApsObject { get set }
}

0 comments on commit def50eb

Please sign in to comment.