Skip to content

Commit 44361df

Browse files
committed
SDK-777 don't retry event's with callbacks
1 parent c6b75d5 commit 44361df

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

Branch-SDK/Branch-SDK/BNCCallbackMap.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ NS_ASSUME_NONNULL_BEGIN
1717

1818
- (void)storeRequest:(BNCServerRequest *)request withCompletion:(void (^_Nullable)(NSString *statusMessage))completion;
1919

20+
- (BOOL)containsRequest:(BNCServerRequest *)request;
21+
2022
- (void)callCompletionForRequest:(BNCServerRequest *)request withStatusMessage:(NSString *)statusMessage;
2123

2224
@end

Branch-SDK/Branch-SDK/BNCCallbackMap.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ - (void)storeRequest:(BNCServerRequest *)request withCompletion:(void (^_Nullabl
3939
[self.callbacks setObject:completion forKey:request];
4040
}
4141

42+
- (BOOL)containsRequest:(BNCServerRequest *)request {
43+
BOOL contains = NO;
44+
if ([self.callbacks objectForKey:request] != nil) {
45+
contains = YES;
46+
}
47+
return contains;
48+
}
49+
4250
- (void)callCompletionForRequest:(BNCServerRequest *)request withStatusMessage:(NSString *)statusMessage {
4351
void (^completion)(NSString *) = [self.callbacks objectForKey:request];
4452
if (completion) {

Branch-SDK/Branch-SDK/Branch.m

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,16 +1905,8 @@ - (void) processRequest:(BNCServerRequest*)req
19051905
// Next, remove all the requests that should not be replayed. Note, we do this before
19061906
// calling callbacks, in case any of the callbacks try to kick off another request, which
19071907
// could potentially start another request (and call these callbacks again)
1908-
1909-
NSSet<Class> *replayableRequests = [[NSSet alloc] initWithArray:@[
1910-
BranchEventRequest.class,
1911-
BranchUserCompletedActionRequest.class,
1912-
BranchSetIdentityRequest.class,
1913-
BranchCommerceEventRequest.class,
1914-
]];
1915-
19161908
for (BNCServerRequest *request in requestsToFail) {
1917-
if (Branch.trackingDisabled || ![replayableRequests containsObject:request.class]) {
1909+
if (Branch.trackingDisabled || ![self isReplayableRequest:request]) {
19181910
[self.requestQueue remove:request];
19191911
}
19201912
}
@@ -1927,6 +1919,7 @@ - (void) processRequest:(BNCServerRequest*)req
19271919
BNCPerformBlockOnMainThreadSync(^ {
19281920
[request processResponse:nil error:error];
19291921

1922+
// BranchEventRequests can have callbacks directly tied to them.
19301923
if ([request isKindOfClass:[BranchEventRequest class]]) {
19311924
[[BNCCallbackMap shared] callCompletionForRequest:req withStatusMessage:[NSString stringWithFormat:@"Error: %@", error.description]];
19321925
}
@@ -1935,6 +1928,29 @@ - (void) processRequest:(BNCServerRequest*)req
19351928
}
19361929
}
19371930

1931+
- (BOOL)isReplayableRequest:(BNCServerRequest *)request {
1932+
1933+
// These request types
1934+
NSSet<Class> *replayableRequests = [[NSSet alloc] initWithArray:@[
1935+
BranchEventRequest.class,
1936+
BranchUserCompletedActionRequest.class,
1937+
BranchSetIdentityRequest.class,
1938+
BranchCommerceEventRequest.class,
1939+
]];
1940+
1941+
if ([replayableRequests containsObject:request.class]) {
1942+
1943+
// Check if the client registered a callback for this request.
1944+
// This indicates the client will handle retry themselves, so fail it.
1945+
if ([[BNCCallbackMap shared] containsRequest:request]) {
1946+
return NO;
1947+
} else {
1948+
return YES;
1949+
}
1950+
}
1951+
return NO;
1952+
}
1953+
19381954
- (void)processNextQueueItem {
19391955
dispatch_semaphore_wait(self.processing_sema, DISPATCH_TIME_FOREVER);
19401956

0 commit comments

Comments
 (0)