-
Notifications
You must be signed in to change notification settings - Fork 371
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Changing outcome callbacks and removing cache settings * Cache settings was removed as a decision to prevent users from turning off cache (will need to find a good way to clean cached notifications/outcomes in future though) * Changed callback functionality so there is no failure now (failure could give users the ability to reattempt sending an outcome which we do already through caching and new init) * Fixed example app text view for debugging * Also cleaned unique notification id for-loops so only one is needed * Previously changed/removed getParams * Added getParams back and make sure it returns a String * Added new outcome callback and cache cleaning * Outcome callback should just return the entire OutcomeEvent instead of a name * Also removed the failure and only allow success since we don't want people reattempting sending unique outcomes when they will be reattempted by us anyway (could result in duplicate outcome events failling and being sent later) * Added SQL caching for the unique outcome events with notifications (ATTRIBUTED) and cleaning so they are wiped away when the cached notifications are wiped away * Added SharedPrefs caching for UNATTRIBUTED unique outcome events that simply wipe and start over on enw sessions only * Outcome event clean up (#873) * Outcome event clean up * Removed OutcomeParams class and instead only use a float weight * Fixed all tests that broke after removing OutcomeParams * Cleaned up requests in OutcomeEventsRepository so now there is only 1 of each session (DIRECT, INDIRECT, UNATTRIBUTED) * Reordered expected outcome unit tests because of outcome event changes to JSON creation * Added checking in two places for weight of 0 being sent with an OutcomeEvent, one is when we call the public method (logs an error) and the other is in the toJSON of the OutcomeEvent preventing a weight of 0 from being added into the JSON * Minor clean up after PR * Change equals check on weight to Float in OutcomeEvent equals override * Add '||' check for valid outcome name and value instead of '&&' * Updated example app for new outcomes callback logic * Made CachedUniqueOutcomeNotification package-private * Fixed all unit tests by adding CachedUniqueOutcomeNotification to OneSignalPackagePrivateHelper * Made OutcomeEvent toJsonObject public for access in wrappers * Removed TODO for clean up in OutcomeEventsRepository
- Loading branch information
Showing
25 changed files
with
615 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
OneSignalSDK/onesignal/src/main/java/com/onesignal/CachedUniqueOutcomeNotification.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.onesignal; | ||
|
||
class CachedUniqueOutcomeNotification { | ||
|
||
private String notificationId; | ||
private String name; | ||
|
||
CachedUniqueOutcomeNotification(String notificationId, String name) { | ||
this.notificationId = notificationId; | ||
this.name = name; | ||
} | ||
|
||
String getNotificationId() { | ||
return notificationId; | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
OneSignalSDK/onesignal/src/main/java/com/onesignal/OneSignalCacheCleaner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.onesignal; | ||
|
||
import com.onesignal.OneSignalDbContract.NotificationTable; | ||
import com.onesignal.OneSignalDbContract.CachedUniqueOutcomeNotificationTable; | ||
|
||
import android.content.Context; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.os.Process; | ||
|
||
class OneSignalCacheCleaner { | ||
|
||
private static String OS_DELETE_OLD_CACHED_DATA = "OS_DELETE_OLD_CACHED_DATA"; | ||
|
||
/** | ||
* We clean outdated cache from several places within the OneSignal SDK here | ||
* 1. In App Messaging id sets (impressions, clicks, views) | ||
* 2. Notifications after 1 week | ||
* 3. Unique outcome events linked to notification ids (1 week) | ||
*/ | ||
synchronized static void cleanOldCachedData(final Context context) { | ||
new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
Thread.currentThread().setPriority(Process.THREAD_PRIORITY_BACKGROUND); | ||
OneSignalDbHelper dbHelper = OneSignalDbHelper.getInstance(context); | ||
SQLiteDatabase writableDb = dbHelper.getWritableDbWithRetries(); | ||
|
||
cleanInAppMessagingCache(); | ||
cleanNotificationCache(writableDb); | ||
} | ||
}, OS_DELETE_OLD_CACHED_DATA).start(); | ||
} | ||
|
||
/** | ||
* TODO: Needs to be implemented to clean out old IAM data used to track impressions, clicks, and viewed IAMs | ||
*/ | ||
static void cleanInAppMessagingCache() { | ||
// NOTE: Currently IAMs will pile up overtime and since IAMs can be modified, active, inactive, etc. | ||
// we never truly know when it is the correct time to remove these ids form our cache | ||
} | ||
|
||
/** | ||
* Cleans two notification tables | ||
* 1. NotificationTable.TABLE_NAME | ||
* 2. CachedUniqueOutcomeNotificationTable.TABLE_NAME | ||
*/ | ||
static void cleanNotificationCache(SQLiteDatabase writableDb) { | ||
cleanOldNotificationData(writableDb); | ||
cleanOldUniqueOutcomeEventNotificationsCache(writableDb); | ||
} | ||
|
||
/** | ||
* Deletes any notifications with created timestamps older than 7 days | ||
*/ | ||
private static void cleanOldNotificationData(SQLiteDatabase writableDb) { | ||
writableDb.delete(NotificationTable.TABLE_NAME, | ||
NotificationTable.COLUMN_NAME_CREATED_TIME + " < " + ((System.currentTimeMillis() / 1_000L) - 604_800L), | ||
null); | ||
} | ||
|
||
/** | ||
* Deletes any notifications whose ids do not exist inside of the NotificationTable.TABLE_NAME | ||
*/ | ||
static void cleanOldUniqueOutcomeEventNotificationsCache(SQLiteDatabase writableDb) { | ||
writableDb.delete(CachedUniqueOutcomeNotificationTable.TABLE_NAME, | ||
"NOT EXISTS(SELECT NULL FROM " + NotificationTable.TABLE_NAME + | ||
" n WHERE" + | ||
" n." + NotificationTable.COLUMN_NAME_NOTIFICATION_ID + " = " + CachedUniqueOutcomeNotificationTable.COLUMN_NAME_NOTIFICATION_ID + ")", | ||
null); | ||
} | ||
|
||
} |
Oops, something went wrong.