Commit eb3d41bb authored by Leonardo Aramaki's avatar Leonardo Aramaki

Keep alive the server when tapping a notification

parent a088ec8b
......@@ -74,8 +74,10 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
onHostnameUpdated();
}
} else {
presenter.bindViewOnly(this);
ConnectivityManager.getInstance(getApplicationContext()).keepAliveServer();
presenter.bindView(this);
presenter.loadSignedInServers(hostname);
roomId = new RocketChatCache(getApplicationContext()).getSelectedRoomId();
}
}
......@@ -172,7 +174,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
sessionInteractor,
new MethodCallHelper(this, hostname),
ConnectivityManager.getInstance(getApplicationContext()),
rocketChatCache,
rocketChatCache,
publicSettingRepository
);
......@@ -302,6 +304,15 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
}
}
@Override
public void refreshRoom() {
Fragment fragment = getSupportFragmentManager().findFragmentById(getLayoutContainerForFragment());
if (fragment != null && fragment instanceof RoomFragment) {
RoomFragment roomFragment = (RoomFragment) fragment;
roomFragment.loadMessages();
}
}
private void changeServerIfNeeded(String serverHostname) {
if (!hostname.equalsIgnoreCase(serverHostname)) {
RocketChatCache rocketChatCache = new RocketChatCache(getApplicationContext());
......@@ -328,7 +339,6 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
public static final int STATUS_DISMISS = 0;
public static final int STATUS_CONNECTION_ERROR = 1;
public static final int STATUS_TOKEN_LOGIN = 2;
public static final int STATUS_LOGGING_OUT = 3;
private int status;
private Snackbar snackbar;
......
......@@ -26,6 +26,8 @@ public interface MainContract {
void showConnectionOk();
void showSignedInServers(List<Pair<String, Pair<String, String>>> serverList);
void refreshRoom();
}
interface Presenter extends BaseContract.Presenter<View> {
......
......@@ -225,6 +225,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
connectivity -> {
if (connectivity.state == ServerConnectivity.STATE_CONNECTED) {
view.showConnectionOk();
view.refreshRoom();
return;
}
view.showConnecting();
......
......@@ -701,4 +701,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
startActivity(intent);
}
}
public void loadMessages() {
presenter.loadMessages();
}
}
\ No newline at end of file
......@@ -348,8 +348,8 @@ object PushManager {
val userMessages = pushMessageList.filter {
it.notificationId == lastPushMessage.notificationId }
builder.setContentTitle(getTitle(userMessages.size, title))
inbox.setBigContentTitle(getTitle(userMessages.size, title))
builder.setContentTitle(getTitle(messageCount, title))
inbox.setBigContentTitle(getTitle(messageCount, title))
for (push in userMessages) {
inbox.addLine(push.message)
......@@ -601,11 +601,9 @@ object PushManager {
roomUserTuple.flatMap { tuple -> messageInteractor.send(tuple.first, tuple.second, message as String) }
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ success ->
.subscribe({ success ->
// Empty
},
{ throwable ->
}, { throwable ->
throwable.printStackTrace()
Logger.report(throwable)
})
......
package chat.rocket.android.service;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.List;
......@@ -22,4 +23,6 @@ public interface ConnectivityManagerApi {
List<ServerInfo> getServerList();
Observable<ServerConnectivity> getServerConnectivityAsObservable();
int getConnectivityState(@NonNull String hostname);
}
......@@ -4,6 +4,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import java.util.ArrayList;
......@@ -148,6 +149,11 @@ import rx.subjects.PublishSubject;
return Observable.concat(Observable.from(getCurrentConnectivityList()), connectivitySubject);
}
@Override
public int getConnectivityState(@NonNull String hostname) {
return serverConnectivityList.get(hostname);
}
@DebugLog
private Single<Boolean> connectToServerIfNeeded(String hostname, boolean forceConnect) {
return Single.defer(() -> {
......
......@@ -105,11 +105,14 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
private Single<RocketChatWebSocketThread> getOrCreateWebSocketThread(String hostname) {
return Single.defer(() -> {
webSocketThreadLock.acquire();
if (webSocketThreads.containsKey(hostname)) {
int connectivityState = ConnectivityManager.getInstance(getApplicationContext()).getConnectivityState(hostname);
boolean isConnected = connectivityState == ServerConnectivity.STATE_CONNECTED;
if (webSocketThreads.containsKey(hostname) && isConnected) {
RocketChatWebSocketThread thread = webSocketThreads.get(hostname);
webSocketThreadLock.release();
return Single.just(thread);
}
connectivityManager.notifyConnecting(hostname);
return RocketChatWebSocketThread.getStarted(getApplicationContext(), hostname)
.doOnSuccess(thread -> {
webSocketThreads.put(hostname, thread);
......
......@@ -209,6 +209,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
if (task.isFaulted()) {
Exception error = task.getError();
RCLog.e(error);
connectivityManager.notifyConnectionLost(
hostname, ConnectivityManagerInternal.REASON_NETWORK_ERROR);
emitter.onError(error);
} else {
keepAliveTimer.update();
......
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