Commit a875cca8 authored by Tiago Cunha's avatar Tiago Cunha

Crashes

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