Commit 4535d9ee authored by Leonardo Aramaki's avatar Leonardo Aramaki

Return a default empty PublicSetting if server does not provide any

parent b69d908b
...@@ -5,6 +5,9 @@ import android.support.v4.util.Pair; ...@@ -5,6 +5,9 @@ import android.support.v4.util.Pair;
import com.hadisatrio.optional.Optional; import com.hadisatrio.optional.Optional;
import javax.annotation.Nullable;
import chat.rocket.core.PublicSettingsConstants;
import chat.rocket.core.models.PublicSetting; import chat.rocket.core.models.PublicSetting;
import chat.rocket.core.repositories.PublicSettingRepository; import chat.rocket.core.repositories.PublicSettingRepository;
import chat.rocket.persistence.realm.RealmStore; import chat.rocket.persistence.realm.RealmStore;
...@@ -31,6 +34,7 @@ public class RealmPublicSettingRepository extends RealmRepository ...@@ -31,6 +34,7 @@ public class RealmPublicSettingRepository extends RealmRepository
if (pair.first == null) { if (pair.first == null) {
return Flowable.empty(); return Flowable.empty();
} }
return pair.first.where(RealmPublicSetting.class) return pair.first.where(RealmPublicSetting.class)
.equalTo(RealmPublicSetting.ID, id) .equalTo(RealmPublicSetting.ID, id)
.findAll() .findAll()
...@@ -39,8 +43,19 @@ public class RealmPublicSettingRepository extends RealmRepository ...@@ -39,8 +43,19 @@ public class RealmPublicSettingRepository extends RealmRepository
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.isLoaded() && it.isValid() && it.size() > 0) .filter(it -> it.isLoaded() && it.isValid())
.map(it -> Optional.of(it.get(0).asPublicSetting())) .map(it -> {
if (it.size() > 0) {
return Optional.of(it.get(0).asPublicSetting());
}
PublicSetting defaultSetting = PublicSetting.builder()
.setId(id)
.setValue("")
.setUpdatedAt(0L)
.build();
return Optional.of(defaultSetting);
})
.first(Optional.absent())); .first(Optional.absent()));
} }
} }
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