Commit cf18e7f8 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Implement go back action from LoginActivity to fix the user getting locked at this screen

parent b1514363
...@@ -2,10 +2,13 @@ package chat.rocket.android; ...@@ -2,10 +2,13 @@ package chat.rocket.android;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import com.hadisatrio.optional.Optional; import com.hadisatrio.optional.Optional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -20,8 +23,6 @@ import chat.rocket.android.log.RCLog; ...@@ -20,8 +23,6 @@ import chat.rocket.android.log.RCLog;
import chat.rocket.core.utils.Pair; import chat.rocket.core.utils.Pair;
import io.reactivex.BackpressureStrategy; import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;
import okhttp3.HttpUrl; import okhttp3.HttpUrl;
/** /**
...@@ -38,13 +39,12 @@ public class RocketChatCache { ...@@ -38,13 +39,12 @@ public class RocketChatCache {
private static final String KEY_SESSION_TOKEN = "KEY_SESSION_TOKEN"; private static final String KEY_SESSION_TOKEN = "KEY_SESSION_TOKEN";
private Context context; private Context context;
private String session;
public RocketChatCache(Context context) { public RocketChatCache(Context context) {
this.context = context.getApplicationContext(); this.context = context.getApplicationContext();
} }
public void addOpenedRoom(@NonNull String roomId, long lastSeen) { public void addOpenedRoom(@NotNull String roomId, long lastSeen) {
JSONObject openedRooms = getOpenedRooms(); JSONObject openedRooms = getOpenedRooms();
try { try {
JSONObject room = new JSONObject().put("rid", roomId).put("ls", lastSeen); JSONObject room = new JSONObject().put("rid", roomId).put("ls", lastSeen);
...@@ -55,15 +55,15 @@ public class RocketChatCache { ...@@ -55,15 +55,15 @@ public class RocketChatCache {
setString(KEY_OPENED_ROOMS, openedRooms.toString()); setString(KEY_OPENED_ROOMS, openedRooms.toString());
} }
public void removeOpenedRoom(@NonNull String roomId) { public void removeOpenedRoom(@NotNull String roomId) {
JSONObject openedRooms = getOpenedRooms(); JSONObject openedRooms = getOpenedRooms();
if (openedRooms.has(roomId)) { if (openedRooms.has(roomId)) {
openedRooms.remove(roomId); openedRooms.remove(roomId);
} }
} }
public @NonNull @NotNull
JSONObject getOpenedRooms() { public JSONObject getOpenedRooms() {
String openedRooms = getString(KEY_OPENED_ROOMS, ""); String openedRooms = getString(KEY_OPENED_ROOMS, "");
if (openedRooms.isEmpty()) { if (openedRooms.isEmpty()) {
return new JSONObject(); return new JSONObject();
...@@ -88,9 +88,9 @@ public class RocketChatCache { ...@@ -88,9 +88,9 @@ public class RocketChatCache {
setString(KEY_SELECTED_SERVER_HOSTNAME, newHostname); setString(KEY_SELECTED_SERVER_HOSTNAME, newHostname);
} }
public void addHostSiteName(@NonNull String currentHostname, @NonNull String siteName) { public void addSiteName(@NotNull String currentHostname, @NotNull String siteName) {
try { try {
String hostSiteNamesJson = getHostSiteNamesJson(); String hostSiteNamesJson = getSiteName();
JSONObject jsonObject = (hostSiteNamesJson == null) ? JSONObject jsonObject = (hostSiteNamesJson == null) ?
new JSONObject() : new JSONObject(hostSiteNamesJson); new JSONObject() : new JSONObject(hostSiteNamesJson);
jsonObject.put(currentHostname, siteName); jsonObject.put(currentHostname, siteName);
...@@ -100,8 +100,22 @@ public class RocketChatCache { ...@@ -100,8 +100,22 @@ public class RocketChatCache {
} }
} }
public @NonNull public void removeSiteName(@NotNull String hostname) {
String getHostSiteName(@NonNull String host) { try {
String siteNameJson = getSiteName();
JSONObject jsonObject = (siteNameJson == null) ?
new JSONObject() : new JSONObject(siteNameJson);
if (jsonObject.has(hostname)) {
jsonObject.remove(hostname);
}
setString(KEY_SELECTED_SITE_NAME, jsonObject.toString());
} catch (JSONException e) {
RCLog.e(e);
}
}
@NotNull
public String getHostSiteName(@NotNull String host) {
if (host.startsWith("http")) { if (host.startsWith("http")) {
HttpUrl url = HttpUrl.parse(host); HttpUrl url = HttpUrl.parse(host);
if (url != null) { if (url != null) {
...@@ -109,7 +123,7 @@ public class RocketChatCache { ...@@ -109,7 +123,7 @@ public class RocketChatCache {
} }
} }
try { try {
String hostSiteNamesJson = getHostSiteNamesJson(); String hostSiteNamesJson = getSiteName();
JSONObject jsonObject = (hostSiteNamesJson == null) ? JSONObject jsonObject = (hostSiteNamesJson == null) ?
new JSONObject() : new JSONObject(hostSiteNamesJson); new JSONObject() : new JSONObject(hostSiteNamesJson);
host = getSiteUrlFor(host); host = getSiteUrlFor(host);
...@@ -120,18 +134,18 @@ public class RocketChatCache { ...@@ -120,18 +134,18 @@ public class RocketChatCache {
return ""; return "";
} }
private @Nullable @Nullable
String getHostSiteNamesJson() { private String getSiteName() {
return getString(KEY_SELECTED_SITE_NAME, null); return getString(KEY_SELECTED_SITE_NAME, null);
} }
public void addHostnameSiteUrl(@Nullable String hostnameAlias, @NonNull String currentHostname) { public void addSiteUrl(@Nullable String hostnameAlias, @NotNull String currentHostname) {
String alias = null; String alias = null;
if (hostnameAlias != null) { if (hostnameAlias != null) {
alias = hostnameAlias.toLowerCase(); alias = hostnameAlias.toLowerCase();
} }
try { try {
String selectedHostnameAliasJson = getLoginHostnamesJson(); String selectedHostnameAliasJson = getSiteUrlForAllServers();
JSONObject jsonObject = selectedHostnameAliasJson == null ? JSONObject jsonObject = selectedHostnameAliasJson == null ?
new JSONObject() : new JSONObject(selectedHostnameAliasJson); new JSONObject() : new JSONObject(selectedHostnameAliasJson);
jsonObject.put(alias, currentHostname); jsonObject.put(alias, currentHostname);
...@@ -141,14 +155,33 @@ public class RocketChatCache { ...@@ -141,14 +155,33 @@ public class RocketChatCache {
} }
} }
public @Nullable private void removeSiteUrl(@NotNull String hostname) {
String getSiteUrlFor(String hostname) { try {
String siteUrlForAllServersJson = getSiteUrlForAllServers();
JSONObject jsonObject = siteUrlForAllServersJson == null ?
new JSONObject() : new JSONObject(siteUrlForAllServersJson);
Iterator<String> keys = jsonObject.keys();
while (keys.hasNext()) {
String alias = keys.next();
if (hostname.equals(jsonObject.getString(alias))) {
jsonObject.remove(alias);
break;
}
}
setString(KEY_SELECTED_SITE_URL, jsonObject.toString());
} catch (JSONException e) {
RCLog.e(e);
}
}
@Nullable
public String getSiteUrlFor(String hostname) {
try { try {
String selectedServerHostname = getSelectedServerHostname(); String selectedServerHostname = getSelectedServerHostname();
if (getLoginHostnamesJson() == null || getLoginHostnamesJson().isEmpty()) { if (getSiteUrlForAllServers() == null || getSiteUrlForAllServers().isEmpty()) {
return null; return null;
} }
return new JSONObject(getLoginHostnamesJson()) return new JSONObject(getSiteUrlForAllServers())
.optString(hostname, selectedServerHostname); .optString(hostname, selectedServerHostname);
} catch (JSONException e) { } catch (JSONException e) {
RCLog.e(e); RCLog.e(e);
...@@ -156,12 +189,12 @@ public class RocketChatCache { ...@@ -156,12 +189,12 @@ public class RocketChatCache {
return null; return null;
} }
private @Nullable @Nullable
String getLoginHostnamesJson() { private String getSiteUrlForAllServers() {
return getString(KEY_SELECTED_SITE_URL, null); return getString(KEY_SELECTED_SITE_URL, null);
} }
public void addHostname(@NonNull String hostname, @Nullable String hostnameAvatarUri, String siteName) { public void addHostname(@NotNull String hostname, @Nullable String hostnameAvatarUri, String siteName) {
String hostnameList = getString(KEY_HOSTNAME_LIST, null); String hostnameList = getString(KEY_HOSTNAME_LIST, null);
try { try {
JSONObject json; JSONObject json;
...@@ -257,6 +290,7 @@ public class RocketChatCache { ...@@ -257,6 +290,7 @@ public class RocketChatCache {
} }
} }
@NonNull
private JSONObject getSelectedRoomIdJsonObject() throws JSONException { private JSONObject getSelectedRoomIdJsonObject() throws JSONException {
String json = getString(KEY_SELECTED_ROOM_ID, null); String json = getString(KEY_SELECTED_ROOM_ID, null);
if (json == null) { if (json == null) {
...@@ -367,4 +401,17 @@ public class RocketChatCache { ...@@ -367,4 +401,17 @@ public class RocketChatCache {
return null; return null;
} }
/**
* Wipe all given hostname entries and references from cache.
*/
public void clearSelectedHostnameReferences() {
String hostname = getSelectedServerHostname();
if (hostname != null) {
removeSiteName(hostname);
removeHostname(hostname);
removeSiteUrl(hostname);
setSelectedServerHostname(null);
}
}
} }
...@@ -512,8 +512,8 @@ public class MethodCallHelper { ...@@ -512,8 +512,8 @@ public class MethodCallHelper {
if (httpSiteUrl != null) { if (httpSiteUrl != null) {
String host = httpSiteUrl.host(); String host = httpSiteUrl.host();
RocketChatCache rocketChatCache = new RocketChatCache(context); RocketChatCache rocketChatCache = new RocketChatCache(context);
rocketChatCache.addHostnameSiteUrl(host, currentHostname); rocketChatCache.addSiteUrl(host, currentHostname);
rocketChatCache.addHostSiteName(currentHostname, siteName); rocketChatCache.addSiteName(currentHostname, siteName);
} }
} }
......
...@@ -11,7 +11,7 @@ import chat.rocket.android.fragment.AbstractFragment; ...@@ -11,7 +11,7 @@ import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.widget.RoomToolbar; import chat.rocket.android.widget.RoomToolbar;
import chat.rocket.core.models.User; import chat.rocket.core.models.User;
abstract class AbstractChatRoomFragment extends AbstractFragment { public abstract class AbstractChatRoomFragment extends AbstractFragment {
private RoomToolbar roomToolbar; private RoomToolbar roomToolbar;
@Nullable @Nullable
......
...@@ -131,7 +131,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -131,7 +131,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
private MethodCallHelper methodCallHelper; private MethodCallHelper methodCallHelper;
private AbsoluteUrlHelper absoluteUrlHelper; private AbsoluteUrlHelper absoluteUrlHelper;
private Message edittingMessage = null; private Message editingMessage = null;
private RoomToolbar toolbar; private RoomToolbar toolbar;
...@@ -344,7 +344,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -344,7 +344,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
optionalPane.ifPresent(pane -> pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() { optionalPane.ifPresent(pane -> pane.setPanelSlideListener(new SlidingPaneLayout.PanelSlideListener() {
@Override @Override
public void onPanelSlide(View view, float v) { public void onPanelSlide(@NonNull View view, float v) {
messageFormManager.enableComposingText(false); messageFormManager.enableComposingText(false);
sidebarFragment.clearSearchViewFocus(); sidebarFragment.clearSearchViewFocus();
//Ref: ActionBarDrawerToggle#setProgress //Ref: ActionBarDrawerToggle#setProgress
...@@ -352,12 +352,12 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -352,12 +352,12 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void onPanelOpened(View view) { public void onPanelOpened(@NonNull View view) {
toolbar.setNavigationIconVerticalMirror(true); toolbar.setNavigationIconVerticalMirror(true);
} }
@Override @Override
public void onPanelClosed(View view) { public void onPanelClosed(@NonNull View view) {
messageFormManager.enableComposingText(true); messageFormManager.enableComposingText(true);
toolbar.setNavigationIconVerticalMirror(false); toolbar.setNavigationIconVerticalMirror(false);
subPane.closePane(); subPane.closePane();
...@@ -487,8 +487,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -487,8 +487,8 @@ public class RoomFragment extends AbstractChatRoomFragment implements
@Override @Override
public boolean onBackPressed() { public boolean onBackPressed() {
if (edittingMessage != null) { if (editingMessage != null) {
edittingMessage = null; editingMessage = null;
messageFormManager.clearComposingText(); messageFormManager.clearComposingText();
} }
return false; return false;
...@@ -547,15 +547,15 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -547,15 +547,15 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
private void sendMessage(String messageText) { private void sendMessage(String messageText) {
if (edittingMessage == null) { if (editingMessage == null) {
presenter.sendMessage(messageText); presenter.sendMessage(messageText);
} else { } else {
presenter.updateMessage(edittingMessage, messageText); presenter.updateMessage(editingMessage, messageText);
} }
} }
@Override @Override
public void setupWith(RocketChatAbsoluteUrl rocketChatAbsoluteUrl) { public void setupWith(@NonNull RocketChatAbsoluteUrl rocketChatAbsoluteUrl) {
if (rocketChatAbsoluteUrl != null) { if (rocketChatAbsoluteUrl != null) {
token = rocketChatAbsoluteUrl.getToken(); token = rocketChatAbsoluteUrl.getToken();
userId = rocketChatAbsoluteUrl.getUserId(); userId = rocketChatAbsoluteUrl.getUserId();
...@@ -564,7 +564,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -564,7 +564,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void render(Room room) { public void render(@NonNull Room room) {
roomType = room.getType(); roomType = room.getType();
setToolbarTitle(room.getName()); setToolbarTitle(room.getName());
...@@ -589,7 +589,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -589,7 +589,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void showUserStatus(User user) { public void showUserStatus(@NonNull User user) {
showToolbarUserStatuslIcon(user.getStatus()); showToolbarUserStatuslIcon(user.getStatus());
} }
...@@ -610,7 +610,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -610,7 +610,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
public void onMessageSendSuccessfully() { public void onMessageSendSuccessfully() {
scrollToLatestMessage(); scrollToLatestMessage();
messageFormManager.onMessageSend(); messageFormManager.onMessageSend();
edittingMessage = null; editingMessage = null;
} }
@Override @Override
...@@ -629,15 +629,16 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -629,15 +629,16 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void showMessages(List<Message> messages) { public void showMessages(@NonNull List<? extends Message> messages) {
if (messageListAdapter == null) { if (messageListAdapter == null) {
return; return;
} }
messageListAdapter.updateData(messages);
messageListAdapter.updateData((List<Message>) messages);
} }
@Override @Override
public void showMessageSendFailure(Message message) { public void showMessageSendFailure(@NonNull Message message) {
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setPositiveButton(R.string.resend, .setPositiveButton(R.string.resend,
(dialog, which) -> presenter.resendMessage(message)) (dialog, which) -> presenter.resendMessage(message))
...@@ -648,7 +649,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -648,7 +649,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void showMessageDeleteFailure(Message message) { public void showMessageDeleteFailure(@NonNull Message message) {
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setTitle(getContext().getString(R.string.failed_to_delete)) .setTitle(getContext().getString(R.string.failed_to_delete))
.setMessage(getContext().getString(R.string.failed_to_delete_message)) .setMessage(getContext().getString(R.string.failed_to_delete_message))
...@@ -667,12 +668,12 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -667,12 +668,12 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void onReply(AbsoluteUrl absoluteUrl, String markdown, Message message) { public void onReply(@NonNull AbsoluteUrl absoluteUrl, @NonNull String markdown, @NonNull Message message) {
messageFormManager.setReply(absoluteUrl, markdown, message); messageFormManager.setReply(absoluteUrl, markdown, message);
} }
@Override @Override
public void onCopy(String message) { public void onCopy(@NonNull String message) {
RocketChatApplication context = RocketChatApplication.getInstance(); RocketChatApplication context = RocketChatApplication.getInstance();
ClipboardManager clipboardManager = ClipboardManager clipboardManager =
(ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
...@@ -680,7 +681,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -680,7 +681,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
@Override @Override
public void showMessageActions(Message message) { public void showMessageActions(@NonNull Message message) {
Activity context = getActivity(); Activity context = getActivity();
if (context != null && context instanceof MainActivity) { if (context != null && context instanceof MainActivity) {
MessagePopup.take(message) MessagePopup.take(message)
...@@ -694,7 +695,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements ...@@ -694,7 +695,7 @@ public class RoomFragment extends AbstractChatRoomFragment implements
} }
private void onEditMessage(Message message) { private void onEditMessage(Message message) {
edittingMessage = message; editingMessage = message;
messageFormManager.setEditMessage(message.getMessage()); messageFormManager.setEditMessage(message.getMessage());
} }
......
...@@ -8,7 +8,7 @@ import chat.rocket.android.R; ...@@ -8,7 +8,7 @@ import chat.rocket.android.R;
import chat.rocket.android.fragment.AbstractFragment; import chat.rocket.android.fragment.AbstractFragment;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
abstract class AbstractServerConfigFragment extends AbstractFragment { public abstract class AbstractServerConfigFragment extends AbstractFragment {
public static final String KEY_HOSTNAME = "hostname"; public static final String KEY_HOSTNAME = "hostname";
protected String hostname; protected String hostname;
......
...@@ -99,14 +99,14 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -99,14 +99,14 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
showFragmentWithBackStack(fragment) showFragmentWithBackStack(fragment)
} }
} }
viewMap[info.serviceName]?.setVisibility(View.VISIBLE) viewMap[info.serviceName]?.visibility = View.VISIBLE
} }
} }
} }
for (info in OAuthProviderInfo.LIST) { for (info in OAuthProviderInfo.LIST) {
if (supportedMap[info.serviceName] == false) { if (supportedMap[info.serviceName] == false) {
viewMap[info.serviceName]?.setVisibility(View.GONE) viewMap[info.serviceName]?.visibility = View.GONE
} }
} }
} }
......
...@@ -3,10 +3,14 @@ package chat.rocket.android.fragment.server_config ...@@ -3,10 +3,14 @@ package chat.rocket.android.fragment.server_config
import bolts.Continuation import bolts.Continuation
import bolts.Task import bolts.Task
import chat.rocket.android.BackgroundLooper import chat.rocket.android.BackgroundLooper
import chat.rocket.android.LaunchUtil
import chat.rocket.android.RocketChatApplication
import chat.rocket.android.RocketChatCache
import chat.rocket.android.api.MethodCallHelper import chat.rocket.android.api.MethodCallHelper
import chat.rocket.android.api.TwoStepAuthException import chat.rocket.android.api.TwoStepAuthException
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.shared.BasePresenter import chat.rocket.android.shared.BasePresenter
import chat.rocket.core.PublicSettingsConstants import chat.rocket.core.PublicSettingsConstants
import chat.rocket.core.models.PublicSetting import chat.rocket.core.models.PublicSetting
...@@ -26,6 +30,20 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi ...@@ -26,6 +30,20 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
getLoginServices() getLoginServices()
} }
override fun release() {
val context = RocketChatApplication.getInstance()
val rocketChatCache = RocketChatCache(context)
val hostname = rocketChatCache.selectedServerHostname
hostname?.let {
ConnectivityManager.getInstance(context).removeServer(hostname)
rocketChatCache.clearSelectedHostnameReferences()
}
super.release()
LaunchUtil.showMainActivity(context)
}
override fun login(username: String, password: String) { override fun login(username: String, password: String) {
if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) { if (TextUtils.isEmpty(username) || TextUtils.isEmpty(password)) {
return return
...@@ -50,7 +68,9 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi ...@@ -50,7 +68,9 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
.subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())) .subscribeOn(AndroidSchedulers.from(BackgroundLooper.get()))
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeBy( .subscribeBy(
onNext = { loginServiceConfigurations -> view.showLoginServices(loginServiceConfigurations) }, onNext = { loginServiceConfigurations ->
view.showLoginServices(loginServiceConfigurations);
},
onError = { Logger.report(it) } onError = { Logger.report(it) }
) )
) )
......
package chat.rocket.android.helper package chat.rocket.android.helper
import chat.rocket.android.BuildConfig
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.google.firebase.crash.FirebaseCrash import com.google.firebase.crash.FirebaseCrash
import chat.rocket.android.BuildConfig
object Logger { object Logger {
fun report(throwable: Throwable) { fun report(throwable: Throwable) {
......
...@@ -22,7 +22,6 @@ import chat.rocket.android.BuildConfig ...@@ -22,7 +22,6 @@ import chat.rocket.android.BuildConfig
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.RocketChatCache import chat.rocket.android.RocketChatCache
import chat.rocket.android.activity.MainActivity import chat.rocket.android.activity.MainActivity
import chat.rocket.android.extensions.printStackTraceOnDebug
import chat.rocket.android.helper.Logger import chat.rocket.android.helper.Logger
import chat.rocket.core.interactors.MessageInteractor import chat.rocket.core.interactors.MessageInteractor
import chat.rocket.core.models.Room import chat.rocket.core.models.Room
......
...@@ -107,7 +107,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -107,7 +107,7 @@ import io.reactivex.subjects.BehaviorSubject;
public void removeServer(String hostname) { public void removeServer(String hostname) {
RealmBasedServerInfo.remove(hostname); RealmBasedServerInfo.remove(hostname);
if (serverConnectivityList.containsKey(hostname)) { if (serverConnectivityList.containsKey(hostname)) {
disconnectFromServerIfNeeded(hostname) disconnectFromServerIfNeeded(hostname, DDPClient.REASON_CLOSED_BY_USER)
.subscribe(_val -> { .subscribe(_val -> {
}, RCLog::e); }, RCLog::e);
} }
...@@ -207,7 +207,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -207,7 +207,7 @@ import io.reactivex.subjects.BehaviorSubject;
}); });
} }
private Single<Boolean> disconnectFromServerIfNeeded(String hostname) { private Single<Boolean> disconnectFromServerIfNeeded(String hostname, int reason) {
return Single.defer(() -> { return Single.defer(() -> {
final int connectivity = serverConnectivityList.get(hostname); final int connectivity = serverConnectivityList.get(hostname);
if (connectivity == ServerConnectivity.STATE_DISCONNECTED) { if (connectivity == ServerConnectivity.STATE_DISCONNECTED) {
...@@ -216,8 +216,8 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -216,8 +216,8 @@ import io.reactivex.subjects.BehaviorSubject;
if (connectivity == ServerConnectivity.STATE_CONNECTING) { if (connectivity == ServerConnectivity.STATE_CONNECTING) {
return waitForConnected(hostname) return waitForConnected(hostname)
.doOnError(err -> notifyConnectionLost(hostname, DDPClient.REASON_NETWORK_ERROR)) // .doOnError(err -> notifyConnectionLost(hostname, DDPClient.REASON_CLOSED_BY_USER))
.flatMap(_val -> disconnectFromServerIfNeeded(hostname)); .flatMap(_val -> disconnectFromServerIfNeeded(hostname, DDPClient.REASON_CLOSED_BY_USER));
} }
if (connectivity == ServerConnectivity.STATE_DISCONNECTING) { if (connectivity == ServerConnectivity.STATE_DISCONNECTING) {
...@@ -286,7 +286,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -286,7 +286,7 @@ import io.reactivex.subjects.BehaviorSubject;
if (serviceInterface != null) { if (serviceInterface != null) {
return serviceInterface.disconnectFromServer(hostname) return serviceInterface.disconnectFromServer(hostname)
//after disconnection from server, remove HOSTNAME key from HashMap //after disconnection from server, remove HOSTNAME key from HashMap
.doAfterTerminate(() -> { .doAfterTerminate(() -> {
serverConnectivityList.remove(hostname); serverConnectivityList.remove(hostname);
serverConnectivityList.put(hostname, ServerConnectivity.STATE_DISCONNECTED); serverConnectivityList.put(hostname, ServerConnectivity.STATE_DISCONNECTED);
......
This diff is collapsed.
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