Search in sources :

Example 1 with Session

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);
    });
}
Also used : Realm(io.realm.Realm) Flowable(io.reactivex.Flowable) SessionRepository(chat.rocket.core.repositories.SessionRepository) RealmSession(chat.rocket.persistence.realm.models.internal.RealmSession) Optional(com.fernandocejas.arrow.optional.Optional) Pair(android.support.v4.util.Pair) Looper(android.os.Looper) Session(chat.rocket.core.models.Session) RxJavaInterop(hu.akarnokd.rxjava.interop.RxJavaInterop) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) RealmStore(chat.rocket.persistence.realm.RealmStore) Looper(android.os.Looper) RealmSession(chat.rocket.persistence.realm.models.internal.RealmSession) Realm(io.realm.Realm)

Example 2 with Session

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);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Logger(chat.rocket.android.helper.Logger) Session(chat.rocket.core.models.Session)

Example 3 with Session

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);
    }
}
Also used : Session(chat.rocket.core.models.Session)

Aggregations

Session (chat.rocket.core.models.Session)3 Looper (android.os.Looper)1 Pair (android.support.v4.util.Pair)1 Logger (chat.rocket.android.helper.Logger)1 SessionRepository (chat.rocket.core.repositories.SessionRepository)1 RealmStore (chat.rocket.persistence.realm.RealmStore)1 RealmSession (chat.rocket.persistence.realm.models.internal.RealmSession)1 Optional (com.fernandocejas.arrow.optional.Optional)1 RxJavaInterop (hu.akarnokd.rxjava.interop.RxJavaInterop)1 Flowable (io.reactivex.Flowable)1 Single (io.reactivex.Single)1 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)1 Disposable (io.reactivex.disposables.Disposable)1 Realm (io.realm.Realm)1