Rx: fetch first before returning live data results

This commit is contained in:
ganfra 2020-01-07 18:15:07 +01:00
parent 42c7421b05
commit 38c198fe02
5 changed files with 45 additions and 3 deletions

View file

@ -35,10 +35,12 @@ class RxRoom(private val room: Room) {
fun liveRoomMembers(memberships: List<Membership>): Observable<List<RoomMember>> {
return room.getRoomMembersLive(memberships).asObservable()
.startWith(room.getRoomMembers(memberships))
}
fun liveAnnotationSummary(eventId: String): Observable<Optional<EventAnnotationsSummary>> {
return room.getEventSummaryLive(eventId).asObservable()
return room.getEventAnnotationsSummaryLive(eventId).asObservable()
.startWith(room.getEventAnnotationsSummary(eventId).toOptional())
}
fun liveTimelineEvent(eventId: String): Observable<Optional<TimelineEvent>> {

View file

@ -41,6 +41,14 @@ interface MembershipService {
*/
fun getRoomMember(userId: String): RoomMember?
/**
* Return all the roomMembers of the room filtered by memberships
* @param memberships list of accepted memberships
* @return a roomMember list.
*/
fun getRoomMembers(memberships: List<Membership>): List<RoomMember>
/**
* Return all the roomMembers of the room filtered by memberships
* @param memberships list of accepted memberships

View file

@ -108,5 +108,17 @@ interface RelationService {
replyText: CharSequence,
autoMarkdown: Boolean = false): Cancelable?
fun getEventSummaryLive(eventId: String): LiveData<Optional<EventAnnotationsSummary>>
/**
* Get the current EventAnnotationsSummary
* @param eventId the eventId to look for EventAnnotationsSummary
* @return the EventAnnotationsSummary found
*/
fun getEventAnnotationsSummary(eventId: String): EventAnnotationsSummary?
/**
* Get the a LiveData EventAnnotationsSummary
* @param eventId the eventId to look for EventAnnotationsSummary
* @return the LiveData of EventAnnotationsSummary
*/
fun getEventAnnotationsSummaryLive(eventId: String): LiveData<Optional<EventAnnotationsSummary>>
}

View file

@ -64,6 +64,17 @@ internal class DefaultMembershipService @AssistedInject constructor(@Assisted pr
return roomMemberEntity?.asDomain()
}
override fun getRoomMembers(memberships: List<Membership>): List<RoomMember> {
return monarchy.fetchAllMappedSync(
{
RoomMembers(it, roomId).queryRoomMembersEvent()
},
{
it.asDomain()
}
)
}
override fun getRoomMembersLive(memberships: List<Membership>): LiveData<List<RoomMember>> {
return monarchy.findAllMappedWithChanges(
{

View file

@ -215,7 +215,16 @@ internal class DefaultRelationService @AssistedInject constructor(@Assisted priv
return TimelineSendEventWorkCommon.createWork<SendEventWorker>(sendWorkData, startChain)
}
override fun getEventSummaryLive(eventId: String): LiveData<Optional<EventAnnotationsSummary>> {
override fun getEventAnnotationsSummary(eventId: String): EventAnnotationsSummary? {
return monarchy.fetchCopyMap(
{ EventAnnotationsSummaryEntity.where(it, eventId).findFirst() },
{ entity, _ ->
entity.asDomain()
}
)
}
override fun getEventAnnotationsSummaryLive(eventId: String): LiveData<Optional<EventAnnotationsSummary>> {
val liveData = monarchy.findAllMappedWithChanges(
{ EventAnnotationsSummaryEntity.where(it, eventId) },
{ it.asDomain() }