[IMPROVEMENT] Use parsed EJSON info on load notification (#2370)

This commit is contained in:
Djorkaeff Alexandre 2020-08-04 17:39:39 -03:00 committed by GitHub
parent dae058cdb4
commit 0f0e2c7b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 13 deletions

View File

@ -62,7 +62,7 @@ public class CustomPushNotification extends PushNotification {
Ejson receivedEjson = new Gson().fromJson(received.getString("ejson", "{}"), Ejson.class); Ejson receivedEjson = new Gson().fromJson(received.getString("ejson", "{}"), Ejson.class);
if (receivedEjson.notificationType != null && receivedEjson.notificationType.equals("message-id-only")) { if (receivedEjson.notificationType != null && receivedEjson.notificationType.equals("message-id-only")) {
notificationLoad(receivedEjson.serverURL(), receivedEjson.messageId, new Callback() { notificationLoad(receivedEjson, new Callback() {
@Override @Override
public void call(@Nullable Bundle bundle) { public void call(@Nullable Bundle bundle) {
if (bundle != null) { if (bundle != null) {
@ -340,7 +340,7 @@ public class CustomPushNotification extends PushNotification {
notification.setDeleteIntent(dismissPendingIntent); notification.setDeleteIntent(dismissPendingIntent);
} }
private void notificationLoad(String server, String messageId, Callback callback) { private void notificationLoad(Ejson ejson, Callback callback) {
LoadNotification.load(reactApplicationContext, server, messageId, callback); LoadNotification.load(reactApplicationContext, ejson, callback);
} }
} }

View File

@ -2,7 +2,6 @@ package chat.rocket.reactnative;
import android.os.Bundle; import android.os.Bundle;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences;
import okhttp3.Call; import okhttp3.Call;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
@ -54,19 +53,15 @@ public class LoadNotification {
private static int RETRY_COUNT = 0; private static int RETRY_COUNT = 0;
private static int[] TIMEOUT = new int[]{ 0, 1, 3, 5, 10 }; private static int[] TIMEOUT = new int[]{ 0, 1, 3, 5, 10 };
private static String TOKEN_KEY = "reactnativemeteor_usertoken-"; 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(); final OkHttpClient client = new OkHttpClient();
HttpUrl.Builder url = HttpUrl.parse(host.concat("/api/v1/push.get")).newBuilder(); HttpUrl.Builder url = HttpUrl.parse(ejson.serverURL().concat("/api/v1/push.get")).newBuilder();
String userId = sharedPreferences.getString(TOKEN_KEY.concat(host), "");
String token = sharedPreferences.getString(TOKEN_KEY.concat(userId), "");
Request request = new Request.Builder() Request request = new Request.Builder()
.header("x-user-id", userId) .header("x-user-id", ejson.userId())
.header("x-auth-token", token) .header("x-auth-token", ejson.token())
.url(url.addQueryParameter("id", msgId).build()) .url(url.addQueryParameter("id", ejson.messageId).build())
.build(); .build();
runRequest(client, request, callback); runRequest(client, request, callback);