Skip to content

Commit

Permalink
Skipping attribute filters for events with no attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dalmo Cirne committed Oct 29, 2015
1 parent b304cef commit bb4159a
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions Pod/Classes/Kits/MPKitContainer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -586,36 +586,33 @@ - (void)filterKit:(MPKitAbstract *)kit forEvent:(MPEvent *const)event selector:(
}

// Attributes
if (!event.info) {
kitFilter = [[MPKitFilter alloc] initWithEvent:event shouldFilter:NO];
completionHandlerCopy(kitFilter, YES);
return;
}

MPMessageType messageTypeCode = (MPMessageType)mParticle::MessageTypeName::messageTypeForName(string([messageType UTF8String]));
if (messageTypeCode != MPMessageTypeEvent && messageTypeCode != MPMessageTypeScreenView) {
messageTypeCode = MPMessageTypeUnknown;
}

MPEvent *forwardEvent = [event copy];
__block NSMutableDictionary *filteredAttributes = [[NSMutableDictionary alloc] initWithCapacity:forwardEvent.info.count];

[forwardEvent.info enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
auxString = [NSString stringWithFormat:@"%@%@%@", eventTypeString, event.name, key];
hashValue = [NSString stringWithCString:mParticle::Hasher::hashString([auxString cStringUsingEncoding:NSUTF8StringEncoding]).c_str()
encoding:NSUTF8StringEncoding];
if (event.info) {
__block NSMutableDictionary *filteredAttributes = [[NSMutableDictionary alloc] initWithCapacity:forwardEvent.info.count];

id attributeFilterValue = attributeFilters[hashValue];
BOOL attributeFilterIsFalse = [attributeFilterValue isEqualToNumber:zero];
[forwardEvent.info enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) {
auxString = [NSString stringWithFormat:@"%@%@%@", eventTypeString, event.name, key];
hashValue = [NSString stringWithCString:mParticle::Hasher::hashString([auxString cStringUsingEncoding:NSUTF8StringEncoding]).c_str()
encoding:NSUTF8StringEncoding];

id attributeFilterValue = attributeFilters[hashValue];
BOOL attributeFilterIsFalse = [attributeFilterValue isEqualToNumber:zero];

if (!attributeFilterValue || (attributeFilterValue && !attributeFilterIsFalse)) {
filteredAttributes[key] = obj;
} else if (attributeFilterValue && attributeFilterIsFalse) {
shouldFilter = YES;
}
}];

if (!attributeFilterValue || (attributeFilterValue && !attributeFilterIsFalse)) {
filteredAttributes[key] = obj;
} else if (attributeFilterValue && attributeFilterIsFalse) {
shouldFilter = YES;
}
}];

forwardEvent.info = filteredAttributes.count > 0 ? filteredAttributes : nil;
forwardEvent.info = filteredAttributes.count > 0 ? filteredAttributes : nil;
}

[self projectKit:kit
event:forwardEvent
Expand Down

0 comments on commit bb4159a

Please sign in to comment.