mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-26 13:34:50 +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) {
|
public Single<GroupChat> getOrCreateGroupChat(Account account, String roomAddress) {
|
||||||
return getGroupChatByRoomAddress(account, roomAddress)
|
return getGroupChatByRoomAddress(account, roomAddress)
|
||||||
.switchIfEmpty(
|
.switchIfEmpty(
|
||||||
Single.just((GroupChat) new IGroupChat() {
|
Single.just(new IGroupChat())
|
||||||
{
|
.map(chat -> {
|
||||||
setAccount(account);
|
chat.setAccount(account);
|
||||||
setRoomAddress(roomAddress);
|
chat.setRoomAddress(roomAddress);
|
||||||
}
|
return chat;
|
||||||
})
|
})
|
||||||
.flatMap(this::insertGroupChat))
|
.flatMap(this::insertGroupChat))
|
||||||
.subscribeOn(subscriberScheduler())
|
.subscribeOn(subscriberScheduler())
|
||||||
.observeOn(observerScheduler());
|
.observeOn(observerScheduler());
|
||||||
}
|
}
|
||||||
|
@ -109,17 +109,19 @@ public class XmppGroupChatRepository
|
||||||
public Observable<List<GroupChat>> observeAllGroupChats() {
|
public Observable<List<GroupChat>> observeAllGroupChats() {
|
||||||
return dao.getAll().observableResult()
|
return dao.getAll().observableResult()
|
||||||
.map(ResultDelegate::toList)
|
.map(ResultDelegate::toList)
|
||||||
.map(list -> {
|
.map(this::modelsToEntities)
|
||||||
List<GroupChat> entities = new ArrayList<>(list.size());
|
|
||||||
for (GroupChatModel model : list) {
|
|
||||||
entities.add(groupChatMapping.toEntity(model));
|
|
||||||
}
|
|
||||||
return entities;
|
|
||||||
})
|
|
||||||
.subscribeOn(subscriberScheduler())
|
.subscribeOn(subscriberScheduler())
|
||||||
.observeOn(observerScheduler());
|
.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
|
@Override
|
||||||
public Single<GroupChat> updateGroupChat(GroupChat chat) {
|
public Single<GroupChat> updateGroupChat(GroupChat chat) {
|
||||||
return dao.get(chat.getId()).maybe().toSingle()
|
return dao.get(chat.getId()).maybe().toSingle()
|
||||||
|
|
Loading…
Reference in a new issue