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
19 changes: 10 additions & 9 deletions Parse/Internal/Object/PinningStore/PFPinningObjectStore.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <Parse/PFConstants.h>

#import "PFDataProvider.h"
#import "PFMacros.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -41,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN

@return `BFTask` with `PFPin` result if pinning succeeds.
*/
- (BFTask *)fetchPinAsyncWithName:(NSString *)name;
- (BFTask PF_GENERIC(PFPin *)*)fetchPinAsyncWithName:(NSString *)name;

/**
Pins given objects to the pin. Creates new pin if the pin with such name is not found.
Expand All @@ -50,11 +51,11 @@ NS_ASSUME_NONNULL_BEGIN
@param name Pin Name.
@param includeChildren Whether children of `objects` should be pinned as well.

@return `BFTask` with `@YES` result.
@return `BFTask` with no result.
*/
- (BFTask *)pinObjectsAsync:(nullable NSArray *)objects
withPinName:(NSString *)name
includeChildren:(BOOL)includeChildren;
- (BFTask PF_GENERIC(PFVoid)*)pinObjectsAsync:(nullable NSArray *)objects
withPinName:(NSString *)name
includeChildren:(BOOL)includeChildren;

///--------------------------------------
/// @name Unpin
Expand All @@ -66,18 +67,18 @@ NS_ASSUME_NONNULL_BEGIN
@param objects Objects to unpin.
@param name Pin name.

@return `BFTask` with `@YES` result.
@return `BFTask` with no result.
*/
- (BFTask *)unpinObjectsAsync:(nullable NSArray *)objects withPinName:(NSString *)name;
- (BFTask PF_GENERIC(PFVoid)*)unpinObjectsAsync:(nullable NSArray *)objects withPinName:(NSString *)name;

/**
Unpins all objects from the pin.

@param name Pin name.

@return `BFTask` with `YES` result.
@return `BFTask` with no result.
*/
- (BFTask *)unpinAllObjectsAsyncWithPinName:(NSString *)name;
- (BFTask PF_GENERIC(PFVoid)*)unpinAllObjectsAsyncWithPinName:(NSString *)name;

@end

Expand Down
27 changes: 13 additions & 14 deletions Parse/Internal/Object/PinningStore/PFPinningObjectStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#import "PFQueryPrivate.h"

@interface PFPinningObjectStore () {
NSMapTable *_pinCacheTable;
NSMapTable PF_GENERIC(NSString *, BFTask<PFPin *>*)*_pinCacheTable;
dispatch_queue_t _pinCacheAccessQueue;
BFExecutor *_pinCacheAccessExecutor;
}
Expand Down Expand Up @@ -55,7 +55,7 @@ + (instancetype)storeWithDataSource:(id<PFOfflineStoreProvider>)dataSource {
#pragma mark - Pin
///--------------------------------------

- (BFTask *)fetchPinAsyncWithName:(NSString *)name {
- (BFTask PF_GENERIC(PFPin *)*)fetchPinAsyncWithName:(NSString *)name {
@weakify(self);
return [BFTask taskFromExecutor:_pinCacheAccessExecutor withBlock:^id{
BFTask *cachedTask = [_pinCacheTable objectForKey:name] ?: [BFTask taskWithResult:nil];
Expand All @@ -79,13 +79,13 @@ - (BFTask *)fetchPinAsyncWithName:(NSString *)name {
}];
}

- (BFTask *)pinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name includeChildren:(BOOL)includeChildren {
- (BFTask PF_GENERIC(PFVoid) *)pinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name includeChildren:(BOOL)includeChildren {
if (objects.count == 0) {
return [BFTask taskWithResult:@YES];
return [BFTask taskWithResult:nil];
}

@weakify(self);
return [[[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
@strongify(self);
PFPin *pin = task.result;
PFOfflineStore *store = self.dataSource.offlineStore;
Expand Down Expand Up @@ -113,26 +113,26 @@ - (BFTask *)pinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name incl
saveTask = [store saveObjectLocallyAsync:pin withChildren:pin.objects];
}
return saveTask;
}] continueWithSuccessResult:@YES];
}];
}

///--------------------------------------
#pragma mark - Unpin
///--------------------------------------

- (BFTask *)unpinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name {
- (BFTask PF_GENERIC(PFVoid) *)unpinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name {
if (objects.count == 0) {
return [BFTask taskWithResult:@YES];
return [BFTask taskWithResult:nil];
}

@weakify(self);
return [[[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
@strongify(self);
PFPin *pin = task.result;
NSMutableArray *modified = pin.objects;
if (!modified) {
// Nothing to unpin
return task;
return nil;
}

//TODO (hallucinogen): some stuff @grantland mentioned can't be done maybe needs to be done here
Expand All @@ -148,15 +148,14 @@ - (BFTask *)unpinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name {
pin.objects = modified;

return [store saveObjectLocallyAsync:pin includeChildren:YES];
}] continueWithSuccessResult:@YES];
}];
}

- (BFTask *)unpinAllObjectsAsyncWithPinName:(NSString *)name {
- (BFTask PF_GENERIC(PFVoid)*)unpinAllObjectsAsyncWithPinName:(NSString *)name {
@weakify(self);
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
@strongify(self);
PFPin *pin = task.result;
return [[self.dataSource.offlineStore unpinObjectAsync:pin] continueWithSuccessResult:@YES];
return [self.dataSource.offlineStore unpinObjectAsync:task.result];
}];
}

