Skip to content
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: 4 additions & 0 deletions Sources/WordPressData/Objective-C/PostHelper.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
@import WordPressShared;
@import NSObject_SafeExpectations;

PostServiceType const PostServiceTypePost = @"post";
PostServiceType const PostServiceTypePage = @"page";
PostServiceType const PostServiceTypeAny = @"any";

@implementation PostHelper

+ (void)updatePost:(AbstractPost *)post withRemotePost:(RemotePost *)remotePost inContext:(NSManagedObjectContext *)managedObjectContext {
Expand Down
8 changes: 6 additions & 2 deletions Sources/WordPressData/Objective-C/include/PostHelper.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import <WordPressData/PostService.h>

@class AbstractPost, RemotePost;
@class AbstractPost, RemotePost, Post, Blog;

typedef NSString * PostServiceType NS_TYPED_ENUM;
extern PostServiceType const PostServiceTypePost;
extern PostServiceType const PostServiceTypePage;
extern PostServiceType const PostServiceTypeAny;

NS_ASSUME_NONNULL_BEGIN

Expand Down
2 changes: 0 additions & 2 deletions Sources/WordPressData/WordPressData.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ FOUNDATION_EXPORT const unsigned char WordPressDataVersionString[];
#import <WordPressData/LocalCoreDataService.h>
#import <WordPressData/Media.h>
#import <WordPressData/PostHelper.h>
#import <WordPressData/PostService.h>
#import <WordPressData/PostServiceOptions.h>
#import <WordPressData/ReaderPost.h>
#import <WordPressData/WPAccount.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,21 @@ class MockReblogPresenter: ReaderReblogPresenter {

class ReblogTestCase: CoreDataTestCase {
var readerPost: ReaderPost?
var postService: PostService?

override func setUp() {
readerPost = ReaderPost(context: self.mainContext)
postService = PostService(managedObjectContext: self.mainContext)
}

override func tearDown() {
readerPost = nil
postService = nil
}
}

class ReaderReblogActionTests: ReblogTestCase {

func testExecuteAction() {
// Given
let presenter = MockReblogPresenter(postService: postService!)
let presenter = MockReblogPresenter()
presenter.presentReblogExpectation = expectation(description: "presentBlog was called")
let action = ReaderReblogAction(coreDataStack: contextManager, presenter: presenter)
let controller = UIViewController()
Expand All @@ -53,7 +50,7 @@ class ReblogPresenterTests: ReblogTestCase {
let draftPosts = NSFetchRequest<Post>(entityName: "Post")
draftPosts.predicate = NSPredicate(format: "status = %@", Post.Status.draft.rawValue)
try XCTAssertEqual(mainContext.count(for: draftPosts), 0)
let presenter = ReaderReblogPresenter(postService: postService!)
let presenter = ReaderReblogPresenter()
// When
presenter.presentReblog(coreDataStack: contextManager, readerPost: readerPost!, origin: UIViewController())
// Then
Expand All @@ -65,7 +62,7 @@ class ReblogPresenterTests: ReblogTestCase {
for _ in 1...2 {
BlogBuilder(contextManager.mainContext).isHostedAtWPcom().withAnAccount().build()
}
let presenter = ReaderReblogPresenter(postService: postService!)
let presenter = ReaderReblogPresenter()
let origin = MockViewController()
origin.presentExpectation = expectation(description: "blog selector is presented")
// When
Expand Down
10 changes: 10 additions & 0 deletions WordPress/Classes/Services/PostService+Likes.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import WordPressData
import WordPressKit

final class PostService {
let managedObjectContext: NSManagedObjectContext
let postServiceRemoteFactory: PostServiceRemoteFactory

init(managedObjectContext: NSManagedObjectContext, postServiceRemoteFactory: PostServiceRemoteFactory = PostServiceRemoteFactory()) {
self.managedObjectContext = managedObjectContext
self.postServiceRemoteFactory = postServiceRemoteFactory
}
}

extension PostService {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ NS_ASSUME_NONNULL_BEGIN

@end

@class PostServiceSyncOptions;
@class MenuPostServiceSyncOptions;

@protocol MenuItemSourcePostAbstractViewSubclass <NSObject>
- (Class)entityClass;
- (PostServiceSyncOptions *)syncOptions;
- (MenuPostServiceSyncOptions *)syncOptions;
@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import "MenuItemAbstractPostsViewController.h"
@import WordPressData;
#import "MenuPostService.h"
#import "MenuPostServiceOptions.h"
@import WordPressKit;

@interface MenuItemAbstractPostsViewController () <MenuItemSourcePostAbstractViewSubclass>
Expand Down Expand Up @@ -54,8 +55,8 @@ - (void)syncPosts
[self showLoadingSourcesIndicatorIfEmpty];
self.additionalPostsAvailableForSync = YES;

PostService *service = [[PostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
PostServiceSyncOptions *options = [self syncOptions];
MenuPostService *service = [[MenuPostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
MenuPostServiceSyncOptions *options = [self syncOptions];
[service syncPostsOfType:[self sourceItemType]
withOptions:options
forBlog:[self blog]
Expand Down Expand Up @@ -110,15 +111,15 @@ - (Class)entityClass
return nil;
}

- (PostServiceSyncOptions *)syncOptions
- (MenuPostServiceSyncOptions *)syncOptions
{
PostServiceSyncOptions *options = [[PostServiceSyncOptions alloc] init];
MenuPostServiceSyncOptions *options = [[MenuPostServiceSyncOptions alloc] init];
options.statuses = @[PostStatusPublish, PostStatusPrivate];
options.number = @(PostServiceDefaultNumberToSync);
return options;
}

- (void)didFinishSyncingPosts:(NSArray *)posts options:(PostServiceSyncOptions *)options
- (void)didFinishSyncingPosts:(NSArray *)posts options:(MenuPostServiceSyncOptions *)options
{
self.isSyncing = NO;
if (posts) {
Expand All @@ -143,8 +144,8 @@ - (void)scrollingWillDisplayEndOfTableView:(UITableView *)tableView
self.isSyncingAdditionalPosts = YES;
[self showLoadingSourcesIndicator];

PostService *service = [[PostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
PostServiceSyncOptions *options = [self syncOptions];
MenuPostService *service = [[MenuPostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
MenuPostServiceSyncOptions *options = [self syncOptions];
options.offset = @(self.resultsController.fetchedObjects.count);
[service syncPostsOfType:[self sourceItemType]
withOptions:options
Expand Down Expand Up @@ -202,8 +203,8 @@ - (void)searchBarInputChangeDetectedForRemoteResultsUpdateWithText:(NSString *)s
};

DDLogDebug(@"MenuItemSourcePostView: Searching posts via PostService");
PostService *service = [[PostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
PostServiceSyncOptions *options = [self syncOptions];
MenuPostService *service = [[MenuPostService alloc] initWithManagedObjectContext:[self managedObjectContext]];
MenuPostServiceSyncOptions *options = [self syncOptions];
options.search = searchText;
[service syncPostsOfType:[self sourceItemType]
withOptions:options
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "MenuItemPagesViewController.h"
#import "WordPress-Swift.h"
@import WordPressData;
#import "MenuPostServiceOptions.h"

@interface MenuItemAbstractPostsViewController () <MenuItemSourcePostAbstractViewSubclass>
@end
Expand Down Expand Up @@ -31,9 +31,9 @@ - (Class)entityClass
return [Page class];
}

- (PostServiceSyncOptions *)syncOptions
- (MenuPostServiceSyncOptions *)syncOptions
{
PostServiceSyncOptions *options = [super syncOptions];
MenuPostServiceSyncOptions *options = [super syncOptions];
options.order = PostServiceResultsOrderAscending;
options.orderBy = PostServiceResultsOrderingByTitle;
return options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#import <Foundation/Foundation.h>
#import <WordPressData/LocalCoreDataService.h>

@import WordPressData;

@class AbstractPost;
@class Blog;
Expand All @@ -8,21 +9,16 @@
@class RemotePost;
@class RemoteUser;
@class PostServiceRemoteFactory;
@class PostServiceSyncOptions;
@class MenuPostServiceSyncOptions;

NS_ASSUME_NONNULL_BEGIN

typedef void(^PostServiceSyncSuccess)(NSArray<AbstractPost *> * _Nullable posts);
typedef void(^PostServiceSyncFailure)(NSError * _Nullable error);

typedef NSString * PostServiceType NS_TYPED_ENUM;
extern PostServiceType const PostServiceTypePost;
extern PostServiceType const PostServiceTypePage;
extern PostServiceType const PostServiceTypeAny;
extern const NSUInteger PostServiceDefaultNumberToSync;


@interface PostService : LocalCoreDataService
@interface MenuPostService : LocalCoreDataService

// This is public so it can be accessed from Swift extensions.
@property (nonnull, strong, nonatomic) PostServiceRemoteFactory *postServiceRemoteFactory;
Expand Down Expand Up @@ -59,7 +55,7 @@ extern const NSUInteger PostServiceDefaultNumberToSync;
@param failure A failure block
*/
- (void)syncPostsOfType:(PostServiceType)postType
withOptions:(PostServiceSyncOptions *)options
withOptions:(MenuPostServiceSyncOptions *)options
forBlog:(Blog *)blog
success:(PostServiceSyncSuccess)success
failure:(PostServiceSyncFailure)failure;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
#import "Blog.h"
#import "PostService.h"
#import "PostServiceOptions.h"
#import "Media.h"
#import "WordPressData-Swift.h"
#import "MenuPostService.h"
#import "MenuPostServiceOptions.h"
#import "PostHelper.h"
@import WordPressKit;
@import WordPressShared;
@import WordPressData;

PostServiceType const PostServiceTypePost = @"post";
PostServiceType const PostServiceTypePage = @"page";
PostServiceType const PostServiceTypeAny = @"any";
NSString * const PostServiceErrorDomain = @"PostServiceErrorDomain";

const NSUInteger PostServiceDefaultNumberToSync = 40;

@interface PostService ()

@end

@implementation PostService
@implementation MenuPostService

- (instancetype)initWithManagedObjectContext:(NSManagedObjectContext *)context {
return [self initWithManagedObjectContext:context
Expand Down Expand Up @@ -46,7 +38,7 @@ - (void)syncPostsOfType:(PostServiceType)postType
}

- (void)syncPostsOfType:(PostServiceType)postType
withOptions:(PostServiceSyncOptions *)options
withOptions:(MenuPostServiceSyncOptions *)options
forBlog:(Blog *)blog
success:(PostServiceSyncSuccess)success
failure:(PostServiceSyncFailure)failure
Expand All @@ -61,7 +53,7 @@ - (void)syncPostsOfType:(PostServiceType)postType
}

- (void)syncPostsOfType:(PostServiceType)postType
withOptions:(PostServiceSyncOptions *)options
withOptions:(MenuPostServiceSyncOptions *)options
forBlog:(Blog *)blog
loadedPosts:(NSMutableArray <RemotePost *>*)loadedPosts
syncAll:(BOOL)syncAll
Expand Down Expand Up @@ -128,7 +120,7 @@ - (void)syncPostsOfType:(PostServiceType)postType
#pragma mark - Helpers

- (NSDictionary *)remoteSyncParametersDictionaryForRemote:(nonnull id <PostServiceRemote>)remote
withOptions:(nonnull PostServiceSyncOptions *)options
withOptions:(nonnull MenuPostServiceSyncOptions *)options
{
return [remote dictionaryWithRemoteOptions:options];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
@import WordPressKitObjC;

/**
@class PostServiceSyncOptions
@class MenuPostServiceSyncOptions
@brief An object of options and paramters for specific filtering and syncing of posts.
See each remote API parameters for specifics regarding default values and limits.
WP.com/REST Jetpack: https://developer.wordpress.com/docs/api/1.1/get/sites/%24site/posts/
XML-RPC: https://codex.wordpress.org/XML-RPC_WordPress_API/Posts
*/
@interface PostServiceSyncOptions : NSObject <PostServiceRemoteOptions>
@interface MenuPostServiceSyncOptions : NSObject <PostServiceRemoteOptions>

/**
When set to true previously synced AbstractPosts matching statuses and authorID will be purged while updating.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#import "PostServiceOptions.h"
#import "MenuPostServiceOptions.h"

@implementation PostServiceSyncOptions
@implementation MenuPostServiceSyncOptions

- (instancetype)init
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class AbstractPostListViewController: UIViewController,
}

@objc func numberOfPostsPerSync() -> UInt {
return PostServiceDefaultNumberToSync
return 40
}

// MARK: - WPContentSyncHelperDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import WordPressUI

/// Presents the appropriate reblog scene, depending on the number of available sites
class ReaderReblogPresenter {
private let postService: PostService

private struct NoSitesConfiguration {
static let noSitesTitle = NSLocalizedString(
Expand All @@ -26,16 +25,6 @@ class ReaderReblogPresenter {
comment: "Back button title.")
}

init(postService: PostService? = nil) {

// fallback for self.postService
func makePostService() -> PostService {
let context = ContextManager.shared.mainContext
return PostService(managedObjectContext: context)
}
self.postService = postService ?? makePostService()
}

/// Presents the reblog screen(s)
func presentReblog(coreDataStack: CoreDataStack,
readerPost: ReaderPost,
Expand Down
2 changes: 0 additions & 2 deletions WordPress/WordPress.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1178,8 +1178,6 @@
"Objective-C/include/LocalCoreDataService.h",
"Objective-C/include/Media.h",
"Objective-C/include/PostHelper.h",
"Objective-C/include/PostService.h",
"Objective-C/include/PostServiceOptions.h",
"Objective-C/include/ReaderPost.h",
"Objective-C/include/WPAccount.h",
WordPressData.h,
Expand Down