Commit 1a43611e authored by Leonardo Aramaki's avatar Leonardo Aramaki

Prune database collections after interactively logging out

parent cbda8984
...@@ -18,9 +18,7 @@ import chat.rocket.android.helper.LogIfError; ...@@ -18,9 +18,7 @@ import chat.rocket.android.helper.LogIfError;
import chat.rocket.android.helper.Logger; import chat.rocket.android.helper.Logger;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.service.ConnectivityManager; import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.android.service.ConnectivityManagerApi;
import chat.rocket.android.shared.BasePresenter; import chat.rocket.android.shared.BasePresenter;
import chat.rocket.android_ddp.DDPClient;
import chat.rocket.core.interactors.RoomInteractor; import chat.rocket.core.interactors.RoomInteractor;
import chat.rocket.core.models.Room; import chat.rocket.core.models.Room;
import chat.rocket.core.models.RoomSidebar; import chat.rocket.core.models.RoomSidebar;
...@@ -30,16 +28,11 @@ import chat.rocket.core.repositories.SpotlightRepository; ...@@ -30,16 +28,11 @@ import chat.rocket.core.repositories.SpotlightRepository;
import chat.rocket.core.repositories.UserRepository; import chat.rocket.core.repositories.UserRepository;
import chat.rocket.persistence.realm.RealmHelper; import chat.rocket.persistence.realm.RealmHelper;
import chat.rocket.persistence.realm.RealmStore; import chat.rocket.persistence.realm.RealmStore;
import chat.rocket.persistence.realm.models.ddp.RealmEmail;
import chat.rocket.persistence.realm.models.ddp.RealmUser;
import chat.rocket.persistence.realm.models.internal.GetUsersOfRoomsProcedure;
import chat.rocket.persistence.realm.models.internal.LoadMessageProcedure;
import chat.rocket.persistence.realm.models.internal.MethodCall;
import chat.rocket.persistence.realm.models.internal.RealmSession;
import chat.rocket.persistence.realm.repositories.RealmSpotlightRepository; import chat.rocket.persistence.realm.repositories.RealmSpotlightRepository;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
import io.realm.Realm;
public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View> implements SidebarMainContract.Presenter { public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View> implements SidebarMainContract.Presenter {
private final String hostname; private final String hostname;
...@@ -164,23 +157,17 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -164,23 +157,17 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
} }
clearSubscriptions(); clearSubscriptions();
DDPClient.get().close();
String currentHostname = rocketChatCache.getSelectedServerHostname(); String currentHostname = rocketChatCache.getSelectedServerHostname();
RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname); RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname);
return realmHelper.executeTransaction(realm -> { return realmHelper.executeTransaction(realm -> {
CookieManager.getInstance().removeAllCookie();
ConnectivityManagerApi connectivityManagerApi = ConnectivityManager.getInstance(RocketChatApplication.getInstance());
connectivityManagerApi.removeServer(currentHostname);
rocketChatCache.removeHostname(currentHostname); rocketChatCache.removeHostname(currentHostname);
rocketChatCache.removeSelectedRoomId(currentHostname); rocketChatCache.removeSelectedRoomId(currentHostname);
rocketChatCache.setSelectedServerHostname(rocketChatCache.getFirstLoggedHostnameIfAny()); rocketChatCache.setSelectedServerHostname(rocketChatCache.getFirstLoggedHostnameIfAny());
realm.delete(RealmEmail.class); realm.executeTransactionAsync(Realm::deleteAll);
realm.delete(RealmUser.class);
realm.delete(RealmSession.class);
realm.delete(MethodCall.class);
realm.delete(LoadMessageProcedure.class);
realm.delete(GetUsersOfRoomsProcedure.class);
view.onPreparedToLogOut(); view.onPreparedToLogOut();
ConnectivityManager.getInstance(RocketChatApplication.getInstance())
.removeServer(hostname);
CookieManager.getInstance().removeAllCookie();
return null; return null;
}); });
}); });
......
...@@ -109,7 +109,6 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -109,7 +109,6 @@ import io.reactivex.subjects.BehaviorSubject;
if (serverConnectivityList.containsKey(hostname)) { if (serverConnectivityList.containsKey(hostname)) {
disconnectFromServerIfNeeded(hostname) disconnectFromServerIfNeeded(hostname)
.subscribe(_val -> { .subscribe(_val -> {
System.out.println("Disconnected " + _val);
}, RCLog::e); }, RCLog::e);
} }
} }
......
...@@ -230,7 +230,7 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -230,7 +230,7 @@ public class RocketChatWebSocketThread extends HandlerThread {
if (result.code == DDPClient.REASON_NETWORK_ERROR) { if (result.code == DDPClient.REASON_NETWORK_ERROR) {
reconnect(); reconnect();
} else { } else {
unregisterListeners(); unregisterListenersAndClose();
} }
return null; return null;
}); });
...@@ -335,8 +335,8 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -335,8 +335,8 @@ public class RocketChatWebSocketThread extends HandlerThread {
.findAll()); .findAll());
if (sessions != null && sessions.size() > 0) { if (sessions != null && sessions.size() > 0) {
// if we have a session try to resume it. At this point we're probably recovering from // If we have a session try to resume it. At this point we're probably recovering from
// a disconnection state // a disconnection state.
final CompositeDisposable disposables = new CompositeDisposable(); final CompositeDisposable disposables = new CompositeDisposable();
MethodCallHelper methodCall = new MethodCallHelper(realmHelper); MethodCallHelper methodCall = new MethodCallHelper(realmHelper);
disposables.add( disposables.add(
...@@ -353,7 +353,11 @@ public class RocketChatWebSocketThread extends HandlerThread { ...@@ -353,7 +353,11 @@ public class RocketChatWebSocketThread extends HandlerThread {
createObserversAndRegister(); createObserversAndRegister();
disposables.clear(); disposables.clear();
}, },
error -> logErrorAndUnsubscribe(disposables, error) error -> {
logErrorAndUnsubscribe(disposables, error);
connectivityManager.notifyConnectionLost(hostname,
DDPClient.REASON_NETWORK_ERROR);
}
) )
); );
} else { } else {
......
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