-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for skipping sending usage pixels for remote messages #902
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,10 +31,24 @@ public enum RemoteMessageResponse { | |
let content: JsonContent | ||
let translations: [String: JsonContentTranslation]? | ||
let matchingRules, exclusionRules: [Int]? | ||
let metrics: JsonMetrics? | ||
|
||
static func == (lhs: JsonRemoteMessage, rhs: JsonRemoteMessage) -> Bool { | ||
return lhs.id == rhs.id | ||
} | ||
|
||
var isMetricsEnabled: Bool { | ||
metrics?.state.flatMap(JsonMetrics.MetricsState.init) != .disabled | ||
} | ||
} | ||
|
||
struct JsonMetrics: Decodable { | ||
let state: String? | ||
|
||
enum MetricsState: String, Decodable { | ||
case disabled | ||
case enabled | ||
} | ||
Comment on lines
+39
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the actual change – parse |
||
} | ||
|
||
struct JsonContent: Decodable { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,28 +24,31 @@ public struct RemoteMessageModel: Equatable, Codable { | |
public var content: RemoteMessageModelType? | ||
public let matchingRules: [Int] | ||
public let exclusionRules: [Int] | ||
public let isMetricsEnabled: Bool | ||
|
||
public init(id: String, content: RemoteMessageModelType?, matchingRules: [Int], exclusionRules: [Int]) { | ||
public init(id: String, content: RemoteMessageModelType?, matchingRules: [Int], exclusionRules: [Int], isMetricsEnabled: Bool) { | ||
self.id = id | ||
self.content = content | ||
self.matchingRules = matchingRules | ||
self.exclusionRules = exclusionRules | ||
self.isMetricsEnabled = isMetricsEnabled | ||
} | ||
|
||
public static func == (lhs: RemoteMessageModel, rhs: RemoteMessageModel) -> Bool { | ||
if lhs.id != rhs.id { | ||
return false | ||
} | ||
if lhs.content != rhs.content { | ||
return false | ||
} | ||
if lhs.matchingRules != rhs.matchingRules { | ||
return false | ||
} | ||
if lhs.exclusionRules != rhs.exclusionRules { | ||
return false | ||
} | ||
return true | ||
enum CodingKeys: CodingKey { | ||
case id | ||
case content | ||
case matchingRules | ||
case exclusionRules | ||
case isMetricsEnabled | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
self.id = try container.decode(String.self, forKey: .id) | ||
self.content = try container.decodeIfPresent(RemoteMessageModelType.self, forKey: .content) | ||
self.matchingRules = try container.decode([Int].self, forKey: .matchingRules) | ||
self.exclusionRules = try container.decode([Int].self, forKey: .exclusionRules) | ||
self.isMetricsEnabled = try container.decodeIfPresent(Bool.self, forKey: .isMetricsEnabled) ?? true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
} | ||
|
||
mutating func localizeContent(translation: RemoteMessageResponse.JsonContentTranslation) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file contains all supported cases for metrics object, including no metrics object at all. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"version": 1, | ||
"messages": [ | ||
{ | ||
"id": "1", | ||
"content": { | ||
"messageType": "small", | ||
"titleText": "title", | ||
"descriptionText": "description" | ||
} | ||
}, | ||
{ | ||
"id": "2", | ||
"content": { | ||
"messageType": "small", | ||
"titleText": "title", | ||
"descriptionText": "description" | ||
}, | ||
"metrics": { | ||
"state": "enabled" | ||
} | ||
}, | ||
{ | ||
"id": "3", | ||
"content": { | ||
"messageType": "small", | ||
"titleText": "title", | ||
"descriptionText": "description" | ||
}, | ||
"metrics": { | ||
"state": "disabled" | ||
} | ||
}, | ||
{ | ||
"id": "4", | ||
"content": { | ||
"messageType": "small", | ||
"titleText": "title", | ||
"descriptionText": "description" | ||
}, | ||
"metrics": { | ||
"state": "unsupported-value" | ||
} | ||
} | ||
], | ||
"rules": [] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this part of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My Xcode keeps bugging me about adding this. It's an update to the otherwise auto-generated scheme, so I reckon it doesn't hurt to include it.