From 0f0e2c7b5f0869ab934d3e0e4d92e2d363cbd12b Mon Sep 17 00:00:00 2001 From: Djorkaeff Alexandre Date: Tue, 4 Aug 2020 17:39:39 -0300 Subject: [PATCH] [IMPROVEMENT] Use parsed EJSON info on load notification (#2370) --- .../reactnative/CustomPushNotification.java | 6 +++--- .../chat/rocket/reactnative/LoadNotification.java | 15 +++++---------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java b/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java index 401314d7..46c086ea 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java +++ b/android/app/src/main/java/chat/rocket/reactnative/CustomPushNotification.java @@ -62,7 +62,7 @@ public class CustomPushNotification extends PushNotification { Ejson receivedEjson = new Gson().fromJson(received.getString("ejson", "{}"), Ejson.class); if (receivedEjson.notificationType != null && receivedEjson.notificationType.equals("message-id-only")) { - notificationLoad(receivedEjson.serverURL(), receivedEjson.messageId, new Callback() { + notificationLoad(receivedEjson, new Callback() { @Override public void call(@Nullable Bundle bundle) { if (bundle != null) { @@ -340,7 +340,7 @@ public class CustomPushNotification extends PushNotification { notification.setDeleteIntent(dismissPendingIntent); } - private void notificationLoad(String server, String messageId, Callback callback) { - LoadNotification.load(reactApplicationContext, server, messageId, callback); + private void notificationLoad(Ejson ejson, Callback callback) { + LoadNotification.load(reactApplicationContext, ejson, callback); } } diff --git a/android/app/src/main/java/chat/rocket/reactnative/LoadNotification.java b/android/app/src/main/java/chat/rocket/reactnative/LoadNotification.java index e7e2ad43..9c4c0374 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/LoadNotification.java +++ b/android/app/src/main/java/chat/rocket/reactnative/LoadNotification.java @@ -2,7 +2,6 @@ package chat.rocket.reactnative; import android.os.Bundle; import android.content.Context; -import android.content.SharedPreferences; import okhttp3.Call; import okhttp3.OkHttpClient; @@ -54,19 +53,15 @@ 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 static SharedPreferences sharedPreferences = RNUserDefaultsModule.getPreferences(CustomPushNotification.reactApplicationContext); - public static void load(ReactApplicationContext reactApplicationContext, final String host, final String msgId, Callback callback) { + public static void load(ReactApplicationContext reactApplicationContext, final Ejson ejson, Callback callback) { final OkHttpClient client = new OkHttpClient(); - HttpUrl.Builder url = HttpUrl.parse(host.concat("/api/v1/push.get")).newBuilder(); - - String userId = sharedPreferences.getString(TOKEN_KEY.concat(host), ""); - String token = sharedPreferences.getString(TOKEN_KEY.concat(userId), ""); + HttpUrl.Builder url = HttpUrl.parse(ejson.serverURL().concat("/api/v1/push.get")).newBuilder(); Request request = new Request.Builder() - .header("x-user-id", userId) - .header("x-auth-token", token) - .url(url.addQueryParameter("id", msgId).build()) + .header("x-user-id", ejson.userId()) + .header("x-auth-token", ejson.token()) + .url(url.addQueryParameter("id", ejson.messageId).build()) .build(); runRequest(client, request, callback);