Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class MParticleModule(
},
)
} else {
callback.invoke()
callback.invoke(null, WritableNativeMap())
}
Comment on lines 181 to 183
Copy link

Copilot AI Mar 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are Android unit tests for other user methods, but this updated getUserAttributes behavior (always invoking the callback with (null, emptyMap) when the user is missing) isn’t covered. Add a test to assert the callback is invoked with two arguments and that the second argument is an empty map when selectedUser is null.

Copilot uses AI. Check for mistakes.
}

Expand Down
9 changes: 8 additions & 1 deletion ios/RNMParticle/RNMParticle.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ + (void)load {
{
MParticleUser *selectedUser = [[MParticleUser alloc] init];
selectedUser.userId = [NSNumber numberWithLong:mpid.longLongValue];
callback(@[[NSNull null], [selectedUser userAttributes]]);
NSDictionary *attributes = [selectedUser userAttributes] ?: @{};
NSMutableDictionary *sanitizedAttributes = [[NSMutableDictionary alloc] initWithCapacity:attributes.count];
[attributes enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
if (obj != nil && obj != [NSNull null]) {
sanitizedAttributes[key] = obj;
}
}];
callback(@[[NSNull null], sanitizedAttributes]);
}

RCT_EXPORT_METHOD(setUserTag:(NSString *)mpid tag:(NSString *)tag)
Expand Down
7 changes: 3 additions & 4 deletions js/codegenSpecs/NativeMParticle.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { TurboModule } from 'react-native';
import { TurboModuleRegistry } from 'react-native';
import type { UnsafeObject } from 'react-native/Libraries/Types/CodegenTypes';

export type CustomAttributes = { [key: string]: string | number | boolean };
export type UserAttributes = {
[key: string]: string | string[] | number | boolean | null;
};
export type UserAttributes = UnsafeObject;
export type UserIdentities = { [key: string]: string };

export interface Product {
Expand Down Expand Up @@ -153,7 +152,7 @@ export interface Spec extends TurboModule {
mpid: string,
callback: (
error: CallbackError | null,
result: UserAttributes | null
result: UserAttributes
) => void
): void;
setUserTag(mpid: string, tag: string): void;
Expand Down
Loading