Readability improvements XmppPeerRepository

This commit is contained in:
Paul Schaub 2019-12-22 02:36:38 +01:00
parent c165d7a633
commit 7606a3c351
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -24,6 +24,9 @@ import io.reactivex.Observable;
import io.reactivex.Scheduler; import io.reactivex.Scheduler;
import io.reactivex.Single; import io.reactivex.Single;
import io.requery.Persistable; import io.requery.Persistable;
import io.requery.query.Conditional;
import io.requery.query.Expression;
import io.requery.query.LogicalCondition;
import io.requery.query.ResultDelegate; import io.requery.query.ResultDelegate;
import io.requery.reactivex.ReactiveEntityStore; import io.requery.reactivex.ReactiveEntityStore;
@ -139,8 +142,7 @@ public class XmppPeerRepository
public Observable<List<Peer>> observeAllContactsOfAccount(UUID accountId) { public Observable<List<Peer>> observeAllContactsOfAccount(UUID accountId) {
return data().select(PeerModel.class) return data().select(PeerModel.class)
.where(PeerModel.ACCOUNT_ID.eq(accountId)) .where(PeerModel.ACCOUNT_ID.eq(accountId))
.and(PeerModel.SUBSCRIPTION_DIRECTION.in( .and(isContact())
Arrays.asList(SubscriptionDirection.both, SubscriptionDirection.to)))
.get().observableResult() .get().observableResult()
.map(ResultDelegate::toList) .map(ResultDelegate::toList)
.map(peerModels -> { .map(peerModels -> {
@ -154,6 +156,12 @@ public class XmppPeerRepository
.observeOn(observerScheduler()); .observeOn(observerScheduler());
} }
private LogicalCondition<? extends Expression<SubscriptionDirection>, ?> isContact() {
return PeerModel.SUBSCRIPTION_DIRECTION.in(Arrays.asList(
SubscriptionDirection.both,
SubscriptionDirection.to));
}
@Override @Override
public Single<Peer> updatePeer(Peer peer) { public Single<Peer> updatePeer(Peer peer) {
// In order to update, we fetch the model, update it and write it back. // In order to update, we fetch the model, update it and write it back.