Commit 65d5c3a7 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Fix some issues when logging-in after previous backpress fix

parent cf18e7f8
package chat.rocket.android.helper package chat.rocket.android.helper
import android.content.Context import android.content.Context
import chat.rocket.android.RocketChatCache
import chat.rocket.android.api.rest.CookieInterceptor import chat.rocket.android.api.rest.CookieInterceptor
import chat.rocket.android.api.rest.DefaultCookieProvider import chat.rocket.android.api.rest.DefaultCookieProvider
import com.facebook.stetho.okhttp3.StethoInterceptor import com.facebook.stetho.okhttp3.StethoInterceptor
...@@ -24,17 +23,18 @@ object OkHttpHelper { ...@@ -24,17 +23,18 @@ object OkHttpHelper {
return httpClientForUploadFile ?: throw AssertionError("httpClientForUploadFile set to null by another thread") return httpClientForUploadFile ?: throw AssertionError("httpClientForUploadFile set to null by another thread")
} }
fun getClientForDownloadFile(context: Context): OkHttpClient { fun getClientForDownloadFile(): OkHttpClient {
if(httpClientForDownloadFile == null) { if (httpClientForDownloadFile == null) {
httpClientForDownloadFile = OkHttpClient.Builder() httpClientForDownloadFile = OkHttpClient.Builder()
.addNetworkInterceptor(StethoInterceptor()) .addNetworkInterceptor(StethoInterceptor())
.followRedirects(true) .followRedirects(true)
.followSslRedirects(true) .followSslRedirects(true)
.addInterceptor(CookieInterceptor(DefaultCookieProvider(RocketChatCache(context)))) .addInterceptor(CookieInterceptor(DefaultCookieProvider()))
.build() .build()
} }
return httpClientForDownloadFile ?: throw AssertionError("httpClientForDownloadFile set to null by another thread") return httpClientForDownloadFile ?: throw AssertionError("httpClientForDownloadFile set to null by another thread")
} }
/** /**
* Returns the OkHttpClient instance for WebSocket connection. * Returns the OkHttpClient instance for WebSocket connection.
* @return The OkHttpClient WebSocket connection instance. * @return The OkHttpClient WebSocket connection instance.
......
...@@ -35,6 +35,7 @@ public class RocketChatApplication extends MultiDexApplication { ...@@ -35,6 +35,7 @@ public class RocketChatApplication extends MultiDexApplication {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
RocketChatCache.INSTANCE.initialize(this);
JobManager.create(this).addJobCreator(new RocketChatJobCreator()); JobManager.create(this).addJobCreator(new RocketChatJobCreator());
DDPClient.initialize(OkHttpHelper.INSTANCE.getClientForWebSocket()); DDPClient.initialize(OkHttpHelper.INSTANCE.getClientForWebSocket());
Fabric.with(this, new Crashlytics()); Fabric.with(this, new Crashlytics());
...@@ -46,7 +47,7 @@ public class RocketChatApplication extends MultiDexApplication { ...@@ -46,7 +47,7 @@ public class RocketChatApplication extends MultiDexApplication {
RealmStore.put(serverInfo.getHostname()); RealmStore.put(serverInfo.getHostname());
} }
RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile(this)); RocketChatWidgets.initialize(this, OkHttpHelper.INSTANCE.getClientForDownloadFile());
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true); AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
......
This diff is collapsed.
...@@ -16,77 +16,85 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository; ...@@ -16,77 +16,85 @@ import chat.rocket.persistence.realm.repositories.RealmSessionRepository;
* Activity for Login, Sign-up, and Retry connecting... * Activity for Login, Sign-up, and Retry connecting...
*/ */
public class LoginActivity extends AbstractFragmentActivity implements LoginContract.View { public class LoginActivity extends AbstractFragmentActivity implements LoginContract.View {
public static final String KEY_HOSTNAME = "hostname"; public static final String KEY_HOSTNAME = "hostname";
private LoginContract.Presenter presenter; private LoginContract.Presenter presenter;
@Override @Override
protected int getLayoutContainerForFragment() { protected int getLayoutContainerForFragment() {
return R.id.content; return R.id.content;
} }
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String hostname = null;
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
hostname = intent.getStringExtra(KEY_HOSTNAME);
}
presenter = new LoginPresenter(
hostname,
new SessionInteractor(new RealmSessionRepository(hostname)),
ConnectivityManager.getInstance(getApplicationContext())
);
}
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
protected void onDestroy() {
presenter.release();
super.onDestroy();
}
private void showFragment(Fragment fragment, String hostname) {
setContentView(R.layout.simple_screen);
injectHostnameArgTo(fragment, hostname);
super.showFragment(fragment);
}
private void injectHostnameArgTo(Fragment fragment, String hostname) {
Bundle args = fragment.getArguments();
if (args == null) {
args = new Bundle();
}
args.putString(LoginActivity.KEY_HOSTNAME, hostname);
fragment.setArguments(args);
}
@Override
protected void onBackPressedNotHandled() {
moveTaskToBack(true);
}
@Override
public void showLogin(String hostname) {
showFragment(new LoginFragment(), hostname);
}
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { public void showRetryLogin(String hostname) {
super.onCreate(savedInstanceState); showFragment(new RetryLoginFragment(), hostname);
}
String hostname = null; @Override
Intent intent = getIntent(); public void closeView() {
if (intent != null && intent.getExtras() != null) { finish();
hostname = intent.getStringExtra(KEY_HOSTNAME); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
} }
presenter = new LoginPresenter( @Override
hostname, protected boolean onBackPress() {
new SessionInteractor(new RealmSessionRepository(hostname)), LoginFragment loginFragment = (LoginFragment) getSupportFragmentManager()
ConnectivityManager.getInstance(getApplicationContext()) .findFragmentById(getLayoutContainerForFragment());
); loginFragment.goBack();
} return true;
@Override
protected void onResume() {
super.onResume();
presenter.bindView(this);
}
@Override
protected void onDestroy() {
presenter.release();
super.onDestroy();
}
private void showFragment(Fragment fragment, String hostname) {
setContentView(R.layout.simple_screen);
injectHostnameArgTo(fragment, hostname);
super.showFragment(fragment);
}
private void injectHostnameArgTo(Fragment fragment, String hostname) {
Bundle args = fragment.getArguments();
if (args == null) {
args = new Bundle();
} }
args.putString(LoginActivity.KEY_HOSTNAME, hostname);
fragment.setArguments(args);
}
@Override
protected void onBackPressedNotHandled() {
moveTaskToBack(true);
}
@Override
public void showLogin(String hostname) {
showFragment(new LoginFragment(), hostname);
}
@Override
public void showRetryLogin(String hostname) {
showFragment(new RetryLoginFragment(), hostname);
}
@Override
public void closeView() {
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}
} }
...@@ -81,7 +81,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -81,7 +81,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
ConnectivityManagerApi connectivityManager = ConnectivityManager.getInstance(getApplicationContext()); ConnectivityManagerApi connectivityManager = ConnectivityManager.getInstance(getApplicationContext());
if (hostname == null || presenter == null) { if (hostname == null || presenter == null) {
String previousHostname = hostname; String previousHostname = hostname;
hostname = new RocketChatCache(getApplicationContext()).getSelectedServerHostname(); hostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
if (hostname == null) { if (hostname == null) {
showAddServerScreen(); showAddServerScreen();
} else { } else {
...@@ -95,7 +95,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -95,7 +95,7 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
connectivityManager.keepAliveServer(); connectivityManager.keepAliveServer();
presenter.bindView(this); presenter.bindView(this);
presenter.loadSignedInServers(hostname); presenter.loadSignedInServers(hostname);
roomId = new RocketChatCache(getApplicationContext()).getSelectedRoomId(); roomId = RocketChatCache.INSTANCE.getSelectedRoomId();
} }
} }
...@@ -186,15 +186,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -186,15 +186,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
PublicSettingRepository publicSettingRepository = new RealmPublicSettingRepository(hostname); PublicSettingRepository publicSettingRepository = new RealmPublicSettingRepository(hostname);
RocketChatCache rocketChatCache = new RocketChatCache(this);
presenter = new MainPresenter( presenter = new MainPresenter(
roomInteractor, roomInteractor,
createRoomInteractor, createRoomInteractor,
sessionInteractor, sessionInteractor,
new MethodCallHelper(this, hostname), new MethodCallHelper(this, hostname),
ConnectivityManager.getInstance(getApplicationContext()), ConnectivityManager.getInstance(getApplicationContext()),
rocketChatCache,
publicSettingRepository publicSettingRepository
); );
...@@ -203,12 +200,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -203,12 +200,12 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
presenter.bindView(this); presenter.bindView(this);
presenter.loadSignedInServers(hostname); presenter.loadSignedInServers(hostname);
roomId = rocketChatCache.getSelectedRoomId(); roomId = RocketChatCache.INSTANCE.getSelectedRoomId();
} }
private void updateSidebarMainFragment() { private void updateSidebarMainFragment() {
closeSidebarIfNeeded(); closeSidebarIfNeeded();
String selectedServerHostname = new RocketChatCache(this).getSelectedServerHostname(); String selectedServerHostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
Fragment sidebarFragment = findFragmentByTag(selectedServerHostname); Fragment sidebarFragment = findFragmentByTag(selectedServerHostname);
if (sidebarFragment == null) { if (sidebarFragment == null) {
sidebarFragment = SidebarMainFragment.create(selectedServerHostname); sidebarFragment = SidebarMainFragment.create(selectedServerHostname);
...@@ -399,15 +396,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract ...@@ -399,15 +396,14 @@ public class MainActivity extends AbstractAuthedActivity implements MainContract
private void changeServerIfNeeded(String serverHostname) { private void changeServerIfNeeded(String serverHostname) {
if (!hostname.equalsIgnoreCase(serverHostname)) { if (!hostname.equalsIgnoreCase(serverHostname)) {
RocketChatCache rocketChatCache = new RocketChatCache(getApplicationContext()); RocketChatCache.INSTANCE.setSelectedServerHostname(serverHostname);
rocketChatCache.setSelectedServerHostname(serverHostname);
} }
} }
@DebugLog @DebugLog
public void onLogout() { public void onLogout() {
presenter.prepareToLogout(); presenter.prepareToLogout();
if (new RocketChatCache(getApplicationContext()).getSelectedServerHostname() == null) { if (RocketChatCache.INSTANCE.getSelectedServerHostname() == null) {
finish(); finish();
LaunchUtil.showMainActivity(this); LaunchUtil.showMainActivity(this);
} else { } else {
......
...@@ -41,7 +41,6 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -41,7 +41,6 @@ public class MainPresenter extends BasePresenter<MainContract.View>
private final SessionInteractor sessionInteractor; private final SessionInteractor sessionInteractor;
private final MethodCallHelper methodCallHelper; private final MethodCallHelper methodCallHelper;
private final ConnectivityManagerApi connectivityManagerApi; private final ConnectivityManagerApi connectivityManagerApi;
private final RocketChatCache rocketChatCache;
private final PublicSettingRepository publicSettingRepository; private final PublicSettingRepository publicSettingRepository;
public MainPresenter(RoomInteractor roomInteractor, public MainPresenter(RoomInteractor roomInteractor,
...@@ -49,13 +48,12 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -49,13 +48,12 @@ public class MainPresenter extends BasePresenter<MainContract.View>
SessionInteractor sessionInteractor, SessionInteractor sessionInteractor,
MethodCallHelper methodCallHelper, MethodCallHelper methodCallHelper,
ConnectivityManagerApi connectivityManagerApi, ConnectivityManagerApi connectivityManagerApi,
RocketChatCache rocketChatCache, PublicSettingRepository publicSettingRepository) { PublicSettingRepository publicSettingRepository) {
this.roomInteractor = roomInteractor; this.roomInteractor = roomInteractor;
this.canCreateRoomInteractor = canCreateRoomInteractor; this.canCreateRoomInteractor = canCreateRoomInteractor;
this.sessionInteractor = sessionInteractor; this.sessionInteractor = sessionInteractor;
this.methodCallHelper = methodCallHelper; this.methodCallHelper = methodCallHelper;
this.connectivityManagerApi = connectivityManagerApi; this.connectivityManagerApi = connectivityManagerApi;
this.rocketChatCache = rocketChatCache;
this.publicSettingRepository = publicSettingRepository; this.publicSettingRepository = publicSettingRepository;
} }
...@@ -101,7 +99,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -101,7 +99,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
@Override @Override
public void release() { public void release() {
if (rocketChatCache.getSessionToken() != null) { if (RocketChatCache.INSTANCE.getSessionToken() != null) {
setUserAway(); setUserAway();
} }
...@@ -158,13 +156,13 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -158,13 +156,13 @@ public class MainPresenter extends BasePresenter<MainContract.View>
String logoUrl = (jsonObject.has("url")) ? String logoUrl = (jsonObject.has("url")) ?
jsonObject.optString("url") : jsonObject.optString("defaultUrl"); jsonObject.optString("url") : jsonObject.optString("defaultUrl");
String siteName = serverInfoPair.second; String siteName = serverInfoPair.second;
rocketChatCache.addHostname(hostname.toLowerCase(), logoUrl, siteName); RocketChatCache.INSTANCE.addHostname(hostname.toLowerCase(), logoUrl, siteName);
return rocketChatCache.getServerList(); return RocketChatCache.INSTANCE.getServerList();
} }
private void openRoom() { private void openRoom() {
String hostname = rocketChatCache.getSelectedServerHostname(); String hostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
String roomId = rocketChatCache.getSelectedRoomId(); String roomId = RocketChatCache.INSTANCE.getSelectedRoomId();
if (roomId == null || roomId.length() == 0) { if (roomId == null || roomId.length() == 0) {
view.showHome(); view.showHome();
...@@ -214,7 +212,7 @@ public class MainPresenter extends BasePresenter<MainContract.View> ...@@ -214,7 +212,7 @@ public class MainPresenter extends BasePresenter<MainContract.View>
} }
// TODO: Should we remove below and above calls to view? // TODO: Should we remove below and above calls to view?
// view.showConnectionOk(); // view.showConnectionOk();
rocketChatCache.setSessionToken(session.getToken()); RocketChatCache.INSTANCE.setSessionToken(session.getToken());
}, },
Logger.INSTANCE::report Logger.INSTANCE::report
); );
......
...@@ -12,7 +12,6 @@ import java.util.UUID; ...@@ -12,7 +12,6 @@ import java.util.UUID;
import bolts.Continuation; import bolts.Continuation;
import bolts.Task; import bolts.Task;
import chat.rocket.android.RocketChatApplication;
import chat.rocket.android.RocketChatCache; import chat.rocket.android.RocketChatCache;
import chat.rocket.android.helper.CheckSum; import chat.rocket.android.helper.CheckSum;
import chat.rocket.android.helper.TextUtils; import chat.rocket.android.helper.TextUtils;
...@@ -304,9 +303,7 @@ public class MethodCallHelper { ...@@ -304,9 +303,7 @@ public class MethodCallHelper {
realm.createOrUpdateAllFromJson( realm.createOrUpdateAllFromJson(
RealmRoom.class, result); RealmRoom.class, result);
Context appContext = RocketChatApplication.getInstance(); JSONObject openedRooms = RocketChatCache.INSTANCE.getOpenedRooms();
RocketChatCache cache = new RocketChatCache(appContext);
JSONObject openedRooms = cache.getOpenedRooms();
RealmQuery<RealmRoom> query = realm.where(RealmRoom.class); RealmQuery<RealmRoom> query = realm.where(RealmRoom.class);
Iterator<String> keys = openedRooms.keys(); Iterator<String> keys = openedRooms.keys();
...@@ -314,7 +311,7 @@ public class MethodCallHelper { ...@@ -314,7 +311,7 @@ public class MethodCallHelper {
String rid = keys.next(); String rid = keys.next();
RealmRoom realmRoom = query.equalTo(RealmRoom.ID, rid).findFirst(); RealmRoom realmRoom = query.equalTo(RealmRoom.ID, rid).findFirst();
if (realmRoom == null) { if (realmRoom == null) {
cache.removeOpenedRoom(rid); RocketChatCache.INSTANCE.removeOpenedRoom(rid);
} else { } else {
loadMissedMessages(rid, realmRoom.getLastSeen()) loadMissedMessages(rid, realmRoom.getLastSeen())
.continueWithTask(task1 -> { .continueWithTask(task1 -> {
...@@ -511,9 +508,8 @@ public class MethodCallHelper { ...@@ -511,9 +508,8 @@ public class MethodCallHelper {
HttpUrl httpSiteUrl = HttpUrl.parse(siteUrl); HttpUrl httpSiteUrl = HttpUrl.parse(siteUrl);
if (httpSiteUrl != null) { if (httpSiteUrl != null) {
String host = httpSiteUrl.host(); String host = httpSiteUrl.host();
RocketChatCache rocketChatCache = new RocketChatCache(context); RocketChatCache.INSTANCE.addSiteUrl(host, currentHostname);
rocketChatCache.addSiteUrl(host, currentHostname); RocketChatCache.INSTANCE.addSiteName(currentHostname, siteName);
rocketChatCache.addSiteName(currentHostname, siteName);
} }
} }
......
...@@ -8,42 +8,37 @@ import chat.rocket.persistence.realm.models.internal.RealmSession; ...@@ -8,42 +8,37 @@ import chat.rocket.persistence.realm.models.internal.RealmSession;
public class DefaultCookieProvider implements CookieProvider { public class DefaultCookieProvider implements CookieProvider {
private RocketChatCache rocketChatCache;
public DefaultCookieProvider(RocketChatCache rocketChatCache) {
this.rocketChatCache = rocketChatCache;
}
@Override
public String getHostname() {
return getHostnameFromCache();
}
@Override
public String getCookie() {
final String hostname = getHostnameFromCache();
if (hostname == null) {
return "";
}
final RealmHelper realmHelper = RealmStore.get(getHostnameFromCache()); @Override
if (realmHelper == null) { public String getHostname() {
return ""; return getHostnameFromCache();
} }
final RealmUser user = realmHelper.executeTransactionForRead(realm -> @Override
RealmUser.queryCurrentUser(realm).findFirst()); public String getCookie() {
final RealmSession session = realmHelper.executeTransactionForRead(realm -> final String hostname = getHostnameFromCache();
RealmSession.queryDefaultSession(realm).findFirst()); if (hostname == null) {
return "";
}
if (user == null || session == null) { final RealmHelper realmHelper = RealmStore.get(getHostnameFromCache());
return ""; if (realmHelper == null) {
} return "";
}
final RealmUser user = realmHelper.executeTransactionForRead(realm ->
RealmUser.queryCurrentUser(realm).findFirst());
final RealmSession session = realmHelper.executeTransactionForRead(realm ->
RealmSession.queryDefaultSession(realm).findFirst());
return "rc_uid=" + user.getId() + ";rc_token=" + session.getToken(); if (user == null || session == null) {
} return "";
}
private String getHostnameFromCache() { return "rc_uid=" + user.getId() + ";rc_token=" + session.getToken();
return rocketChatCache.getSelectedServerHostname(); }
}
private String getHostnameFromCache() {
return RocketChatCache.INSTANCE.getSelectedServerHostname();
}
} }
...@@ -32,7 +32,7 @@ public class InputHostnameFragment extends AbstractFragment implements InputHost ...@@ -32,7 +32,7 @@ public class InputHostnameFragment extends AbstractFragment implements InputHost
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Context appContext = getContext().getApplicationContext(); Context appContext = getContext().getApplicationContext();
presenter = new InputHostnamePresenter(new RocketChatCache(appContext), ConnectivityManager.getInstance(appContext)); presenter = new InputHostnamePresenter(ConnectivityManager.getInstance(appContext));
} }
@Override @Override
......
...@@ -14,11 +14,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers; ...@@ -14,11 +14,9 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable; import io.reactivex.disposables.Disposable;
public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.View> implements InputHostnameContract.Presenter { public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.View> implements InputHostnameContract.Presenter {
private final RocketChatCache rocketChatCache;
private final ConnectivityManagerApi connectivityManager; private final ConnectivityManagerApi connectivityManager;
public InputHostnamePresenter(RocketChatCache rocketChatCache, ConnectivityManagerApi connectivityManager) { public InputHostnamePresenter(ConnectivityManagerApi connectivityManager) {
this.rocketChatCache = rocketChatCache;
this.connectivityManager = connectivityManager; this.connectivityManager = connectivityManager;
} }
...@@ -54,7 +52,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract. ...@@ -54,7 +52,7 @@ public class InputHostnamePresenter extends BasePresenter<InputHostnameContract.
} }
private void onServerValid(String hostname, boolean usesSecureConnection) { private void onServerValid(String hostname, boolean usesSecureConnection) {
rocketChatCache.setSelectedServerHostname(hostname); RocketChatCache.INSTANCE.setSelectedServerHostname(hostname);
String server = hostname.replace("/", "."); String server = hostname.replace("/", ".");
connectivityManager.addOrUpdateServer(server, server, !usesSecureConnection); connectivityManager.addOrUpdateServer(server, server, !usesSecureConnection);
......
...@@ -170,7 +170,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -170,7 +170,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
@Override @Override
public void loadMissedMessages() { public void loadMissedMessages() {
RocketChatApplication appContext = RocketChatApplication.getInstance(); RocketChatApplication appContext = RocketChatApplication.getInstance();
JSONObject openedRooms = new RocketChatCache(appContext).getOpenedRooms(); JSONObject openedRooms = RocketChatCache.INSTANCE.getOpenedRooms();
if (openedRooms.has(roomId)) { if (openedRooms.has(roomId)) {
try { try {
JSONObject room = openedRooms.getJSONObject(roomId); JSONObject room = openedRooms.getJSONObject(roomId);
...@@ -369,8 +369,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View> ...@@ -369,8 +369,7 @@ public class RoomPresenter extends BasePresenter<RoomContract.View>
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
.map(room -> { .map(room -> {
new RocketChatCache(RocketChatApplication.getInstance()) RocketChatCache.INSTANCE.addOpenedRoom(room.getRoomId(), room.getLastSeen());
.addOpenedRoom(room.getRoomId(), room.getLastSeen());
return room; return room;
}) })
.flatMap(messageInteractor::getAllFrom) .flatMap(messageInteractor::getAllFrom)
......
...@@ -7,21 +7,25 @@ import chat.rocket.core.models.LoginServiceConfiguration; ...@@ -7,21 +7,25 @@ import chat.rocket.core.models.LoginServiceConfiguration;
public interface LoginContract { public interface LoginContract {
interface View extends BaseContract.View { interface View extends BaseContract.View {
void showLoader(); void showLoader();
void hideLoader(); void hideLoader();
void showError(String message); void showError(String message);
void showLoginServices(List<LoginServiceConfiguration> loginServiceList); void showLoginServices(List<LoginServiceConfiguration> loginServiceList);
void showTwoStepAuth(); void showTwoStepAuth();
}
interface Presenter extends BaseContract.Presenter<View> { void goBack();
}
void login(String username, String password); interface Presenter extends BaseContract.Presenter<View> {
}
void login(String username, String password);
void goBack();
}
} }
...@@ -50,9 +50,9 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -50,9 +50,9 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
txtPasswd = rootView.findViewById(R.id.editor_passwd) txtPasswd = rootView.findViewById(R.id.editor_passwd)
waitingView = rootView.findViewById(R.id.waiting) waitingView = rootView.findViewById(R.id.waiting)
btnEmail.setOnClickListener { view -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) } btnEmail.setOnClickListener { _ -> presenter.login(txtUsername.text.toString(), txtPasswd.text.toString()) }
btnUserRegistration.setOnClickListener { view -> btnUserRegistration.setOnClickListener { _ ->
UserRegistrationDialogFragment.create(hostname, txtUsername.text.toString(), txtPasswd.text.toString()) UserRegistrationDialogFragment.create(hostname, txtUsername.text.toString(), txtPasswd.text.toString())
.show(fragmentManager!!, "UserRegistrationDialogFragment") .show(fragmentManager!!, "UserRegistrationDialogFragment")
} }
...@@ -84,7 +84,7 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -84,7 +84,7 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
for (info in OAuthProviderInfo.LIST) { for (info in OAuthProviderInfo.LIST) {
if (supportedMap[info.serviceName] == false && info.serviceName == authProvider.service) { if (supportedMap[info.serviceName] == false && info.serviceName == authProvider.service) {
supportedMap.put(info.serviceName, true) supportedMap.put(info.serviceName, true)
viewMap[info.serviceName]?.setOnClickListener { view -> viewMap[info.serviceName]?.setOnClickListener { _ ->
var fragment: Fragment? = null var fragment: Fragment? = null
try { try {
fragment = info.fragmentClass.newInstance() fragment = info.fragmentClass.newInstance()
...@@ -126,4 +126,8 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View { ...@@ -126,4 +126,8 @@ class LoginFragment : AbstractServerConfigFragment(), LoginContract.View {
presenter.release() presenter.release()
super.onPause() super.onPause()
} }
override fun goBack() {
presenter.goBack()
}
} }
...@@ -30,17 +30,14 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi ...@@ -30,17 +30,14 @@ class LoginPresenter(private val loginServiceConfigurationRepository: LoginServi
getLoginServices() getLoginServices()
} }
override fun release() { override fun goBack() {
val context = RocketChatApplication.getInstance() val context = RocketChatApplication.getInstance()
val rocketChatCache = RocketChatCache(context) val hostname = RocketChatCache.getSelectedServerHostname()
val hostname = rocketChatCache.selectedServerHostname
hostname?.let { hostname?.let {
ConnectivityManager.getInstance(context).removeServer(hostname) ConnectivityManager.getInstance(context).removeServer(hostname)
rocketChatCache.clearSelectedHostnameReferences() RocketChatCache.clearSelectedHostnameReferences()
} }
super.release()
LaunchUtil.showMainActivity(context) LaunchUtil.showMainActivity(context)
} }
......
...@@ -94,13 +94,11 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain ...@@ -94,13 +94,11 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
new SessionInteractor(new RealmSessionRepository(hostname)) new SessionInteractor(new RealmSessionRepository(hostname))
); );
RocketChatCache rocketChatCache = new RocketChatCache(getContext().getApplicationContext());
presenter = new SidebarMainPresenter( presenter = new SidebarMainPresenter(
hostname, hostname,
new RoomInteractor(new RealmRoomRepository(hostname)), new RoomInteractor(new RealmRoomRepository(hostname)),
userRepository, userRepository,
rocketChatCache,
absoluteUrlHelper, absoluteUrlHelper,
new MethodCallHelper(getContext(), hostname), new MethodCallHelper(getContext(), hostname),
new RealmSpotlightRepository(hostname) new RealmSpotlightRepository(hostname)
......
...@@ -38,7 +38,6 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -38,7 +38,6 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
private final String hostname; private final String hostname;
private final RoomInteractor roomInteractor; private final RoomInteractor roomInteractor;
private final UserRepository userRepository; private final UserRepository userRepository;
private final RocketChatCache rocketChatCache;
private final AbsoluteUrlHelper absoluteUrlHelper; private final AbsoluteUrlHelper absoluteUrlHelper;
private final MethodCallHelper methodCallHelper; private final MethodCallHelper methodCallHelper;
private SpotlightRepository realmSpotlightRepository; private SpotlightRepository realmSpotlightRepository;
...@@ -47,14 +46,12 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -47,14 +46,12 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
public SidebarMainPresenter(String hostname, public SidebarMainPresenter(String hostname,
RoomInteractor roomInteractor, RoomInteractor roomInteractor,
UserRepository userRepository, UserRepository userRepository,
RocketChatCache rocketChatCache,
AbsoluteUrlHelper absoluteUrlHelper, AbsoluteUrlHelper absoluteUrlHelper,
MethodCallHelper methodCallHelper, MethodCallHelper methodCallHelper,
RealmSpotlightRepository realmSpotlightRepository) { RealmSpotlightRepository realmSpotlightRepository) {
this.hostname = hostname; this.hostname = hostname;
this.roomInteractor = roomInteractor; this.roomInteractor = roomInteractor;
this.userRepository = userRepository; this.userRepository = userRepository;
this.rocketChatCache = rocketChatCache;
this.absoluteUrlHelper = absoluteUrlHelper; this.absoluteUrlHelper = absoluteUrlHelper;
this.methodCallHelper = methodCallHelper; this.methodCallHelper = methodCallHelper;
this.realmSpotlightRepository = realmSpotlightRepository; this.realmSpotlightRepository = realmSpotlightRepository;
...@@ -87,7 +84,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -87,7 +84,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
@Override @Override
public void onRoomSelected(RoomSidebar roomSidebar) { public void onRoomSelected(RoomSidebar roomSidebar) {
rocketChatCache.setSelectedRoomId(roomSidebar.getRoomId()); RocketChatCache.INSTANCE.setSelectedRoomId(roomSidebar.getRoomId());
} }
@Override @Override
...@@ -103,7 +100,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -103,7 +100,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
methodCallHelper.createDirectMessage(username) methodCallHelper.createDirectMessage(username)
.continueWithTask(task -> { .continueWithTask(task -> {
if (task.isCompleted()) { if (task.isCompleted()) {
rocketChatCache.setSelectedRoomId(task.getResult()); RocketChatCache.INSTANCE.setSelectedRoomId(task.getResult());
} }
return null; return null;
}); });
...@@ -111,7 +108,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -111,7 +108,7 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
methodCallHelper.joinRoom(spotlight.getId()) methodCallHelper.joinRoom(spotlight.getId())
.continueWithTask(task -> { .continueWithTask(task -> {
if (task.isCompleted()) { if (task.isCompleted()) {
rocketChatCache.setSelectedRoomId(spotlight.getId()); RocketChatCache.INSTANCE.setSelectedRoomId(spotlight.getId());
} }
return null; return null;
}); });
...@@ -157,12 +154,12 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View ...@@ -157,12 +154,12 @@ public class SidebarMainPresenter extends BasePresenter<SidebarMainContract.View
} }
clearSubscriptions(); clearSubscriptions();
String currentHostname = rocketChatCache.getSelectedServerHostname(); String currentHostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname); RealmHelper realmHelper = RealmStore.getOrCreate(currentHostname);
return realmHelper.executeTransaction(realm -> { return realmHelper.executeTransaction(realm -> {
rocketChatCache.removeHostname(currentHostname); RocketChatCache.INSTANCE.removeHostname(currentHostname);
rocketChatCache.removeSelectedRoomId(currentHostname); RocketChatCache.INSTANCE.removeSelectedRoomId(currentHostname);
rocketChatCache.setSelectedServerHostname(rocketChatCache.getFirstLoggedHostnameIfAny()); RocketChatCache.INSTANCE.setSelectedServerHostname(RocketChatCache.INSTANCE.getFirstLoggedHostnameIfAny());
realm.executeTransactionAsync(Realm::deleteAll); realm.executeTransactionAsync(Realm::deleteAll);
view.onPreparedToLogOut(); view.onPreparedToLogOut();
ConnectivityManager.getInstance(RocketChatApplication.getInstance()) ConnectivityManager.getInstance(RocketChatApplication.getInstance())
......
...@@ -48,9 +48,7 @@ public class MessagePopup { ...@@ -48,9 +48,7 @@ public class MessagePopup {
} }
private void showAvailableActionsOnly(Context context) { private void showAvailableActionsOnly(Context context) {
RocketChatCache cache = new RocketChatCache(context.getApplicationContext()); String hostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
String hostname = cache.getSelectedServerHostname();
EditMessageInteractor editMessageInteractor = getEditMessageInteractor(hostname); EditMessageInteractor editMessageInteractor = getEditMessageInteractor(hostname);
...@@ -167,7 +165,7 @@ public class MessagePopup { ...@@ -167,7 +165,7 @@ public class MessagePopup {
} }
public MessagePopup setDeleteAction(ActionListener actionListener) { public MessagePopup setDeleteAction(ActionListener actionListener) {
DELETE_ACTION_INFO.actionListener= actionListener; DELETE_ACTION_INFO.actionListener = actionListener;
return singleton; return singleton;
} }
......
package chat.rocket.android.push package chat.rocket.android.push
import android.annotation.SuppressLint
import android.app.Notification import android.app.Notification
import android.app.NotificationChannel import android.app.NotificationChannel
import android.app.NotificationManager import android.app.NotificationManager
...@@ -137,6 +138,7 @@ object PushManager { ...@@ -137,6 +138,7 @@ object PushManager {
return group return group
} }
@SuppressLint("NewApi")
internal fun showNotification(context: Context, lastPushMessage: PushMessage) { internal fun showNotification(context: Context, lastPushMessage: PushMessage) {
if (lastPushMessage.host == null || lastPushMessage.message == null || lastPushMessage.title == null) { if (lastPushMessage.host == null || lastPushMessage.message == null || lastPushMessage.title == null) {
return return
...@@ -202,7 +204,7 @@ object PushManager { ...@@ -202,7 +204,7 @@ object PushManager {
.setDeleteIntent(deleteIntent) .setDeleteIntent(deleteIntent)
.setMessageNotification() .setMessageNotification()
val subText = RocketChatCache(context).getHostSiteName(host) val subText = RocketChatCache.getHostSiteName(host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
} }
...@@ -257,6 +259,7 @@ object PushManager { ...@@ -257,6 +259,7 @@ object PushManager {
} }
} }
@SuppressLint("NewApi")
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
internal fun createGroupNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification? { internal fun createGroupNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification? {
with(lastPushMessage) { with(lastPushMessage) {
...@@ -289,7 +292,7 @@ object PushManager { ...@@ -289,7 +292,7 @@ object PushManager {
manager.createNotificationChannel(groupChannel) manager.createNotificationChannel(groupChannel)
} }
val subText = RocketChatCache(context).getHostSiteName(host) val subText = RocketChatCache.getHostSiteName(host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
} }
...@@ -344,7 +347,7 @@ object PushManager { ...@@ -344,7 +347,7 @@ object PushManager {
.setContentIntent(contentIntent) .setContentIntent(contentIntent)
.setMessageNotification() .setMessageNotification()
val subText = RocketChatCache(context).getHostSiteName(host) val subText = RocketChatCache.getHostSiteName(host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
} }
...@@ -370,6 +373,7 @@ object PushManager { ...@@ -370,6 +373,7 @@ object PushManager {
} }
} }
@SuppressLint("NewApi")
@RequiresApi(Build.VERSION_CODES.N) @RequiresApi(Build.VERSION_CODES.N)
internal fun createSingleNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification? { internal fun createSingleNotificationForNougatAndAbove(context: Context, lastPushMessage: PushMessage): Notification? {
val manager: NotificationManager = val manager: NotificationManager =
...@@ -404,7 +408,7 @@ object PushManager { ...@@ -404,7 +408,7 @@ object PushManager {
manager.createNotificationChannel(channel) manager.createNotificationChannel(channel)
} }
val subText = RocketChatCache(context).getHostSiteName(host) val subText = RocketChatCache.getHostSiteName(host)
if (subText.isNotEmpty()) { if (subText.isNotEmpty()) {
builder.setSubText(subText) builder.setSubText(subText)
} }
...@@ -647,7 +651,7 @@ object PushManager { ...@@ -647,7 +651,7 @@ object PushManager {
} }
val httpUrl = HttpUrl.parse(pushMessage.host) val httpUrl = HttpUrl.parse(pushMessage.host)
httpUrl?.let { httpUrl?.let {
val siteUrl = RocketChatCache(context).getSiteUrlFor(httpUrl.host()) val siteUrl = RocketChatCache.getSiteUrlFor(httpUrl.host())
if (siteUrl != null) { if (siteUrl != null) {
sendMessage(siteUrl, message, pushMessage.rid) sendMessage(siteUrl, message, pushMessage.rid)
} }
......
...@@ -2,7 +2,6 @@ package chat.rocket.android.service ...@@ -2,7 +2,6 @@ package chat.rocket.android.service
import chat.rocket.android.ConnectionStatusManager import chat.rocket.android.ConnectionStatusManager
import chat.rocket.android.RocketChatApplication import chat.rocket.android.RocketChatApplication
import chat.rocket.android.RocketChatCache
import com.evernote.android.job.Job import com.evernote.android.job.Job
import com.evernote.android.job.JobManager import com.evernote.android.job.JobManager
import com.evernote.android.job.JobRequest import com.evernote.android.job.JobRequest
...@@ -11,7 +10,6 @@ import java.util.concurrent.TimeUnit ...@@ -11,7 +10,6 @@ import java.util.concurrent.TimeUnit
class KeepAliveJob : Job() { class KeepAliveJob : Job() {
private val connectivityManager: ConnectivityManagerApi private val connectivityManager: ConnectivityManagerApi
private val rocketChatCache: RocketChatCache
companion object { companion object {
val TAG = "chat.rocket.android.service.KeepAliveJob" val TAG = "chat.rocket.android.service.KeepAliveJob"
...@@ -38,7 +36,6 @@ class KeepAliveJob : Job() { ...@@ -38,7 +36,6 @@ class KeepAliveJob : Job() {
init { init {
val context = RocketChatApplication.getInstance() val context = RocketChatApplication.getInstance()
connectivityManager = ConnectivityManager.getInstance(context) connectivityManager = ConnectivityManager.getInstance(context)
rocketChatCache = RocketChatCache(context)
} }
override fun onRunJob(params: Params): Result { override fun onRunJob(params: Params): Result {
......
...@@ -74,7 +74,7 @@ import io.reactivex.subjects.BehaviorSubject; ...@@ -74,7 +74,7 @@ import io.reactivex.subjects.BehaviorSubject;
@DebugLog @DebugLog
@Override @Override
public void ensureConnections() { public void ensureConnections() {
String hostname = new RocketChatCache(appContext).getSelectedServerHostname(); String hostname = RocketChatCache.INSTANCE.getSelectedServerHostname();
if (hostname == null) { if (hostname == null) {
return; return;
} }
......
...@@ -106,21 +106,24 @@ public class RocketChatService extends Service implements ConnectivityServiceInt ...@@ -106,21 +106,24 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
} }
if (currentWebSocketThread != null) { if (currentWebSocketThread != null) {
return currentWebSocketThread.terminate(isDisconnected) if (isDisconnected) {
.doAfterTerminate(() -> currentWebSocketThread = null) return currentWebSocketThread.terminate(true)
.flatMap(terminated -> .doAfterTerminate(() -> currentWebSocketThread = null)
RocketChatWebSocketThread.getStarted(getApplicationContext(), hostname) .flatMap(terminated ->
.doOnSuccess(thread -> { RocketChatWebSocketThread.getStarted(getApplicationContext(), hostname)
currentWebSocketThread = thread; .doOnSuccess(thread -> {
webSocketThreadLock.release(); currentWebSocketThread = thread;
}) webSocketThreadLock.release();
.doOnError(throwable -> { })
currentWebSocketThread = null; .doOnError(throwable -> {
RCLog.e(throwable); currentWebSocketThread = null;
Logger.INSTANCE.report(throwable); RCLog.e(throwable);
webSocketThreadLock.release(); Logger.INSTANCE.report(throwable);
}) webSocketThreadLock.release();
); })
);
}
return Single.just(currentWebSocketThread);
} }
return RocketChatWebSocketThread.getStarted(getApplicationContext(), hostname) return RocketChatWebSocketThread.getStarted(getApplicationContext(), hostname)
......
...@@ -13,13 +13,11 @@ import chat.rocket.persistence.realm.models.ddp.RealmRoom; ...@@ -13,13 +13,11 @@ import chat.rocket.persistence.realm.models.ddp.RealmRoom;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
public abstract class AbstractRocketChatCacheObserver implements Registrable { public abstract class AbstractRocketChatCacheObserver implements Registrable {
private final Context context;
private final RealmHelper realmHelper; private final RealmHelper realmHelper;
private String roomId; private String roomId;
private CompositeDisposable compositeDisposable = new CompositeDisposable(); private CompositeDisposable compositeDisposable = new CompositeDisposable();
protected AbstractRocketChatCacheObserver(Context context, RealmHelper realmHelper) { protected AbstractRocketChatCacheObserver(RealmHelper realmHelper) {
this.context = context;
this.realmHelper = realmHelper; this.realmHelper = realmHelper;
} }
...@@ -47,7 +45,7 @@ public abstract class AbstractRocketChatCacheObserver implements Registrable { ...@@ -47,7 +45,7 @@ public abstract class AbstractRocketChatCacheObserver implements Registrable {
@Override @Override
public final void register() { public final void register() {
compositeDisposable.add( compositeDisposable.add(
new RocketChatCache(context) RocketChatCache.INSTANCE
.getSelectedRoomIdPublisher() .getSelectedRoomIdPublisher()
.filter(Optional::isPresent) .filter(Optional::isPresent)
.map(Optional::get) .map(Optional::get)
......
...@@ -13,60 +13,58 @@ import chat.rocket.persistence.realm.RealmHelper; ...@@ -13,60 +13,58 @@ import chat.rocket.persistence.realm.RealmHelper;
* wrapper for managing stream-notify-message depending on RocketChatCache. * wrapper for managing stream-notify-message depending on RocketChatCache.
*/ */
public class StreamRoomMessageManager implements Registrable { public class StreamRoomMessageManager implements Registrable {
private final Context context; private final Context context;
private final String hostname; private final String hostname;
private final RealmHelper realmHelper; private final RealmHelper realmHelper;
private final AbstractRocketChatCacheObserver cacheObserver; private final AbstractRocketChatCacheObserver cacheObserver;
private final Handler handler; private final Handler handler;
private final RocketChatCache rocketChatCache; private StreamRoomMessage streamRoomMessage;
private StreamRoomMessage streamRoomMessage;
public StreamRoomMessageManager(Context context, String hostname, public StreamRoomMessageManager(Context context, String hostname,
RealmHelper realmHelper) { RealmHelper realmHelper) {
this.context = context; this.context = context;
this.hostname = hostname; this.hostname = hostname;
this.realmHelper = realmHelper; this.realmHelper = realmHelper;
this.rocketChatCache = new RocketChatCache(context);
cacheObserver = new AbstractRocketChatCacheObserver(context, realmHelper) { cacheObserver = new AbstractRocketChatCacheObserver(realmHelper) {
@Override @Override
protected void onRoomIdUpdated(String roomId) { protected void onRoomIdUpdated(String roomId) {
unregisterStreamNotifyMessageIfNeeded(); unregisterStreamNotifyMessageIfNeeded();
registerStreamNotifyMessage(roomId); registerStreamNotifyMessage(roomId);
} }
}; };
handler = new Handler(Looper.myLooper()); handler = new Handler(Looper.myLooper());
} }
private void registerStreamNotifyMessage(String roomId) { private void registerStreamNotifyMessage(String roomId) {
handler.post(() -> { handler.post(() -> {
streamRoomMessage = new StreamRoomMessage(context, hostname, realmHelper, roomId); streamRoomMessage = new StreamRoomMessage(context, hostname, realmHelper, roomId);
streamRoomMessage.register(); streamRoomMessage.register();
}); });
} }
private void unregisterStreamNotifyMessageIfNeeded() { private void unregisterStreamNotifyMessageIfNeeded() {
handler.post(() -> { handler.post(() -> {
if (streamRoomMessage != null) { if (streamRoomMessage != null) {
streamRoomMessage.unregister(); streamRoomMessage.unregister();
streamRoomMessage = null; streamRoomMessage = null;
} }
}); });
} }
@Override @Override
public void register() { public void register() {
cacheObserver.register(); cacheObserver.register();
String selectedRoomId = rocketChatCache.getSelectedRoomId(); String selectedRoomId = RocketChatCache.INSTANCE.getSelectedRoomId();
if (selectedRoomId == null) { if (selectedRoomId == null) {
return; return;
}
registerStreamNotifyMessage(selectedRoomId);
} }
registerStreamNotifyMessage(selectedRoomId);
}
@Override @Override
public void unregister() { public void unregister() {
unregisterStreamNotifyMessageIfNeeded(); unregisterStreamNotifyMessageIfNeeded();
cacheObserver.unregister(); cacheObserver.unregister();
} }
} }
...@@ -68,7 +68,7 @@ public class GcmPushRegistrationObserver extends AbstractModelObserver<GcmPushRe ...@@ -68,7 +68,7 @@ public class GcmPushRegistrationObserver extends AbstractModelObserver<GcmPushRe
final RealmUser currentUser = realmHelper.executeTransactionForRead(realm -> final RealmUser currentUser = realmHelper.executeTransactionForRead(realm ->
RealmUser.queryCurrentUser(realm).findFirst()); RealmUser.queryCurrentUser(realm).findFirst());
final String userId = currentUser != null ? currentUser.getId() : null; final String userId = currentUser != null ? currentUser.getId() : null;
final String pushId = new RocketChatCache(context).getOrCreatePushId(); final String pushId = RocketChatCache.INSTANCE.getOrCreatePushId();
return new RaixPushHelper(realmHelper) return new RaixPushHelper(realmHelper)
.pushUpdate(pushId, gcmToken, userId); .pushUpdate(pushId, gcmToken, userId);
......
...@@ -74,7 +74,7 @@ public class SessionObserver extends AbstractModelObserver<RealmSession> { ...@@ -74,7 +74,7 @@ public class SessionObserver extends AbstractModelObserver<RealmSession> {
// update push info // update push info
pushHelper pushHelper
.pushSetUser(new RocketChatCache(context).getOrCreatePushId()) .pushSetUser(RocketChatCache.INSTANCE.getOrCreatePushId())
.continueWith(new LogIfError()); .continueWith(new LogIfError());
ConnectivityManager.getInstance(context).notifySessionEstablished(hostname); ConnectivityManager.getInstance(context).notifySessionEstablished(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