Improve GroupChatRepo

This commit is contained in:
Paul Schaub 2019-12-22 02:57:24 +01:00
parent d76d0fb2f2
commit 4491df0dd3
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311

View file

@ -76,13 +76,13 @@ public class XmppGroupChatRepository
public Single<GroupChat> getOrCreateGroupChat(Account account, String roomAddress) {
return getGroupChatByRoomAddress(account, roomAddress)
.switchIfEmpty(
Single.just((GroupChat) new IGroupChat() {
{
setAccount(account);
setRoomAddress(roomAddress);
}
})
.flatMap(this::insertGroupChat))
Single.just(new IGroupChat())
.map(chat -> {
chat.setAccount(account);
chat.setRoomAddress(roomAddress);
return chat;
})
.flatMap(this::insertGroupChat))
.subscribeOn(subscriberScheduler())
.observeOn(observerScheduler());
}
@ -109,17 +109,19 @@ public class XmppGroupChatRepository
public Observable<List<GroupChat>> observeAllGroupChats() {
return dao.getAll().observableResult()
.map(ResultDelegate::toList)
.map(list -> {
List<GroupChat> entities = new ArrayList<>(list.size());
for (GroupChatModel model : list) {
entities.add(groupChatMapping.toEntity(model));
}
return entities;
})
.map(this::modelsToEntities)
.subscribeOn(subscriberScheduler())
.observeOn(observerScheduler());
}
private List<GroupChat> modelsToEntities(List<GroupChatModel> models) {
List<GroupChat> entities = new ArrayList<>(models.size());
for (GroupChatModel model : models) {
entities.add(groupChatMapping.toEntity(model));
}
return entities;
}
@Override
public Single<GroupChat> updateGroupChat(GroupChat chat) {
return dao.get(chat.getId()).maybe().toSingle()