From 4f960e9fb43935502a89328a737b702b83b3c1a5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Fri, 4 Nov 2022 13:34:00 -0300 Subject: [PATCH] [FIX] Secured push notifications not fetching content on Android (#4487) --- .../reactnative/CustomPushNotification.java | 3 +- .../rocket/reactnative/LoadNotification.java | 28 ++++++++----------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java index e8090c3ae..2232517ca 100644 --- a/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java +++ b/android/app/src/play/java/chat/rocket/reactnative/CustomPushNotification.java @@ -354,6 +354,7 @@ public class CustomPushNotification extends PushNotification { } private void notificationLoad(Ejson ejson, Callback callback) { - LoadNotification.load(reactApplicationContext, ejson, callback); + LoadNotification loadNotification = new LoadNotification(); + loadNotification.load(reactApplicationContext, ejson, callback); } } diff --git a/android/app/src/play/java/chat/rocket/reactnative/LoadNotification.java b/android/app/src/play/java/chat/rocket/reactnative/LoadNotification.java index 6b6ad6beb..0e75534cb 100644 --- a/android/app/src/play/java/chat/rocket/reactnative/LoadNotification.java +++ b/android/app/src/play/java/chat/rocket/reactnative/LoadNotification.java @@ -1,20 +1,14 @@ package chat.rocket.reactnative; import android.os.Bundle; -import android.content.Context; - -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.HttpUrl; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.Interceptor; - -import com.google.gson.Gson; - -import java.io.IOException; import com.facebook.react.bridge.ReactApplicationContext; +import com.google.gson.Gson; + +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; class JsonResponse { Data data; @@ -49,11 +43,11 @@ class JsonResponse { } public class LoadNotification { - private static int RETRY_COUNT = 0; - private static int[] TIMEOUT = new int[]{0, 1, 3, 5, 10}; - private static String TOKEN_KEY = "reactnativemeteor_usertoken-"; + private int RETRY_COUNT = 0; + private int[] TIMEOUT = new int[]{0, 1, 3, 5, 10}; + private String TOKEN_KEY = "reactnativemeteor_usertoken-"; - public static void load(ReactApplicationContext reactApplicationContext, final Ejson ejson, Callback callback) { + public void load(ReactApplicationContext reactApplicationContext, final Ejson ejson, Callback callback) { final OkHttpClient client = new OkHttpClient(); HttpUrl.Builder url = HttpUrl.parse(ejson.serverURL().concat("/api/v1/push.get")).newBuilder(); @@ -73,7 +67,7 @@ public class LoadNotification { runRequest(client, request, callback); } - private static void runRequest(OkHttpClient client, Request request, Callback callback) { + private void runRequest(OkHttpClient client, Request request, Callback callback) { try { Thread.sleep(TIMEOUT[RETRY_COUNT] * 1000);