Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
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
2 changes: 1 addition & 1 deletion WordPressKit.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "WordPressKit"
s.version = "4.25.0-beta.1"
s.version = "4.25.0-beta.2"
s.summary = "WordPressKit offers a clean and simple WordPress.com and WordPress.org API."

s.description = <<-DESC
Expand Down
49 changes: 49 additions & 0 deletions WordPressKit/ReaderPostServiceRemote+V2.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,53 @@ extension ReaderPostServiceRemote {

return self.path(forEndpoint: endpoint, withVersion: ._2_0)
}


/// Sets the `is_seen` status for a given post.
///
/// - Parameter seen: the post is to be marked seen or not (unseen)
/// - Parameter feedID: feedID of the ReaderPost
/// - Parameter feedItemID: feedItemID of the ReaderPost
/// - Parameter success: Called when the request succeeds
/// - Parameter failure: Called when the request fails
@objc
public func markPostSeen(seen: Bool,
feedID: NSNumber,
feedItemID: NSNumber,
success: @escaping (() -> Void),
failure: @escaping ((Error) -> Void)) {

let endpoint = seen ? SeenEndpoints.seen : SeenEndpoints.unseen
let path = self.path(forEndpoint: endpoint, withVersion: ._2_0)

let params = [
"feed_id": feedID,
"feed_item_ids": [feedItemID],
"source": "reader-ios"
] as [String: AnyObject]

wordPressComRestApi.POST(path, parameters: params, success: { (responseObject, httpResponse) in
guard let response = responseObject as? [String: AnyObject],
let status = response["status"] as? Bool,
status == true else {
failure(MarkSeenError.failed)
return
}
success()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we should check what's returned in the response object. It should be a dictionary with a single key status. The value of status can be true or false depending on if the call succeeded. Looks like there are a few (unlikely) scenarios where false could be returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. And done!

}, failure: { (error, httpResponse) in
failure(error)
})
}

private enum MarkSeenError: Error {
case failed
}

private struct SeenEndpoints {
// Creates a new `seen` entry (i.e. mark as seen)
static let seen = "seen-posts/seen/new"
// Removes the `seen` entry (i.e. mark as unseen)
static let unseen = "seen-posts/seen/delete"
}

}
1 change: 1 addition & 0 deletions WordPressKit/RemoteReaderPost.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
@property (nonatomic) BOOL isLiked;
@property (nonatomic) BOOL isReblogged;
@property (nonatomic) BOOL isWPCom;
@property (nonatomic) BOOL isSeen;
@property (nonatomic, strong) NSNumber *likeCount;
@property (nonatomic, strong) NSNumber *score;
@property (nonatomic, strong) NSNumber *siteID;
Expand Down
2 changes: 2 additions & 0 deletions WordPressKit/RemoteReaderPost.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
NSString * const PostRESTKeyIsFollowing = @"is_following";
NSString * const PostRESTKeyIsJetpack = @"is_jetpack";
NSString * const PostRESTKeyIsReblogged = @"is_reblogged";
NSString * const PostRESTKeyIsSeen = @"is_seen";
NSString * const PostRESTKeyLikeCount = @"like_count";
NSString * const PostRESTKeyLikesEnabled = @"likes_enabled";
NSString * const PostRESTKeyName = @"name";
Expand Down Expand Up @@ -110,6 +111,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict;
self.isFollowing = [[dict numberForKey:PostRESTKeyIsFollowing] boolValue];
self.isLiked = [[dict numberForKey:PostRESTKeyILike] boolValue];
self.isReblogged = [[dict numberForKey:PostRESTKeyIsReblogged] boolValue];
self.isSeen = [[dict numberForKey:PostRESTKeyIsSeen] boolValue];
self.isWPCom = [self isWPComFromPostDictionary:dict];
self.likeCount = [dict numberForKey:PostRESTKeyLikeCount];
self.permalink = [self stringOrEmptyString:[dict stringForKey:PostRESTKeyURL]];
Expand Down