Expand Down
32 changes: 16 additions & 16 deletions Parse/PFObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -2342,7 +2342,7 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation {
#pragma mark - Pinning
///--------------------------------------

- (BFTask *)pinInBackground {
- (BFTask PF_GENERIC(NSNumber *)*)pinInBackground {
return [self pinInBackgroundWithName:PFObjectDefaultPin];
}

Expand All @@ -2354,19 +2354,19 @@ - (void)pinInBackgroundWithName:(NSString *)name block:(PFBooleanResultBlock)blo
[[self pinInBackgroundWithName:name] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

- (BFTask *)pinInBackgroundWithName:(NSString *)name {
- (BFTask PF_GENERIC(NSNumber *)*)pinInBackgroundWithName:(NSString *)name {
return [self _pinInBackgroundWithName:name includeChildren:YES];
}

- (BFTask *)_pinInBackgroundWithName:(NSString *)name includeChildren:(BOOL)includeChildren {
- (BFTask PF_GENERIC(NSNumber *)*)_pinInBackgroundWithName:(NSString *)name includeChildren:(BOOL)includeChildren {
return [[self class] _pinAllInBackground:@[ self ] withName:name includeChildren:includeChildren];
}

///--------------------------------------
#pragma mark - Pinning Many Objects
///--------------------------------------

+ (BFTask *)pinAllInBackground:(NSArray *)objects {
+ (BFTask PF_GENERIC(NSNumber *)*)pinAllInBackground:(NSArray *)objects {
return [self pinAllInBackground:objects withName:PFObjectDefaultPin];
}

Expand All @@ -2375,7 +2375,7 @@ + (void)pinAllInBackground:(NSArray *)objects
[[self pinAllInBackground:objects] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

+ (BFTask *)pinAllInBackground:(NSArray *)objects withName:(NSString *)name {
+ (BFTask PF_GENERIC(NSNumber *)*)pinAllInBackground:(NSArray *)objects withName:(NSString *)name {
return [self _pinAllInBackground:objects withName:name includeChildren:YES];
}

Expand All @@ -2385,25 +2385,25 @@ + (void)pinAllInBackground:(NSArray *)objects
[[self pinAllInBackground:objects withName:name] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

+ (BFTask *)_pinAllInBackground:(NSArray *)objects
withName:(NSString *)name
includeChildren:(BOOL)includeChildren {
return [[self pinningObjectStore] pinObjectsAsync:objects withPinName:name includeChildren:includeChildren];
+ (BFTask PF_GENERIC(NSNumber *)*)_pinAllInBackground:(NSArray *)objects withName:(NSString *)name includeChildren:(BOOL)includeChildren {
return [[[self pinningObjectStore] pinObjectsAsync:objects
withPinName:name
includeChildren:includeChildren] continueWithSuccessResult:@YES];
}

///--------------------------------------
#pragma mark - Unpinning
///--------------------------------------

- (BFTask *)unpinInBackground {
- (BFTask PF_GENERIC(NSNumber *)*)unpinInBackground {
return [self unpinInBackgroundWithName:PFObjectDefaultPin];
}

- (void)unpinInBackgroundWithBlock:(PFBooleanResultBlock)block {
[[self unpinInBackground] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

- (BFTask *)unpinInBackgroundWithName:(NSString *)name {
- (BFTask PF_GENERIC(NSNumber *)*)unpinInBackgroundWithName:(NSString *)name {
return [[self class] unpinAllInBackground:@[ self ] withName:name];
}

Expand All @@ -2415,7 +2415,7 @@ - (void)unpinInBackgroundWithName:(NSString *)name block:(PFBooleanResultBlock)b
#pragma mark - Unpinning Many Objects
///--------------------------------------

+ (BFTask *)unpinAllObjectsInBackground {
+ (BFTask PF_GENERIC(NSNumber *)*)unpinAllObjectsInBackground {
return [self unpinAllObjectsInBackgroundWithName:PFObjectDefaultPin];
}

Expand All @@ -2427,8 +2427,8 @@ + (void)unpinAllObjectsInBackgroundWithName:(NSString *)name block:(PFBooleanRes
[[self unpinAllObjectsInBackgroundWithName:name] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

+ (BFTask *)unpinAllObjectsInBackgroundWithName:(NSString *)name {
return [[self pinningObjectStore] unpinAllObjectsAsyncWithPinName:name];
+ (BFTask PF_GENERIC(NSNumber *)*)unpinAllObjectsInBackgroundWithName:(NSString *)name {
return [[[self pinningObjectStore] unpinAllObjectsAsyncWithPinName:name] continueWithSuccessResult:@YES];
}

+ (BFTask *)unpinAllInBackground:(NSArray *)objects {
Expand All @@ -2439,8 +2439,8 @@ + (void)unpinAllInBackground:(NSArray *)objects block:(PFBooleanResultBlock)bloc
[[self unpinAllInBackground:objects] thenCallBackOnMainThreadWithBoolValueAsync:block];
}

+ (BFTask *)unpinAllInBackground:(NSArray *)objects withName:(NSString *)name {
return [[self pinningObjectStore] unpinObjectsAsync:objects withPinName:name];
+ (BFTask PF_GENERIC(NSNumber *)*)unpinAllInBackground:(NSArray *)objects withName:(NSString *)name {
return [[[self pinningObjectStore] unpinObjectsAsync:objects withPinName:name] continueWithSuccessResult:@YES];
}

+ (void)unpinAllInBackground:(NSArray *)objects withName:(NSString *)name block:(PFBooleanResultBlock)block {
Expand Down
18 changes: 9 additions & 9 deletions Tests/Unit/PinningObjectStoreTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ - (void)testPinObjects {
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
XCTAssertEqualObjects(pin.objects, @[ object ]);
[expectation fulfill];
return nil;
Expand Down Expand Up @@ -155,7 +155,7 @@ - (void)testPinObjectsExistingPin {
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
XCTAssertEqualObjects(pin.objects, (@[ existingObject, object ]));
[expectation fulfill];
return nil;
Expand All @@ -170,7 +170,7 @@ - (void)testPinZeroObjects {

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store pinObjectsAsync:nil withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand All @@ -195,7 +195,7 @@ - (void)testPinObjectsWithoutChildren {
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:NO] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
XCTAssertEqualObjects(pin.objects, (@[ object ]));
[expectation fulfill];
return nil;
Expand All @@ -221,7 +221,7 @@ - (void)testUnpinObjects {

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store unpinObjectsAsync:@[ object ] withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand All @@ -246,7 +246,7 @@ - (void)testUnpinObjectsEmptyPin {

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store unpinObjectsAsync:@[ object ] withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand All @@ -260,7 +260,7 @@ - (void)testUnpinZeroObjects {

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store unpinObjectsAsync:nil withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand All @@ -278,7 +278,7 @@ - (void)testUnpinObjectsNoPin {
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store unpinObjectsAsync:@[ object ] withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand All @@ -300,7 +300,7 @@ - (void)testUnpinAllObjects {

XCTestExpectation *expectation = [self currentSelectorTestExpectation];
[[store unpinAllObjectsAsyncWithPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
XCTAssertEqualObjects(task.result, @YES);
XCTAssertNil(task.result);
[expectation fulfill];
return nil;
}];
Expand Down