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