Skip to content

Exclude deleted sites from getBlogs #833

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

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let package = Package(
targets: [
.binaryTarget(
name: "WordPressKit",
url: "https://github.com/user-attachments/files/19034191/WordPressKit.zip",
checksum: "34f108cba86b5e4334d1c9af79946dbb8b665e270bdd14bc8f7bc0ba7a898583"
url: "https://github.com/user-attachments/files/19315257/WordPressKit.zip",
checksum: "1b4ba5cef01a64e98ffdc02a5c8ac92f550f234222bfb6abf11b4b4df94435bc"
),
]
)
3 changes: 3 additions & 0 deletions Sources/WordPressKit/Models/RemoteBlog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ import Foundation
/// Blog's total disk quota space used.
public var quotaSpaceUsed: NSNumber?

public var isDeleted: Bool

/// Parses details from a JSON dictionary, as returned by the WordPress.com REST API.
@objc(initWithJSONDictionary:)
public init(jsonDictionary json: NSDictionary) {
Expand All @@ -79,6 +81,7 @@ import Foundation
self.planActiveFeatures = (json.array(forKeyPath: "plan.features.active") as? [String]) ?? []
self.quotaSpaceAllowed = json.number(forKeyPath: "quota.space_allowed")
self.quotaSpaceUsed = json.number(forKeyPath: "quota.space_used")
self.isDeleted = json.number(forKey: "is_deleted")?.boolValue == true
}

}
8 changes: 6 additions & 2 deletions Sources/WordPressKit/Services/AccountServiceRemoteREST.m
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,14 @@ - (RemoteUser *)remoteUserFromDictionary:(NSDictionary *)dictionary
- (NSArray *)remoteBlogsFromJSONArray:(NSArray *)jsonBlogs
{
NSArray *blogs = jsonBlogs;
return [blogs wpkit_map:^id(NSDictionary *jsonBlog) {
return [[blogs wpkit_map:^id(NSDictionary *jsonBlog) {
return [[RemoteBlog alloc] initWithJSONDictionary:jsonBlog];
}] wpkit_filter:^BOOL(RemoteBlog *blog) {
// Exclude deleted sites from query result, since the app does not handle deleted sites properly.
// I tried to use query arguments `site_visibility=visible` and `site_activity=active`, but neither excludes
// deleted sites.
return !blog.isDeleted;
}];
return blogs;
}

@end