Skip to content

Commit 4bc7581

Browse files
authored
Remove unused Objective-C code in Reader (#25033)
* Remove fetchPostAtURL * Delete
1 parent aa4119c commit 4bc7581

File tree

7 files changed

+0
-148
lines changed

7 files changed

+0
-148
lines changed

Modules/Sources/WordPressKitObjC/ReaderPostServiceRemote.m

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -98,46 +98,6 @@ - (void)fetchPost:(NSUInteger)postID
9898
}];
9999
}
100100

101-
/**
102-
Fetches a specific post from the specified URL
103-
104-
@param postURL The URL of the post to fetch
105-
@param success block called on a successful fetch.
106-
@param failure block called if there is any error. `error` can be any underlying network error.
107-
*/
108-
- (void)fetchPostAtURL:(NSURL *)postURL
109-
success:(void (^)(RemoteReaderPost *post))success
110-
failure:(void (^)(NSError *error))failure
111-
{
112-
NSString *path = [self apiPathForPostAtURL:postURL];
113-
114-
if (!path) {
115-
failure(nil);
116-
return;
117-
}
118-
119-
[self.wordPressComRESTAPI get:path
120-
parameters:nil
121-
success:^(id responseObject, NSHTTPURLResponse *httpResponse) {
122-
if (!success) {
123-
return;
124-
}
125-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
126-
// Do all of this work on a background thread, then call success on the main thread.
127-
// Do this to avoid any chance of blocking the UI while parsing.
128-
RemoteReaderPost *post = [[RemoteReaderPost alloc] initWithDictionary:(NSDictionary *)responseObject];
129-
dispatch_async(dispatch_get_main_queue(), ^{
130-
success(post);
131-
});
132-
});
133-
134-
} failure:^(NSError *error, NSHTTPURLResponse *httpResponse) {
135-
if (failure) {
136-
failure(error);
137-
}
138-
}];
139-
}
140-
141101
- (void)likePost:(NSUInteger)postID
142102
forSite:(NSUInteger)siteID
143103
success:(void (^)(void))success
@@ -260,23 +220,4 @@ - (RemoteReaderPost *)formatPostDictionary:(NSDictionary *)dict offset:(CGFloat)
260220
return post;
261221
}
262222

263-
- (nullable NSString *)apiPathForPostAtURL:(NSURL *)url
264-
{
265-
NSURLComponents *components = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:NO];
266-
267-
NSString *hostname = components.host;
268-
NSArray *pathComponents = [[components.path pathComponents] filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != '/'"] ];
269-
NSString *slug = [components.path lastPathComponent];
270-
271-
// We expect 4 path components for a post – year, month, day, slug, plus a '/' on either end
272-
if (hostname == nil || pathComponents.count != 4 || slug == nil) {
273-
return nil;
274-
}
275-
276-
NSString *path = [NSString stringWithFormat:@"sites/%@/posts/slug:%@?meta=site,likes", hostname, slug];
277-
278-
return [self pathForEndpoint:path
279-
withVersion:WordPressComRESTAPIVersion_1_1];
280-
}
281-
282223
@end

Modules/Sources/WordPressKitObjC/include/ReaderPostServiceRemote.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,6 @@
5151
success:(void (^)(RemoteReaderPost *post))success
5252
failure:(void (^)(NSError *error))failure;
5353

