From 27f21b9274fee6f80da6f25b3b73d4491e4f9925 Mon Sep 17 00:00:00 2001 From: Abhishek Pandey <64667840+1abhishekpandey@users.noreply.github.com> Date: Tue, 19 Mar 2024 13:12:14 +0530 Subject: [PATCH] feat: add support for global customContext option (#485) * chore: remove lingering reference to deleted RudderConfig file * fix: logic to merge the externalId in identify call * chore: refactor code * feat: add global option support for customContext * feat: when reset is called then clear the globalOptions customContext field * chore: create a mutable copy of customContexts while merging * Revert "chore: refactor code" This reverts commit 4773a05b59ed38cc688ad2b51d5dafef29955850. * Revert "fix: logic to merge the externalId in identify call" This reverts commit 9e22dbb4c4fb310f55833f04d924aead88788617. * Revert "chore: remove lingering reference to deleted RudderConfig file" This reverts commit fd8bf6b899c75b067d6a5837f2427b13b16549d3. --- Sources/Classes/RSEventRepository.m | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Sources/Classes/RSEventRepository.m b/Sources/Classes/RSEventRepository.m index 27dfa287..296d0fd9 100644 --- a/Sources/Classes/RSEventRepository.m +++ b/Sources/Classes/RSEventRepository.m @@ -268,6 +268,19 @@ - (void)applyIntegrations:(RSMessage *)message withDefaultOption:(RSOption *)def [mutableIntegrations setObject:@YES forKey:@"All"]; message.integrations = mutableIntegrations; } + + // Merge local customContext (message.customContexts) with global customContext (defaultOption.customContexts) giving preference to local one. + if (defaultOption) { + NSMutableDictionary*>* mergedCustomContextValues = [NSMutableDictionary dictionaryWithDictionary:[message.customContexts mutableCopy]]; + + for (NSString* key in defaultOption.customContexts) { + if (!mergedCustomContextValues[key]) { + mergedCustomContextValues[key] = [defaultOption.customContexts[key] mutableCopy]; + } + } + + message.customContexts = mergedCustomContextValues; + } } - (RSMessage *)applyConsents:(RSMessage *)message { @@ -287,6 +300,11 @@ - (void)applySession:(RSMessage *)message withUserSession:(RSUserSession *)_user } -(void) reset { + if (self->defaultOptions != nil && self->defaultOptions.customContexts != nil) { + // Since the reset operation is intended to reset user-level fields, we clear the globalOptions->customContext field. + // The globalOptions->integrations field is a workspace-level setting and should not be cleared. + [self->defaultOptions.customContexts removeAllObjects]; + } if([self->userSession getSessionId] != nil) { [RSLogger logDebug: @"EventRepository: reset: Refreshing the session as the reset is triggered"]; [self->userSession refreshSession];