use of chat.rocket.core.models.Session in project Rocket.Chat.Android by RocketChat.
the class RealmSessionRepository method save.
@Override
public Single<Boolean> save(Session session) {
return Single.defer(() -> {
final Realm realm = RealmStore.getRealm(hostname);
final Looper looper = Looper.myLooper();
if (realm == null || looper == null) {
return Single.just(false);
}
RealmSession realmSession = realm.where(RealmSession.class).equalTo(RealmSession.ID, session.getSessionId()).findFirst();
if (realmSession == null) {
realmSession = new RealmSession();
} else {
realmSession = realm.copyFromRealm(realmSession);
}
realmSession.setSessionId(session.getSessionId());
realmSession.setToken(session.getToken());
realmSession.setTokenVerified(session.isTokenVerified());
realmSession.setError(session.getError());
realm.beginTransaction();
return RxJavaInterop.toV2Flowable(realm.copyToRealmOrUpdate(realmSession).asObservable()).filter(it -> it != null && it.isLoaded() && it.isValid()).firstElement().doOnSuccess(it -> realm.commitTransaction()).doOnError(throwable -> realm.cancelTransaction()).doOnEvent((realmObject, throwable) -> close(realm, looper)).toSingle().map(realmObject -> true);
});
}
use of chat.rocket.core.models.Session in project Rocket.Chat.Android by RocketChat.
the class MainPresenter method subscribeToSession.
private void subscribeToSession() {
final Disposable subscription = sessionInteractor.getDefault().subscribeOn(AndroidSchedulers.from(BackgroundLooper.get())).observeOn(AndroidSchedulers.mainThread()).subscribe(sessionOptional -> {
Session session = sessionOptional.orNull();
if (session == null || session.getToken() == null) {
view.showLoginScreen();
return;
}
String error = session.getError();
if (error != null && error.length() != 0) {
view.showConnectionError();
return;
}
if (!session.isTokenVerified()) {
view.showConnecting();
return;
}
view.showConnectionOk();
}, Logger::report);
addSubscription(subscription);
}
use of chat.rocket.core.models.Session in project Rocket.Chat.Android by RocketChat.
the class RetryLoginPresenter method onSession.
private void onSession(Optional<Session> sessionOptional) {
if (!sessionOptional.isPresent()) {
return;
}
final Session session = sessionOptional.get();
final String token = session.getToken();
if (!TextUtils.isEmpty(token)) {
view.showRetry(token);
}
final String errorMessage = session.getError();
if (!TextUtils.isEmpty(errorMessage)) {
view.showError(errorMessage);
}
}
Aggregations