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 all 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
24 changes: 22 additions & 2 deletions 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,19 @@
export function addTag(key: string, value: string) {
if (!isNativeModuleLoaded(RNOneSignal)) return;

if (!key || (!value && value !== '')) {
console.error('OneSignal: sendTag: must include a key and a value');
if (!key || value === undefined || value === null) {
console.error('OneSignal: addTag: must include a key and a value');
return;
}

// forces values to be string types
if (typeof value !== 'string') {
console.warn(
'OneSignal: addTag: tag value must be of type string; attempting to convert',
);
value = String(value);
}

RNOneSignal.addTag(key, value);
}

Expand All @@ -456,6 +464,18 @@
return;
}

const convertedTags = tags as { [key: string]: any };
Object.keys(tags).forEach(function (key) {
if (typeof convertedTags[key] !== 'string') {
console.warn(
'OneSignal: addTags: tag value for key ' +
key +
' must be of type string; attempting to convert',
);
convertedTags[key] = String(convertedTags[key]);
}
});

RNOneSignal.addTags(tags);
}

Expand Down