Commit 341e86e5 authored by Tiago Cunha's avatar Tiago Cunha

Ignores not registered servers

parent 5ee45e9f
...@@ -29,9 +29,12 @@ import java.io.InputStream; ...@@ -29,9 +29,12 @@ import java.io.InputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
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.helper.ServerPolicyHelper;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.service.ServerInfo;
public class PushNotificationHandler implements PushConstants { public class PushNotificationHandler implements PushConstants {
...@@ -99,7 +102,7 @@ public class PushNotificationHandler implements PushConstants { ...@@ -99,7 +102,7 @@ public class PushNotificationHandler implements PushConstants {
String hostname = getHostname(extras); String hostname = getHostname(extras);
String roomId = getRoomId(extras); String roomId = getRoomId(extras);
if (hostname == null || roomId == null) { if (hostname == null || roomId == null || !isValidHostname(context, hostname)) {
return; return;
} }
...@@ -652,4 +655,17 @@ public class PushNotificationHandler implements PushConstants { ...@@ -652,4 +655,17 @@ public class PushNotificationHandler implements PushConstants {
return null; return null;
} }
} }
private boolean isValidHostname(Context context, String hostname) {
final List<ServerInfo> serverInfoList =
ConnectivityManager.getInstance(context.getApplicationContext()).getServerList();
for (ServerInfo serverInfo : serverInfoList) {
if (serverInfo.hostname.equals(hostname)) {
return true;
}
}
return false;
}
} }
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