Commit 79024d78 authored by Enzo's avatar Enzo

#1 - Change Hostname on logout - first commit

parent 0fe062dd
......@@ -12,6 +12,7 @@ import bolts.Task;
import chat.rocket.android.helper.CheckSum;
import chat.rocket.android.helper.TextUtils;
import chat.rocket.android.service.ConnectivityManager;
import chat.rocket.core.models.ServerInfo;
import chat.rocket.persistence.realm.models.ddp.RealmPermission;
import chat.rocket.persistence.realm.models.ddp.RealmPublicSetting;
import chat.rocket.core.SyncState;
......@@ -261,6 +262,13 @@ public class MethodCallHelper {
return call("logout", TIMEOUT_MS).onSuccessTask(task ->
realmHelper.executeTransaction(realm -> {
realm.delete(RealmSession.class);
//check whether the server list is empty
if (!ConnectivityManager.getInstance(context).getServerList().isEmpty()){
//for each server in serverList -> remove the server
for (ServerInfo server: ConnectivityManager.getInstance(context).getServerList()) {
ConnectivityManager.getInstance(context.getApplicationContext()).removeServer(server.getHostname());
}
}
return null;
}));
}
......
......@@ -16,6 +16,7 @@ import android.widget.TextView;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import chat.rocket.android.LaunchUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -267,6 +268,7 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
rootView.findViewById(R.id.btn_logout).setOnClickListener(view -> {
presenter.onLogout();
closeUserActionContainer();
LaunchUtil.showAddServerActivity(getContext());
});
}
......
......@@ -238,10 +238,11 @@ import rx.subjects.PublishSubject;
serverConnectivityList.put(hostname, ServerConnectivity.STATE_DISCONNECTING);
if (serviceInterface != null) {
return serviceInterface.disconnectFromServer(hostname);
return serviceInterface.disconnectFromServer(hostname)
.doAfterTerminate(() -> serverConnectivityList.remove(hostname));
} else {
return Single.error(new IllegalStateException("not prepared"));
}
});
}
}
}
\ No newline at end of file
......@@ -80,7 +80,12 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
RocketChatWebSocketThread thread = webSocketThreads.get(hostname);
if (thread != null) {
return thread.terminate();
return thread.terminate()
//after disconnection from server, remove RCWebSocket key from HashMap
.doAfterTerminate(() -> {
webSocketThreads.remove(hostname);
stopSelf();
});
} else {
return Observable.timer(1, TimeUnit.SECONDS).toSingle()
.flatMap(_val -> disconnectFromServer(hostname));
......
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