use of chat.rocket.core.models.RoomHistoryState in project Rocket.Chat.Android by RocketChat.
the class RealmRoomRepository method setHistoryState.
@Override
public Single<Boolean> setHistoryState(RoomHistoryState roomHistoryState) {
return Single.defer(() -> {
final Realm realm = RealmStore.getRealm(hostname);
final Looper looper = Looper.myLooper();
if (realm == null || looper == null) {
return Single.just(false);
}
LoadMessageProcedure loadMessage = new LoadMessageProcedure();
loadMessage.setRoomId(roomHistoryState.getRoomId());
loadMessage.setSyncState(roomHistoryState.getSyncState());
loadMessage.setCount(roomHistoryState.getCount());
loadMessage.setReset(roomHistoryState.isReset());
loadMessage.setHasNext(!roomHistoryState.isComplete());
loadMessage.setTimestamp(roomHistoryState.getTimestamp());
realm.beginTransaction();
return RxJavaInterop.toV2Flowable(realm.copyToRealmOrUpdate(loadMessage).asObservable()).filter(realmObject -> realmObject.isLoaded() && realmObject.isValid()).firstElement().doOnSuccess(it -> realm.commitTransaction()).doOnError(throwable -> realm.cancelTransaction()).doOnEvent((realmObject, throwable) -> close(realm, looper)).toSingle().map(realmObject -> true);
});
}
Aggregations