Skip to content

Commit

Permalink
Merge pull request #105 from OneSignal/cd_update
Browse files Browse the repository at this point in the history
Generator Update
  • Loading branch information
rgomezp authored Mar 31, 2023
2 parents e931e92 + d199ad0 commit a6e4c54
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 33 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let isOneSignalInitialized = false;
// OneSignal#init.
let isOneSignalScriptFailed = false;

window.OneSignalDeferred = window.OneSignalDeferred || [];
window.OneSignalDeferred = window?.OneSignalDeferred || [];

addSDKScript();

Expand Down Expand Up @@ -190,6 +190,10 @@ interface IOneSignalUser {
removeEmail(email: string): void;
addSms(smsNumber: string): void;
removeSms(smsNumber: string): void;
addTag(key: string, value: string): void;
addTags(tags: { [key: string]: string }): void;
removeTag(key: string): void;
removeTags(keys: string[]): void;
}
interface IOneSignalPushSubscription {
id: string | null | undefined;
Expand Down Expand Up @@ -551,6 +555,30 @@ function userRemoveSms(smsNumber: string): void {
});
}

function userAddTag(key: string, value: string): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.User.addTag(key, value)
});
}

function userAddTags(tags: { [key: string]: string }): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.User.addTags(tags)
});
}

function userRemoveTag(key: string): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.User.removeTag(key)
});
}

function userRemoveTags(keys: string[]): void {
window.OneSignalDeferred?.push((OneSignal: IOneSignalOneSignal) => {
OneSignal.User.removeTags(keys)
});
}

function pushSubscriptionOptIn(): Promise<void> {
return new Promise((resolve, reject) => {
if (isOneSignalScriptFailed) {
Expand Down Expand Up @@ -623,6 +651,10 @@ const UserNamespace: IOneSignalUser = {
removeEmail: userRemoveEmail,
addSms: userAddSms,
removeSms: userRemoveSms,
addTag: userAddTag,
addTags: userAddTags,
removeTag: userRemoveTag,
removeTags: userRemoveTags,
PushSubscription: PushSubscriptionNamespace,
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-onesignal",
"version": "3.0.0-beta.2",
"version": "3.0.0-beta.3",
"description": "React OneSignal Module: Make it easy to integrate OneSignal with your React App!",
"author": "rgomezp",
"contributors": [{ "name": "Rodrigo Gomez-Palacio" }, { "name": "Pedro Bini" }, { "name": "Graham Marlow" }],
Expand Down

0 comments on commit a6e4c54

Please sign in to comment.