Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tag type fix #1696

Merged
merged 6 commits into from May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ios/RCTOneSignal/RCTOneSignalEventEmitter.m
Expand Up @@ -352,7 +352,7 @@ + (void)sendEventWithName:(NSString *)name withBody:(NSDictionary *)body {
[OneSignal.User removeSms:smsNumber];
}

RCT_EXPORT_METHOD(addTag:(NSString *)key value:(NSString*)value) {
RCT_EXPORT_METHOD(addTag:(NSString *)key value:(id)value) {
[OneSignal.User addTagWithKey:key value:value];
}

Expand Down
15 changes: 14 additions & 1 deletion src/index.ts
Expand Up @@ -195,7 +195,7 @@
export namespace User {
export namespace pushSubscription {
/** Add a callback that fires when the OneSignal subscription state changes. */
export function addEventListener(

Check warning on line 198 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'addEventListener' is already declared in the upper scope on line 320 column 21
event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
Expand All @@ -210,7 +210,7 @@
}

/** Clears current subscription observers. */
export function removeEventListener(

Check warning on line 213 in src/index.ts

View workflow job for this annotation

GitHub Actions / build

'removeEventListener' is already declared in the upper scope on line 335 column 21
event: 'change',
listener: (event: PushSubscriptionChangedState) => void,
) {
Expand Down Expand Up @@ -433,11 +433,16 @@
export function addTag(key: string, value: string) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

if (!key || (!value && value !== '')) {
if (!key || !value) {
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
console.error('OneSignal: sendTag: must include a key and a value');
return;
}

// forces values to be string types
if (typeof value !== 'string') {
value = String(value);
}

RNOneSignal.addTag(key, value);
}

Expand All @@ -456,6 +461,14 @@
return;
}

const convertedTags = tags as { [key: string]: any };
Object.keys(tags).forEach(function (key) {
// forces values to be string types
if (typeof convertedTags[key] !== 'string') {
convertedTags[key] = JSON.stringify(convertedTags[key]);
jennantilla marked this conversation as resolved.
Show resolved Hide resolved
}
});

RNOneSignal.addTags(tags);
}

Expand Down