Skip to content

Commit

Permalink
Merge pull request #882 from OneSignal/user_model_beta2/privacy
Browse files Browse the repository at this point in the history
[User Model] Update Privacy Methods
  • Loading branch information
jennantilla authored Jun 2, 2023
2 parents 4cd20ae + 1071e13 commit 444e040
Show file tree
Hide file tree
Showing 15 changed files with 663 additions and 513 deletions.
111 changes: 62 additions & 49 deletions MIGRATION_GUIDE.md

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
</engines>

<js-module src="dist/NotificationReceivedEvent.js" name="NotificationReceivedEvent" />
<js-module src="dist/Subscription.js" name="Subscription" />
<js-module src="dist/OSNotification.js" name="OSNotification" />
<js-module src="dist/UserNamespace.js" name="UserNamespace" />
<js-module src="dist/PushSubscriptionNamespace.js" name="PushSubscriptionNamespace" />
Expand All @@ -38,7 +37,7 @@
<js-module src="dist/LiveActivitiesNamespace.js" name="LiveActivitiesNamespace" />

<platform name="android">
<framework src="com.onesignal:OneSignal:5.0.0-beta2" />
<framework src="com.onesignal:OneSignal:5.0.0-beta4" />
<framework src="build-extras-onesignal.gradle" custom="true" type="gradleReference" />
<framework src="org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10" />

Expand Down Expand Up @@ -85,7 +84,7 @@
<source url="https://cdn.cocoapods.org/"/>
</config>
<pods use-frameworks="true">
<pod name="OneSignalXCFramework" spec="5.0.0-beta-02" />
<pod name="OneSignalXCFramework" spec="5.0.0-beta-04" />
</pods>
</podspec>

Expand Down
20 changes: 4 additions & 16 deletions src/android/com/onesignal/cordova/OneSignalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,31 +277,19 @@ public static boolean setLaunchURLsInApp() {
/**
* Privacy consent
*/
public static boolean getRequiresPrivacyConsent(CallbackContext callbackContext) {
boolean requiresUserConsent = OneSignal.getRequiresPrivacyConsent();
CallbackHelper.callbackSuccessBoolean(callbackContext, requiresUserConsent);
return true;
}

public static boolean getPrivacyConsent(CallbackContext callbackContext) {
boolean getPrivacyConsent = OneSignal.getPrivacyConsent();
CallbackHelper.callbackSuccessBoolean(callbackContext, getPrivacyConsent);
return true;
}

public static boolean setRequiresPrivacyConsent(JSONArray data) {
public static boolean setPrivacyConsentRequired(JSONArray data) {
try {
OneSignal.setRequiresPrivacyConsent(data.getBoolean(0));
OneSignal.setConsentRequired(data.getBoolean(0));
return true;
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}

public static boolean setPrivacyConsent(JSONArray data) {
public static boolean setPrivacyConsentGiven(JSONArray data) {
try {
OneSignal.setPrivacyConsent(data.getBoolean(0));
OneSignal.setConsentGiven(data.getBoolean(0));
return true;
} catch (JSONException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ private static void callbackSuccess(CallbackContext callbackContext, JSONObject
public static boolean addTriggers(JSONArray data) {
try {
JSONObject triggersObject = data.getJSONObject(0);
Map<String, Object> triggers = new HashMap<>();
Map<String, String> triggers = new HashMap<>();
Iterator<String> keys = triggersObject.keys();

while (keys.hasNext()) {
String key = keys.next();
triggers.put(key, triggersObject.get(key));
triggers.put(key, (String) triggersObject.get(key));
}

OneSignal.getInAppMessages().addTriggers(triggers);
Expand Down
29 changes: 16 additions & 13 deletions src/android/com/onesignal/cordova/OneSignalObserverController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
import com.onesignal.OneSignal;
import com.onesignal.user.subscriptions.IPushSubscription;
import com.onesignal.user.subscriptions.ISubscription;
import com.onesignal.user.subscriptions.ISubscriptionChangedHandler;
import com.onesignal.notifications.IPermissionChangedHandler;
import com.onesignal.user.subscriptions.IPushSubscriptionObserver;
import com.onesignal.user.subscriptions.PushSubscriptionChangedState;
import com.onesignal.user.subscriptions.PushSubscriptionState;
import com.onesignal.notifications.IPermissionObserver;

public class OneSignalObserverController {
private static CallbackContext jsPermissionObserverCallBack;
private static CallbackContext jsSubscriptionObserverCallBack;

private static IPermissionChangedHandler permissionObserver;
private static ISubscriptionChangedHandler pushSubscriptionChangedHandler;
private static IPermissionObserver permissionObserver;
private static IPushSubscriptionObserver pushSubscriptionObserver;

// This is to prevent an issue where if two Javascript calls are made to OneSignal expecting a callback then only one would fire.
private static void callbackSuccess(CallbackContext callbackContext, JSONObject jsonObject) {
Expand All @@ -33,27 +35,28 @@ private static void callbackSuccess(CallbackContext callbackContext, JSONObject
public static boolean addPermissionObserver(CallbackContext callbackContext) {
jsPermissionObserverCallBack = callbackContext;
if (permissionObserver == null) {
permissionObserver = new IPermissionChangedHandler() {
permissionObserver = new IPermissionObserver() {
@Override
public void onPermissionChanged(boolean permission) {
public void onNotificationPermissionChange(boolean permission) {
CallbackHelper.callbackSuccessBoolean(jsPermissionObserverCallBack, permission);
}
};
OneSignal.getNotifications().addPermissionChangedHandler(permissionObserver);
OneSignal.getNotifications().addPermissionObserver(permissionObserver);
};
return true;
}

public static boolean addPushSubscriptionObserver(CallbackContext callbackContext) {
jsSubscriptionObserverCallBack = callbackContext;
if (pushSubscriptionChangedHandler == null) {
pushSubscriptionChangedHandler = new ISubscriptionChangedHandler() {
if (pushSubscriptionObserver == null) {
pushSubscriptionObserver = new IPushSubscriptionObserver() {
@Override
public void onSubscriptionChanged(ISubscription subscription) {
if (!(subscription instanceof IPushSubscription)){
public void onPushSubscriptionChange(PushSubscriptionChangedState state) {
PushSubscriptionState pushSubscription = state.getCurrent();

if (!(pushSubscription instanceof PushSubscriptionState)){
return;
}
IPushSubscription pushSubscription = (IPushSubscription) subscription;

try {
JSONObject pushSubscriptionProperties = new JSONObject();
Expand All @@ -68,7 +71,7 @@ public void onSubscriptionChanged(ISubscription subscription) {
}
}
};
OneSignal.getUser().getPushSubscription().addChangeHandler(pushSubscriptionChangedHandler);
OneSignal.getUser().getPushSubscription().addObserver(pushSubscriptionObserver);
}
return true;
}
Expand Down
Loading

0 comments on commit 444e040

Please sign in to comment.