-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integerate notification settings endpoint to disable notifications fo…
…r hidden stores (#14730)
- Loading branch information
Showing
10 changed files
with
345 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
|
||
/// Notification settings for a user | ||
/// | ||
public struct NotificationSettings: Equatable, Encodable { | ||
|
||
/// Settings for different blogs connected to the user. | ||
public let blogs: [Blog] | ||
|
||
/// Convenience init to create notification settings for a given device ID. | ||
/// | ||
public init(deviceID: Int64, enabledSites: [Int64], disabledSites: [Int64]) { | ||
let enabledSiteSettings = enabledSites.map { siteID in | ||
Blog(blogID: siteID, devices: [ | ||
Device(deviceID: deviceID, | ||
newComment: true, | ||
storeOrder: true) | ||
]) | ||
} | ||
|
||
let disabledSiteSettings = disabledSites.map { siteID in | ||
Blog(blogID: siteID, devices: [ | ||
Device(deviceID: deviceID, | ||
newComment: false, | ||
storeOrder: false) | ||
]) | ||
} | ||
|
||
self.init(blogs: (enabledSiteSettings + disabledSiteSettings)) | ||
} | ||
|
||
public init(blogs: [Blog]) { | ||
self.blogs = blogs | ||
} | ||
} | ||
|
||
public extension NotificationSettings { | ||
/// Notification settings for a blog | ||
struct Blog: Equatable, Encodable { | ||
/// ID of the blog | ||
public let blogID: Int64 | ||
|
||
/// List of settings for registered devices | ||
public let devices: [Device] | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case blogID = "blog_id" | ||
case devices | ||
} | ||
} | ||
|
||
/// Notification settings for a device | ||
struct Device: Equatable, Encodable { | ||
/// Unique ID of the device | ||
public let deviceID: Int64 | ||
|
||
/// Whether a notification should be sent when there is a new comment on the blog | ||
public let newComment: Bool | ||
|
||
/// Whether a notification should be sent when there is a new order on the store. | ||
public let storeOrder: Bool | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case deviceID = "device_id" | ||
case newComment = "new_comment" | ||
case storeOrder = "store_order" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
Networking/NetworkingTests/Responses/notification-settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
{ | ||
"blogs": [ | ||
{ | ||
"blog_id": 190864441, | ||
"timeline": { | ||
"new_comment": true, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
}, | ||
"email": { | ||
"new_comment": true, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
}, | ||
"devices": [ | ||
{ | ||
"device_id": 58089781, | ||
"new_comment": true, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
} | ||
] | ||
}, | ||
{ | ||
"blog_id": 194373765, | ||
"timeline": { | ||
"new_comment": true, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
}, | ||
"email": { | ||
"new_comment": true, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
}, | ||
"devices": [ | ||
{ | ||
"device_id": 58089781, | ||
"new_comment": false, | ||
"comment_like": true, | ||
"post_like": true, | ||
"follow": true, | ||
"achievement": true, | ||
"mentions": true, | ||
"scheduled_publicize": true, | ||
"store_order": true, | ||
"blogging_prompt": false, | ||
"draft_post_prompt": true | ||
} | ||
] | ||
}, | ||
] | ||
}, | ||
"wpcom": { | ||
"marketing": false, | ||
"research": true, | ||
"affiliates": true, | ||
"community": true, | ||
"promotion": false, | ||
"news": true, | ||
"digest": true, | ||
"reports": true, | ||
"news_developer": true, | ||
"wpcom_spain": false, | ||
"scheduled_updates": true, | ||
"learn": false, | ||
"a4a_agencies": true, | ||
"jetpack_agencies": true, | ||
"jetpack_manage_onboarding": true, | ||
"jetpack_marketing": false, | ||
"jetpack_research": true, | ||
"jetpack_promotion": false, | ||
"jetpack_news": true, | ||
"jetpack_reports": true, | ||
"akismet_marketing": false, | ||
"woopay_marketing": true, | ||
"gravatar_onboarding": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.