54-
/**
55-
Fetches a specific post from the specified URL
56-
57-
@param postURL The URL of the post to fetch
58-
@param success block called on a successful fetch.
59-
@param failure block called if there is any error. `error` can be any underlying network error.
60-
*/
61-
- (void)fetchPostAtURL:(NSURL *)postURL
62-
success:(void (^)(RemoteReaderPost *post))success
63-
failure:(void (^)(NSError *error))failure;
64-
6554
/**
6655
Mark a post as liked by the user.
6756

Tests/KeystoneTests/Tests/Reader/ReaderDetailCoordinatorTests.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ private class ReaderPostServiceMock: ReaderPostService {
202202
var didCallFetchPostWithPostID: UInt?
203203
var didCallFetchPostWithSiteID: UInt?
204204
var didCallFetchPostWithIsFeed: Bool?
205-
var didCallFetchWithURL: URL?
206205

207206
/// The post that should be returned by the mock
208207
var returnPost: ReaderPost?
@@ -230,15 +229,6 @@ private class ReaderPostServiceMock: ReaderPostService {
230229

231230
success(returnPost)
232231
}
233-
234-
override func fetchPost(at postURL: URL!, success: ((ReaderPost?) -> Void)!, failure: ((Error?) -> Void)!) {
235-
didCallFetchWithURL = postURL
236-
237-
guard !forceError else {
238-
failure(nil)
239-
return
240-
}
241-
}
242232
}
243233

244234
private class ReaderDetailViewMock: UIViewController, ReaderDetailView {

WordPress/Classes/Services/Reader Post/ReaderPostService.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,6 @@ extern NSString * const ReaderPostServiceToggleSiteFollowingState;
7777
success:(void (^)(ReaderPost *post))success
7878
failure:(void (^)(NSError *error))failure;
7979

80-
/**
81-
Fetches a specific post from the specified URL
82-
83-
@param postURL The URL of the post to fetch
84-
@param success block called on a successful fetch.
85-
@param failure block called if there is any error. `error` can be any underlying network error.
86-
*/
87-
- (void)fetchPostAtURL:(NSURL *)postURL
88-
success:(void (^)(ReaderPost *post))success
89-
failure:(void (^)(NSError *error))failure;
90-
9180
/**
9281
Silently refresh posts for the followed sites topic.
9382
Note that calling this method creates a new service instance that performs

WordPress/Classes/Services/Reader Post/ReaderPostService.m

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -156,33 +156,6 @@ - (void)fetchPost:(NSUInteger)postID forSite:(NSUInteger)siteID isFeed:(BOOL)isF
156156
} failure:failure];
157157
}
158158

159-
- (void)fetchPostAtURL:(NSURL *)postURL
160-
success:(void (^)(ReaderPost *post))success
161-
failure:(void (^)(NSError *error))failure
162-
{
163-
ReaderPostServiceRemote *remoteService = [[ReaderPostServiceRemote alloc] initWithWordPressComRestApi:[self apiForRequest]];
164-
[remoteService fetchPostAtURL:postURL
165-
success:^(RemoteReaderPost *remotePost) {
166-
if (!success) {
167-
return;
168-
}
169-
170-
NSManagedObjectID * __block postObjectID = nil;
171-
[self.coreDataStack performAndSaveUsingBlock:^(NSManagedObjectContext *context) {
172-
ReaderPost *post = [self createOrReplaceFromRemotePost:remotePost forTopic:nil inContext:context];
173-
174-
NSError *error;
175-
BOOL obtainedID = [context obtainPermanentIDsForObjects:@[post] error:&error];
176-
if (!obtainedID) {
177-
DDLogError(@"Error obtaining a permanent ID for post. %@, %@", post, error);
178-
}
179-
postObjectID = post.objectID;
180-
} completion:^{
181-
success([self.coreDataStack.mainContext existingObjectWithID:postObjectID error:nil]);
182-
} onQueue:dispatch_get_main_queue()];
183-
} failure:failure];
184-
}
185-
186159
- (void)refreshPostsForFollowedTopic
187160
{
188161
[self.coreDataStack performAndSaveUsingBlock:^(NSManagedObjectContext *context) {

WordPress/Classes/Services/ReaderTopicService.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,6 @@ extern NSString * const ReaderTopicFreshlyPressedPathCommponent;
3838
- (void)deleteAllSearchTopics;
3939

4040
/**
41-
Deletes all topics that do not appear in the menu from core data and saves the context.
42-
Use to clean-up previewed topics that are lingering in core data.
43-
*/
44-
- (void)deleteNonMenuTopics;
45-
4641
/**
4742
Globally sets the `inUse` flag to fall for all posts.
4843
*/

WordPress/Classes/Services/ReaderTopicService.m

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,31 +136,6 @@ - (void)deleteAllSearchTopics
136136
}];
137137
}
138138

139-
- (void)deleteNonMenuTopics
140-
{
141-
[self.coreDataStack performAndSaveUsingBlock:^(NSManagedObjectContext *context) {
142-
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:[ReaderAbstractTopic classNameWithoutNamespaces]];
143-
request.predicate = [NSPredicate predicateWithFormat:@"showInMenu = false AND inUse = false"];
144-
145-
NSError *error;
146-
NSArray *results = [context executeFetchRequest:request error:&error];
147-
if (error) {
148-
DDLogError(@"%@ error executing fetch request: %@", NSStringFromSelector(_cmd), error);
149-
return;
150-
}
151-
152-
for (ReaderAbstractTopic *topic in results) {
153-
// Do not purge site topics that are followed. We want these to stay so they appear immediately when managing followed sites.
154-
if ([topic isKindOfClass:[ReaderSiteTopic class]] && topic.following) {
155-
continue;
156-
}
157-
DDLogInfo(@"Deleting topic: %@", topic.title);
158-
[self preserveSavedPostsFromTopic:topic];
159-
[context deleteObject:topic];
160-
}
161-
}];
162-
}
163-
164139
- (void)clearInUseFlags
165140
{
166141
[self.coreDataStack performAndSaveUsingBlock:^(NSManagedObjectContext *context) {

0 commit comments

Comments
 (0)