Skip to content
Merged
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 @@ -67,6 +67,7 @@ of this software and associated documentation files (the "Software"), to deal
import com.onesignal.user.subscriptions.IPushSubscription;
import com.onesignal.user.subscriptions.IPushSubscriptionObserver;
import com.onesignal.user.subscriptions.PushSubscriptionChangedState;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
Expand All @@ -82,8 +83,8 @@ public class RNOneSignal extends NativeOneSignalSpec
private boolean hasSetPushSubscriptionObserver = false;
private boolean hasSetUserStateObserver = false;

private final HashMap<String, INotificationWillDisplayEvent> notificationWillDisplayCache = new HashMap<>();
private final HashMap<String, INotificationWillDisplayEvent> preventDefaultCache = new HashMap<>();
private final Map<String, INotificationWillDisplayEvent> notificationWillDisplayCache =
Collections.synchronizedMap(new HashMap<>());

private boolean hasAddedNotificationForegroundListener = false;
private boolean hasAddedInAppMessageLifecycleListener = false;
Expand Down Expand Up @@ -214,7 +215,6 @@ public String getName() {
public void invalidate() {
removeObservers();
notificationWillDisplayCache.clear();
preventDefaultCache.clear();
if (currentInstance == this) {
currentInstance = null;
}
Expand Down Expand Up @@ -366,6 +366,7 @@ public void addNotificationForegroundLifecycleListener() {
public void onWillDisplay(INotificationWillDisplayEvent event) {
if (!this.hasAddedNotificationForegroundListener) {
event.getNotification().display();
return;
}

INotification notification = event.getNotification();
Expand All @@ -376,24 +377,14 @@ public void onWillDisplay(INotificationWillDisplayEvent event) {
try {
emitOnNotificationWillDisplay(
RNUtils.convertHashMapToWritableMap(RNUtils.convertNotificationToMap(notification)));

try {
synchronized (event) {
while (preventDefaultCache.containsKey(notificationId)) {
event.wait();
}
}
} catch (InterruptedException e) {
Logging.error("InterruptedException: " + e.toString(), null);
}
} catch (JSONException e) {
logJSONException("onNotificationWillDisplay", e);
}
}

@Override
public void displayNotification(String notificationId) {
INotificationWillDisplayEvent event = notificationWillDisplayCache.get(notificationId);
INotificationWillDisplayEvent event = notificationWillDisplayCache.remove(notificationId);
if (event == null) {
Logging.error(
"Could not find onWillDisplayNotification event for notification with id: " + notificationId, null);
Expand All @@ -411,7 +402,6 @@ public void preventDefault(String notificationId) {
return;
}
event.preventDefault();
this.preventDefaultCache.put(notificationId, event);
}

@Override
Expand Down
Loading