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

SDK 4133 - Dedupe check for notifications #694

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public class AnalyticsManager extends BaseAnalyticsManager {

private final InAppResponse inAppResponse;

private final HashMap<String, Object> notificationIdTagMap = new HashMap<>();
private final HashMap<String, Long> notificationIdTagMap = new HashMap<>();

private final Object notificationMapLock = new Object();

private final HashMap<String, Object> notificationViewedIdTagMap = new HashMap<>();
private final HashMap<String, Long> notificationViewedIdTagMap = new HashMap<>();

AnalyticsManager(Context context,
CleverTapInstanceConfig config,
Expand Down Expand Up @@ -1162,18 +1162,41 @@ private void _pushMultiValue(ArrayList<String> originalValues, String key, Strin
}
}

private boolean checkDuplicateNotificationIds(Bundle extras, HashMap<String, Object> notificationTagMap,
int interval) {
private boolean checkDuplicateNotificationIds(
Bundle extras,
HashMap<String, Long> notificationTagMap,
int interval
) {
synchronized (notificationMapLock) {
// default to false; only return true if we are sure we've seen this one before
boolean isDupe = false;
try {
String notificationIdTag = extras.getString(Constants.NOTIFICATION_ID_TAG);

// This flag is used so that we can release in phased manner, eventually the check has to go away.
Object doDedupeCheck = extras.get(Constants.WZRK_DEDUPE);

boolean check = false;
if (doDedupeCheck != null) {
if (doDedupeCheck instanceof String) {
check = "true".equalsIgnoreCase((String) doDedupeCheck);
}
if (doDedupeCheck instanceof Boolean) {
check = (Boolean) doDedupeCheck;
}
}

String notificationIdTag;
if (check) {
notificationIdTag = extras.getString(Constants.WZRK_PUSH_ID);
} else {
notificationIdTag = extras.getString(Constants.NOTIFICATION_ID_TAG);
}

long now = System.currentTimeMillis();
if (notificationTagMap.containsKey(notificationIdTag)) {
long timestamp;
// noinspection ConstantConditions
timestamp = (Long) notificationTagMap.get(notificationIdTag);
timestamp = notificationTagMap.get(notificationIdTag);
// same notificationId within time internal treat as dupe
if (now - timestamp < interval) {
isDupe = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public interface Constants {
String KEY_ENCRYPTION_LEVEL = "encryptionLevel";
String KEY_ENCRYPTION_FLAG_STATUS = "encryptionFlagStatus";
String WZRK_PUSH_ID = "wzrk_pid";
String WZRK_DEDUPE = "wzrk_dd";
String WZRK_PUSH_SILENT = "wzrk_pn_s";
String EXTRAS_FROM = "extras_from";
String NOTIF_MSG = "nm";
Expand Down
Loading