From d46b5be685c9921e235d3135d03a7f51fb5fb4c1 Mon Sep 17 00:00:00 2001 From: kean Date: Thu, 20 Feb 2025 10:47:49 -0500 Subject: [PATCH 1/5] Add RemoteComment as a reponse object in CommentServiceRemote --- Package.swift | 4 ++-- .../Services/CommentServiceRemoteREST.h | 2 +- .../Services/CommentServiceRemoteREST.m | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Package.swift b/Package.swift index b7b5df79..4dcb9f30 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( targets: [ .binaryTarget( name: "WordPressKit", - url: "https://github.com/user-attachments/files/18570063/WordPressKit.zip", - checksum: "fc25d3065e80af713dac970db7ed89ff37e4cc98afc98b6a2ecf7b47b2ddd0c1" + url: "https://github.com/user-attachments/files/18891163/WordPressKit.zip", + checksum: "a768cf1578321fbda9bcbd025f00697773f9dc978a31b7ae9174c310a20596f8" ), ] ) diff --git a/Sources/WordPressKit/Services/CommentServiceRemoteREST.h b/Sources/WordPressKit/Services/CommentServiceRemoteREST.h index e4323aad..4089461a 100644 --- a/Sources/WordPressKit/Services/CommentServiceRemoteREST.h +++ b/Sources/WordPressKit/Services/CommentServiceRemoteREST.h @@ -30,7 +30,7 @@ */ - (void)updateCommentWithID:(NSNumber * _Nonnull)commentID content:(NSString * _Nonnull)content - success:(void (^ _Nullable)(void))success + success:(void (^ _Nullable)(RemoteComment * _Nullable comment))success failure:(void (^ _Nullable)(NSError * _Nullable error))failure; /** diff --git a/Sources/WordPressKit/Services/CommentServiceRemoteREST.m b/Sources/WordPressKit/Services/CommentServiceRemoteREST.m index 4b0f3761..3a610c20 100644 --- a/Sources/WordPressKit/Services/CommentServiceRemoteREST.m +++ b/Sources/WordPressKit/Services/CommentServiceRemoteREST.m @@ -246,7 +246,7 @@ - (void)syncHierarchicalCommentsForPost:(NSNumber *)postID - (void)updateCommentWithID:(NSNumber *)commentID content:(NSString *)content - success:(void (^)(void))success + success:(void (^)(RemoteComment *comment))success failure:(void (^)(NSError *error))failure { NSString *path = [NSString stringWithFormat:@"sites/%@/comments/%@", self.siteID, commentID]; @@ -260,14 +260,15 @@ - (void)updateCommentWithID:(NSNumber *)commentID [self.wordPressComRESTAPI post:requestUrl parameters:parameters success:^(id responseObject, NSHTTPURLResponse *httpResponse) { - if (success) { - success(); - } - } failure:^(NSError *error, NSHTTPURLResponse *httpResponse) { - if (failure) { - failure(error); - } - }]; + RemoteComment *comment = [self remoteCommentFromJSONDictionary:responseObject]; + if (success) { + success(comment); + } + } failure:^(NSError *error, NSHTTPURLResponse *httpResponse) { + if (failure) { + failure(error); + } + }]; } - (void)replyToPostWithID:(NSNumber *)postID From 2846106755b17ab44d69ea1df1af65e308eab044 Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 28 Feb 2025 17:59:05 -0500 Subject: [PATCH 2/5] Add autoSuggestedFeaturedImage --- Sources/WordPressKit/Models/RemoteReaderPost.h | 1 + Sources/WordPressKit/Models/RemoteReaderPost.m | 1 + 2 files changed, 2 insertions(+) diff --git a/Sources/WordPressKit/Models/RemoteReaderPost.h b/Sources/WordPressKit/Models/RemoteReaderPost.h index f25b51a7..a7ac757e 100644 --- a/Sources/WordPressKit/Models/RemoteReaderPost.h +++ b/Sources/WordPressKit/Models/RemoteReaderPost.h @@ -17,6 +17,7 @@ @property (nonatomic, strong) NSNumber *commentCount; @property (nonatomic) BOOL commentsOpen; @property (nonatomic, strong) NSString *featuredImage; +@property (nonatomic, strong) NSString *autoSuggestedFeaturedImage; @property (nonatomic, strong) NSNumber *feedID; @property (nonatomic, strong) NSNumber *feedItemID; @property (nonatomic, strong) NSString *globalID; diff --git a/Sources/WordPressKit/Models/RemoteReaderPost.m b/Sources/WordPressKit/Models/RemoteReaderPost.m index 061c73b5..c184a046 100644 --- a/Sources/WordPressKit/Models/RemoteReaderPost.m +++ b/Sources/WordPressKit/Models/RemoteReaderPost.m @@ -109,6 +109,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict; self.content = [self postContentFromPostDictionary:dict]; self.date_created_gmt = [self stringOrEmptyString:[dict stringForKey:PostRESTKeyDate]]; self.featuredImage = [self featuredImageFromPostDictionary:dict]; + self.autoSuggestedFeaturedImage = [self featuredMediaImageFromPostDictionary:dict]; self.feedID = [dict numberForKey:PostRESTKeyFeedID]; self.feedItemID = [dict numberForKey:PostRESTKeyFeedItemID]; self.globalID = [self stringOrEmptyString:[dict stringForKey:PostRESTKeyGlobalID]]; From 4500041eb1df4efc6b8ce73290f5675cab256994 Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 28 Feb 2025 18:13:41 -0500 Subject: [PATCH 3/5] Udpate package --- Package.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 4dcb9f30..cdd6fa37 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( targets: [ .binaryTarget( name: "WordPressKit", - url: "https://github.com/user-attachments/files/18891163/WordPressKit.zip", - checksum: "a768cf1578321fbda9bcbd025f00697773f9dc978a31b7ae9174c310a20596f8" + url: "https://github.com/user-attachments/files/19034102/WordPressKit.zip", + checksum: "1d845ec9b6b22ae82f309dc7909333b952ca28a523b8e483230f4d3884ef0a0f" ), ] ) From 30563e2b5e3fc1b009467a92b8282cbff30f79be Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 28 Feb 2025 18:30:59 -0500 Subject: [PATCH 4/5] Add suitableImageFromPostContent --- Package.swift | 4 ++-- Sources/WordPressKit/Models/RemoteReaderPost.h | 1 + Sources/WordPressKit/Models/RemoteReaderPost.m | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Package.swift b/Package.swift index cdd6fa37..965f2427 100644 --- a/Package.swift +++ b/Package.swift @@ -11,8 +11,8 @@ let package = Package( targets: [ .binaryTarget( name: "WordPressKit", - url: "https://github.com/user-attachments/files/19034102/WordPressKit.zip", - checksum: "1d845ec9b6b22ae82f309dc7909333b952ca28a523b8e483230f4d3884ef0a0f" + url: "https://github.com/user-attachments/files/19034191/WordPressKit.zip", + checksum: "34f108cba86b5e4334d1c9af79946dbb8b665e270bdd14bc8f7bc0ba7a898583" ), ] ) diff --git a/Sources/WordPressKit/Models/RemoteReaderPost.h b/Sources/WordPressKit/Models/RemoteReaderPost.h index a7ac757e..fa623cdc 100644 --- a/Sources/WordPressKit/Models/RemoteReaderPost.h +++ b/Sources/WordPressKit/Models/RemoteReaderPost.h @@ -18,6 +18,7 @@ @property (nonatomic) BOOL commentsOpen; @property (nonatomic, strong) NSString *featuredImage; @property (nonatomic, strong) NSString *autoSuggestedFeaturedImage; +@property (nonatomic, strong) NSString *suitableImageFromPostContent; @property (nonatomic, strong) NSNumber *feedID; @property (nonatomic, strong) NSNumber *feedItemID; @property (nonatomic, strong) NSString *globalID; diff --git a/Sources/WordPressKit/Models/RemoteReaderPost.m b/Sources/WordPressKit/Models/RemoteReaderPost.m index c184a046..ebefeb08 100644 --- a/Sources/WordPressKit/Models/RemoteReaderPost.m +++ b/Sources/WordPressKit/Models/RemoteReaderPost.m @@ -109,7 +109,8 @@ - (instancetype)initWithDictionary:(NSDictionary *)dict; self.content = [self postContentFromPostDictionary:dict]; self.date_created_gmt = [self stringOrEmptyString:[dict stringForKey:PostRESTKeyDate]]; self.featuredImage = [self featuredImageFromPostDictionary:dict]; - self.autoSuggestedFeaturedImage = [self featuredMediaImageFromPostDictionary:dict]; + self.autoSuggestedFeaturedImage = [self sanitizeFeaturedImageString:[self featuredMediaImageFromPostDictionary:dict]]; + self.suitableImageFromPostContent = [self sanitizeFeaturedImageString:[self suitableImageFromPostContent:dict]]; self.feedID = [dict numberForKey:PostRESTKeyFeedID]; self.feedItemID = [dict numberForKey:PostRESTKeyFeedItemID]; self.globalID = [self stringOrEmptyString:[dict stringForKey:PostRESTKeyGlobalID]]; From bad387c51b0a2f1a39954a9901c5b2a8687ef82d Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 3 Mar 2025 08:24:26 -0500 Subject: [PATCH 5/5] Update tests --- Tests/WordPressKitTests/Tests/RemoteReaderPostTests.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/WordPressKitTests/Tests/RemoteReaderPostTests.m b/Tests/WordPressKitTests/Tests/RemoteReaderPostTests.m index c5aedf61..565020a1 100644 --- a/Tests/WordPressKitTests/Tests/RemoteReaderPostTests.m +++ b/Tests/WordPressKitTests/Tests/RemoteReaderPostTests.m @@ -209,7 +209,7 @@ - (void)testFeaturedImageFromDictionary { uri, uri, uri] }; imagePath = [remoteReaderPost featuredImageFromPostDictionary:dict]; - XCTAssertTrue([uri isEqualToString:imagePath], @"Failed to retrieve the image uri from the post content."); + XCTAssertTrue(imagePath.length == 0, @"No image should be retrieved from the content"); dict = [self editorialDictionaryWithKey:@"image" value:uri]; imagePath = [remoteReaderPost featuredImageFromPostDictionary:dict];