Skip to content

Commit c7e8645

Browse files
committed
Merge pull request #697 from ParsePlatform/nlutsenko.unpin.fix
Fixed potential issue with wrong result type set on pin/unpin methods of PFObject.
2 parents 93bd9eb + b7a818e commit c7e8645

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

Parse/Internal/Object/PinningStore/PFPinningObjectStore.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <Parse/PFConstants.h>
1313

1414
#import "PFDataProvider.h"
15+
#import "PFMacros.h"
1516

1617
NS_ASSUME_NONNULL_BEGIN
1718

@@ -41,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN
4142
4243
@return `BFTask` with `PFPin` result if pinning succeeds.
4344
*/
44-
- (BFTask *)fetchPinAsyncWithName:(NSString *)name;
45+
- (BFTask PF_GENERIC(PFPin *)*)fetchPinAsyncWithName:(NSString *)name;
4546

4647
/**
4748
Pins given objects to the pin. Creates new pin if the pin with such name is not found.
@@ -50,11 +51,11 @@ NS_ASSUME_NONNULL_BEGIN
5051
@param name Pin Name.
5152
@param includeChildren Whether children of `objects` should be pinned as well.
5253
53-
@return `BFTask` with `@YES` result.
54+
@return `BFTask` with no result.
5455
*/
55-
- (BFTask *)pinObjectsAsync:(nullable NSArray *)objects
56-
withPinName:(NSString *)name
57-
includeChildren:(BOOL)includeChildren;
56+
- (BFTask PF_GENERIC(PFVoid)*)pinObjectsAsync:(nullable NSArray *)objects
57+
withPinName:(NSString *)name
58+
includeChildren:(BOOL)includeChildren;
5859

5960
///--------------------------------------
6061
/// @name Unpin
@@ -66,18 +67,18 @@ NS_ASSUME_NONNULL_BEGIN
6667
@param objects Objects to unpin.
6768
@param name Pin name.
6869
69-
@return `BFTask` with `@YES` result.
70+
@return `BFTask` with no result.
7071
*/
71-
- (BFTask *)unpinObjectsAsync:(nullable NSArray *)objects withPinName:(NSString *)name;
72+
- (BFTask PF_GENERIC(PFVoid)*)unpinObjectsAsync:(nullable NSArray *)objects withPinName:(NSString *)name;
7273

7374
/**
7475
Unpins all objects from the pin.
7576
7677
@param name Pin name.
7778
78-
@return `BFTask` with `YES` result.
79+
@return `BFTask` with no result.
7980
*/
80-
- (BFTask *)unpinAllObjectsAsyncWithPinName:(NSString *)name;
81+
- (BFTask PF_GENERIC(PFVoid)*)unpinAllObjectsAsyncWithPinName:(NSString *)name;
8182

8283
@end
8384

Parse/Internal/Object/PinningStore/PFPinningObjectStore.m

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import "PFQueryPrivate.h"
1818

1919
@interface PFPinningObjectStore () {
20-
NSMapTable *_pinCacheTable;
20+
NSMapTable PF_GENERIC(NSString *, BFTask<PFPin *>*)*_pinCacheTable;
2121
dispatch_queue_t _pinCacheAccessQueue;
2222
BFExecutor *_pinCacheAccessExecutor;
2323
}
@@ -55,7 +55,7 @@ + (instancetype)storeWithDataSource:(id<PFOfflineStoreProvider>)dataSource {
5555
#pragma mark - Pin
5656
///--------------------------------------
5757

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

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

8787
@weakify(self);
88-
return [[[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
88+
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
8989
@strongify(self);
9090
PFPin *pin = task.result;
9191
PFOfflineStore *store = self.dataSource.offlineStore;
@@ -113,26 +113,26 @@ - (BFTask *)pinObjectsAsync:(NSArray *)objects withPinName:(NSString *)name incl
113113
saveTask = [store saveObjectLocallyAsync:pin withChildren:pin.objects];
114114
}
115115
return saveTask;
116-
}] continueWithSuccessResult:@YES];
116+
}];
117117
}
118118

119119
///--------------------------------------
120120
#pragma mark - Unpin
121121
///--------------------------------------
122122

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

128128
@weakify(self);
129-
return [[[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
129+
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
130130
@strongify(self);
131131
PFPin *pin = task.result;
132132
NSMutableArray *modified = pin.objects;
133133
if (!modified) {
134134
// Nothing to unpin
135-
return task;
135+
return nil;
136136
}
137137

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

150150
return [store saveObjectLocallyAsync:pin includeChildren:YES];
151-
}] continueWithSuccessResult:@YES];
151+
}];
152152
}
153153

