Commit 399dce09 authored by Tiago Cunha's avatar Tiago Cunha Committed by GitHub

Merge pull request #232 from RocketChat/fix/firebase-crashes

Crashes
parents 68232055 a875cca8
......@@ -9,7 +9,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'io.realm:realm-gradle-plugin:2.3.1'
classpath 'io.realm:realm-gradle-plugin:2.3.2'
classpath 'me.tatarka:gradle-retrolambda:3.5.0'
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
classpath 'com.jakewharton.hugo:hugo-plugin:1.2.1'
......
......@@ -41,17 +41,9 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
pair -> close(pair.first, pair.second)
)
.unsubscribeOn(AndroidSchedulers.from(Looper.myLooper()))
.filter(it -> it != null && it.isLoaded()
&& it.isValid())
.map(realmMessages -> {
if (realmMessages.size() > 0) {
return Optional.of(realmMessages.get(0).asMessage());
}
return Optional.<Message>absent();
})
.firstElement()
.toSingle());
.filter(it -> it.isLoaded() && it.isValid() && it.size() > 0)
.map(realmMessages -> Optional.of(realmMessages.get(0).asMessage()))
.first(Optional.absent()));
}
@Override
......@@ -91,7 +83,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
return RxJavaInterop.toV2Flowable(realm.copyToRealmOrUpdate(realmMessage)
.asObservable())
.filter(it -> it != null && it.isLoaded() && it.isValid())
.filter(it -> it.isLoaded() && it.isValid())
.firstElement()
.doOnSuccess(it -> realm.commitTransaction())
.doOnError(throwable -> realm.cancelTransaction())
......@@ -143,8 +135,7 @@ public class RealmMessageRepository extends RealmRepository implements MessageRe
pair -> close(pair.first, pair.second)
)
.unsubscribeOn(AndroidSchedulers.from(Looper.myLooper()))
.filter(it -> it != null
&& it.isLoaded() && it.isValid())
.filter(it -> it.isLoaded() && it.isValid())
.map(this::toList));
}
......
......@@ -131,8 +131,7 @@ public class RealmRoomRepository extends RealmRepository implements RoomReposito
return RxJavaInterop.toV2Flowable(realm.copyToRealmOrUpdate(loadMessage)
.asObservable())
.filter(realmObject -> realmObject != null
&& realmObject.isLoaded() && realmObject.isValid())
.filter(realmObject -> realmObject.isLoaded() && realmObject.isValid())
.firstElement()
.doOnSuccess(it -> realm.commitTransaction())
.doOnError(throwable -> realm.cancelTransaction())
......
......@@ -46,10 +46,15 @@ public class MessageInteractor {
return !roomHistoryState.isComplete()
&& (syncState == SyncState.SYNCED || syncState == SyncState.FAILED);
})
.firstElement()
.toSingle()
.flatMap(roomHistoryState -> roomRepository
.setHistoryState(roomHistoryState.withSyncState(SyncState.NOT_SYNCED)));
.map(Optional::of)
.first(Optional.absent())
.flatMap(historyStateOptional -> {
if (!historyStateOptional.isPresent()) {
return Single.just(false);
}
return roomRepository
.setHistoryState(historyStateOptional.get().withSyncState(SyncState.NOT_SYNCED));
});
}
public Single<Boolean> send(Room destination, User sender, String messageText) {
......
......@@ -32,10 +32,15 @@ public class SessionInteractor {
.map(Optional::get)
.filter(session -> session.getToken() != null
&& (!session.isTokenVerified() || session.getError() != null))
.map(session -> session.withTokenVerified(false).withError(null))
.firstElement()
.toSingle()
.flatMap(sessionRepository::save);
.map(session -> Optional.of(session.withTokenVerified(false).withError(null)))
.first(Optional.absent())
.flatMap(sessionOptional -> {
if (!sessionOptional.isPresent()) {
return Single.just(false);
}
return sessionRepository.save(sessionOptional.get());
});
}
private Session.State getStateFrom(Session session) {
......
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