Commit 75bf293c authored by Leonardo Aramaki's avatar Leonardo Aramaki

Upon failure, do unregister of current listeners and register them

all again with the new dppclient just reconnected
parent a604ae0d
...@@ -162,6 +162,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -162,6 +162,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
addSubscription(subscription); addSubscription(subscription);
// Update to RxJava 2 (issue: https://github.com/RocketChat/Rocket.Chat.Android/issues/355)
addSubscription( addSubscription(
RxJavaInterop.toV2Observable(connectivityManagerApi.getServerConnectivityAsObservable()) RxJavaInterop.toV2Observable(connectivityManagerApi.getServerConnectivityAsObservable())
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
...@@ -171,8 +172,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -171,8 +172,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
view.showConnecting(); view.showConnecting();
} }
}, },
err -> { Logger::report)
})
); );
} }
......
...@@ -38,6 +38,7 @@ import chat.rocket.persistence.realm.RealmStore; ...@@ -38,6 +38,7 @@ import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.internal.RealmSession; import chat.rocket.persistence.realm.models.internal.RealmSession;
import hu.akarnokd.rxjava.interop.RxJavaInterop; import hu.akarnokd.rxjava.interop.RxJavaInterop;
import hugo.weaving.DebugLog; import hugo.weaving.DebugLog;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import rx.Single; import rx.Single;
...@@ -254,28 +255,14 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -254,28 +255,14 @@ public class RocketChatWebSocketThread extends HandlerThread {
task.getResult().client.getOnFailureCallback().onSuccess(_task -> { task.getResult().client.getOnFailureCallback().onSuccess(_task -> {
ddpClient = null; ddpClient = null;
CompositeDisposable subscriptions = new CompositeDisposable(); CompositeDisposable disposables = new CompositeDisposable();
connectivityManager.notifyConnecting(hostname); connectivityManager.notifyConnecting(hostname);
subscriptions.add( disposables.add(
RxJavaInterop.toV2Single(connect().retry()) RxJavaInterop.toV2Single(connect().retry())
.observeOn(AndroidSchedulers.from(getLooper()))
.subscribe( .subscribe(
rocketChatWebSocketThread -> { rocketChatWebSocketThread -> forceRegisteringListeners(),
String roomId = rocketChatCache.getSelectedRoomId(); err -> logErrorAndDispose(err, disposables)
if (roomId != null) {
StreamRoomMessage streamRoomObserver = new StreamRoomMessage(
appContext,
hostname,
realmHelper,
ddpClientRef,
roomId
);
streamRoomObserver.register();
listeners.add(streamRoomObserver);
}
},
err -> {
subscriptions.dispose();
}
) )
); );
return null; return null;
...@@ -308,6 +295,22 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -308,6 +295,22 @@ public class RocketChatWebSocketThread extends HandlerThread {
})); }));
} }
private void logErrorAndDispose(Throwable throwable, CompositeDisposable disposables) {
RCLog.e(throwable);
disposables.clear();
}
private void forceRegisteringListeners() {
Iterator<Registrable> iterator = listeners.iterator();
while (iterator.hasNext()) {
Registrable registrable = iterator.next();
registrable.unregister();
iterator.remove();
}
listenersRegistered = false;
registerListeners();
}
@DebugLog @DebugLog
private Single<Boolean> connect() { private Single<Boolean> connect() {
return connectDDPClient() return connectDDPClient()
......
...@@ -118,10 +118,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> { ...@@ -118,10 +118,7 @@ public class MethodCallObserver extends AbstractModelObserver<MethodCall> {
} else if (exception instanceof DDPClientCallback.RPC.Timeout) { } else if (exception instanceof DDPClientCallback.RPC.Timeout) {
// temp "fix"- we need to rewrite the connection layer a bit // temp "fix"- we need to rewrite the connection layer a bit
errMessage = "{\"message\": \"Connection Timeout\"}"; errMessage = "{\"message\": \"Connection Timeout\"}";
} /*else if (exception instanceof RxWebSocketCallback.Failure) { } else {
// temp "fix"- we need to rewrite the connection layer a bit
errMessage = "{\"message\": \"Connection Failure\"}";
}*/ else {
errMessage = exception.getMessage(); errMessage = exception.getMessage();
} }
......
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