154-
- (BFTask *)unpinAllObjectsAsyncWithPinName:(NSString *)name {
154+
- (BFTask PF_GENERIC(PFVoid)*)unpinAllObjectsAsyncWithPinName:(NSString *)name {
155155
@weakify(self);
156156
return [[self fetchPinAsyncWithName:name] continueWithSuccessBlock:^id(BFTask *task) {
157157
@strongify(self);
158-
PFPin *pin = task.result;
159-
return [[self.dataSource.offlineStore unpinObjectAsync:pin] continueWithSuccessResult:@YES];
158+
return [self.dataSource.offlineStore unpinObjectAsync:task.result];
160159
}];
161160
}
162161

Parse/PFObject.m

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,7 +2342,7 @@ - (void)forwardInvocation:(NSInvocation *)anInvocation {
23422342
#pragma mark - Pinning
23432343
///--------------------------------------
23442344

2345-
- (BFTask *)pinInBackground {
2345+
- (BFTask PF_GENERIC(NSNumber *)*)pinInBackground {
23462346
return [self pinInBackgroundWithName:PFObjectDefaultPin];
23472347
}
23482348

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

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

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

23652365
///--------------------------------------
23662366
#pragma mark - Pinning Many Objects
23672367
///--------------------------------------
23682368

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

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

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

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

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

23942394
///--------------------------------------
23952395
#pragma mark - Unpinning
23962396
///--------------------------------------
23972397

2398-
- (BFTask *)unpinInBackground {
2398+
- (BFTask PF_GENERIC(NSNumber *)*)unpinInBackground {
23992399
return [self unpinInBackgroundWithName:PFObjectDefaultPin];
24002400
}
24012401

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

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

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

2418-
+ (BFTask *)unpinAllObjectsInBackground {
2418+
+ (BFTask PF_GENERIC(NSNumber *)*)unpinAllObjectsInBackground {
24192419
return [self unpinAllObjectsInBackgroundWithName:PFObjectDefaultPin];
24202420
}
24212421

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

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

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

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

24462446
+ (void)unpinAllInBackground:(NSArray *)objects withName:(NSString *)name block:(PFBooleanResultBlock)block {

Tests/Unit/PinningObjectStoreTests.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ - (void)testPinObjects {
127127
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
128128
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
129129
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
130-
XCTAssertEqualObjects(task.result, @YES);
130+
XCTAssertNil(task.result);
131131
XCTAssertEqualObjects(pin.objects, @[ object ]);
132132
[expectation fulfill];
133133
return nil;
@@ -155,7 +155,7 @@ - (void)testPinObjectsExistingPin {
155155
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
156156
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
157157
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
158-
XCTAssertEqualObjects(task.result, @YES);
158+
XCTAssertNil(task.result);
159159
XCTAssertEqualObjects(pin.objects, (@[ existingObject, object ]));
160160
[expectation fulfill];
161161
return nil;
@@ -170,7 +170,7 @@ - (void)testPinZeroObjects {
170170

171171
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
172172
[[store pinObjectsAsync:nil withPinName:@"Yolo" includeChildren:YES] continueWithSuccessBlock:^id(BFTask *task) {
173-
XCTAssertEqualObjects(task.result, @YES);
173+
XCTAssertNil(task.result);
174174
[expectation fulfill];
175175
return nil;
176176
}];
@@ -195,7 +195,7 @@ - (void)testPinObjectsWithoutChildren {
195195
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
196196
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
197197
[[store pinObjectsAsync:@[ object ] withPinName:@"Yolo" includeChildren:NO] continueWithSuccessBlock:^id(BFTask *task) {
198-
XCTAssertEqualObjects(task.result, @YES);
198+
XCTAssertNil(task.result);
199199
XCTAssertEqualObjects(pin.objects, (@[ object ]));
200200
[expectation fulfill];
201201
return nil;
@@ -221,7 +221,7 @@ - (void)testUnpinObjects {
221221

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

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

261261
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
262262
[[store unpinObjectsAsync:nil withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
263-
XCTAssertEqualObjects(task.result, @YES);
263+
XCTAssertNil(task.result);
264264
[expectation fulfill];
265265
return nil;
266266
}];
@@ -278,7 +278,7 @@ - (void)testUnpinObjectsNoPin {
278278
PFObject *object = [PFObject objectWithClassName:@"Yarr"];
279279
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
280280
[[store unpinObjectsAsync:@[ object ] withPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
281-
XCTAssertEqualObjects(task.result, @YES);
281+
XCTAssertNil(task.result);
282282
[expectation fulfill];
283283
return nil;
284284
}];
@@ -300,7 +300,7 @@ - (void)testUnpinAllObjects {
300300

301301
XCTestExpectation *expectation = [self currentSelectorTestExpectation];
302302
[[store unpinAllObjectsAsyncWithPinName:@"Yolo"] continueWithSuccessBlock:^id(BFTask *task) {
303-
XCTAssertEqualObjects(task.result, @YES);
303+
XCTAssertNil(task.result);
304304
[expectation fulfill];
305305
return nil;
306306
}];

0 commit comments

Comments
 (0)