Commit c822c8df authored by Yusuke Iwaki's avatar Yusuke Iwaki

Revert "remove push interactor."

This reverts commit 4d709b6e.
parent 3f49c4ed
...@@ -20,6 +20,7 @@ import android.support.v4.util.SparseArrayCompat; ...@@ -20,6 +20,7 @@ import android.support.v4.util.SparseArrayCompat;
import android.text.Html; import android.text.Html;
import android.text.Spanned; import android.text.Spanned;
import android.util.Log; import android.util.Log;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -31,9 +32,7 @@ import java.net.URL; ...@@ -31,9 +32,7 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Random; import java.util.Random;
import chat.rocket.android.activity.MainActivity; import chat.rocket.android.activity.MainActivity;
import chat.rocket.android.helper.ServerPolicyHelper; import chat.rocket.android.push.interactors.PushInteractor;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.realm_helper.RealmStore;
public class PushNotificationHandler implements PushConstants { public class PushNotificationHandler implements PushConstants {
...@@ -57,7 +56,8 @@ public class PushNotificationHandler implements PushConstants { ...@@ -57,7 +56,8 @@ public class PushNotificationHandler implements PushConstants {
} }
} }
public void showNotificationIfPossible(Context context, Bundle extras) { public void showNotificationIfPossible(Context context, PushInteractor pushInteractor,
Bundle extras) {
// Send a notification if there is a message or title, otherwise just send data // Send a notification if there is a message or title, otherwise just send data
String message = extras.getString(MESSAGE); String message = extras.getString(MESSAGE);
...@@ -79,11 +79,11 @@ public class PushNotificationHandler implements PushConstants { ...@@ -79,11 +79,11 @@ public class PushNotificationHandler implements PushConstants {
extras.putString(TITLE, getAppName(context)); extras.putString(TITLE, getAppName(context));
} }
createNotification(context, extras); createNotification(context, pushInteractor, extras);
} }
} }
public void createNotification(Context context, Bundle extras) { public void createNotification(Context context, PushInteractor pushInteractor, Bundle extras) {
NotificationManager mNotificationManager = NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(context); String appName = getAppName(context);
...@@ -97,11 +97,8 @@ public class PushNotificationHandler implements PushConstants { ...@@ -97,11 +97,8 @@ public class PushNotificationHandler implements PushConstants {
return; return;
} }
ServerConfig serverConfig = RealmStore.getDefault().executeTransactionForRead(realm -> String serverConfigId = pushInteractor.getServerConfigId(serverUrl);
realm.where(ServerConfig.class) if (serverConfigId == null) {
.equalTo(ServerConfig.HOSTNAME, ServerPolicyHelper.enforceHostname(serverUrl))
.findFirst());
if (serverConfig == null) {
return; return;
} }
...@@ -109,7 +106,7 @@ public class PushNotificationHandler implements PushConstants { ...@@ -109,7 +106,7 @@ public class PushNotificationHandler implements PushConstants {
Intent notificationIntent = new Intent(context, MainActivity.class); Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra(PUSH_BUNDLE, extras); notificationIntent.putExtra(PUSH_BUNDLE, extras);
notificationIntent.putExtra(SERVER_CONFIG_ID, serverConfig.getServerConfigId()); notificationIntent.putExtra(SERVER_CONFIG_ID, serverConfigId);
notificationIntent.putExtra(ROOM_ID, roomId); notificationIntent.putExtra(ROOM_ID, roomId);
notificationIntent.putExtra(NOT_ID, notId); notificationIntent.putExtra(NOT_ID, notId);
......
...@@ -2,6 +2,7 @@ package chat.rocket.android.push.gcm; ...@@ -2,6 +2,7 @@ package chat.rocket.android.push.gcm;
import com.google.android.gms.gcm.GcmListenerService; import com.google.android.gms.gcm.GcmListenerService;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
...@@ -14,7 +15,10 @@ import java.util.ArrayList; ...@@ -14,7 +15,10 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import chat.rocket.android.push.PushConstants; import chat.rocket.android.push.PushConstants;
import chat.rocket.android.push.PushNotificationHandler; import chat.rocket.android.push.PushNotificationHandler;
import chat.rocket.android.push.interactors.DefaultPushInteractor;
import chat.rocket.android.push.interactors.PushInteractor;
@SuppressLint("NewApi")
public class GCMIntentService extends GcmListenerService implements PushConstants { public class GCMIntentService extends GcmListenerService implements PushConstants {
private static final String LOG_TAG = "GCMIntentService"; private static final String LOG_TAG = "GCMIntentService";
...@@ -29,9 +33,13 @@ public class GCMIntentService extends GcmListenerService implements PushConstant ...@@ -29,9 +33,13 @@ public class GCMIntentService extends GcmListenerService implements PushConstant
Context applicationContext = getApplicationContext(); Context applicationContext = getApplicationContext();
PushInteractor pushInteractor = new DefaultPushInteractor();
extras = normalizeExtras(applicationContext, extras); extras = normalizeExtras(applicationContext, extras);
new PushNotificationHandler().showNotificationIfPossible(applicationContext, extras); PushNotificationHandler pushNotificationHandler = new PushNotificationHandler();
pushNotificationHandler.showNotificationIfPossible(applicationContext, pushInteractor, extras);
} }
/* /*
......
package chat.rocket.android.push.interactors;
import chat.rocket.android.helper.ServerPolicyHelper;
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.realm_helper.RealmStore;
public class DefaultPushInteractor implements PushInteractor {
@Override
public String getServerConfigId(String hostname) {
final ServerConfig serverConfig = RealmStore.getDefault()
.executeTransactionForRead(
realm -> realm.where(ServerConfig.class)
.equalTo(ServerConfig.HOSTNAME, ServerPolicyHelper.enforceHostname(hostname))
.findFirst());
return serverConfig != null ? serverConfig.getServerConfigId() : "";
}
}
package chat.rocket.android.push.interactors;
public interface PushInteractor {
String getServerConfigId(String hostname);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment