mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-18 09:34:52 +02:00
Improve GroupChatRepo
This commit is contained in:
parent
d76d0fb2f2
commit
4491df0dd3
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue