Skip to content

Commit

Permalink
Pass now as parameter to update activity state
Browse files Browse the repository at this point in the history
  • Loading branch information
nonelse committed Apr 7, 2014
1 parent 6f674e1 commit eaa2175
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions Adjust/AIActivityHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ - (void)endInternal {

[self.packageHandler pauseSending];
[self stopTimer];
[self updateActivityState];
double now = [NSDate.date timeIntervalSince1970];
[self updateActivityState:now];
[self writeActivityState];
}

Expand All @@ -249,7 +250,7 @@ - (void)eventInternal:(NSString *)eventToken
eventBuilder.callbackParameters = parameters;

double now = [NSDate.date timeIntervalSince1970];
[self updateActivityState];
[self updateActivityState:now];
self.activityState.createdAt = now;
self.activityState.eventCount++;

Expand Down Expand Up @@ -289,7 +290,7 @@ - (void)revenueInternal:(double)amount
revenueBuilder.callbackParameters = parameters;

double now = [NSDate.date timeIntervalSince1970];
[self updateActivityState];
[self updateActivityState:now];
self.activityState.createdAt = now;
self.activityState.eventCount++;

Expand All @@ -311,10 +312,9 @@ - (void)revenueInternal:(double)amount
#pragma mark - private

// returns whether or not the activity state should be written
- (BOOL)updateActivityState {
- (BOOL)updateActivityState:(double)now {
if (![self checkActivityState:self.activityState]) return NO;

double now = [NSDate.date timeIntervalSince1970];
double lastInterval = now - self.activityState.lastActivity;
if (lastInterval < 0) {
[self.logger error:@"Time travel!"];
Expand Down Expand Up @@ -416,7 +416,8 @@ - (void)timerFired {
return;
}
[self.packageHandler sendFirstPackage];
if ([self updateActivityState]) {
double now = [NSDate.date timeIntervalSince1970];
if ([self updateActivityState:now]) {
[self writeActivityState];
}
}
Expand Down

0 comments on commit eaa2175

Please sign in to comment.