mirror of
https://github.com/element-hq/element-android
synced 2024-11-22 09:25:33 +03:00
Use a DataSrouce instead of a Task and return a non Optional Boolean.
This commit is contained in:
parent
f278e2884a
commit
e75070be91
7 changed files with 35 additions and 45 deletions
|
@ -53,10 +53,10 @@ class FlowRoom(private val room: Room) {
|
|||
}
|
||||
}
|
||||
|
||||
fun liveAreAllMembersLoaded(): Flow<Optional<Boolean>> {
|
||||
fun liveAreAllMembersLoaded(): Flow<Boolean> {
|
||||
return room.membershipService().areAllMembersLoadedLive().asFlow()
|
||||
.startWith(room.coroutineDispatchers.io) {
|
||||
room.membershipService().areAllMembersLoaded().toOptional()
|
||||
room.membershipService().areAllMembersLoaded()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ interface MembershipService {
|
|||
/**
|
||||
* Live version for [areAllMembersLoaded].
|
||||
*/
|
||||
fun areAllMembersLoadedLive(): LiveData<Optional<Boolean>>
|
||||
fun areAllMembersLoadedLive(): LiveData<Boolean>
|
||||
|
||||
/**
|
||||
* Return the roomMember with userId or null.
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
@ -14,32 +14,42 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.matrix.android.sdk.internal.session.room.membership
|
||||
package org.matrix.android.sdk.internal.session.room
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import io.realm.Realm
|
||||
import org.matrix.android.sdk.api.extensions.orFalse
|
||||
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
import javax.inject.Inject
|
||||
|
||||
internal interface GetRoomMembersLoadStatusTask : Task<GetRoomMembersLoadStatusTask.Params, RoomMembersLoadStatusType> {
|
||||
data class Params(
|
||||
val roomId: String,
|
||||
)
|
||||
}
|
||||
|
||||
internal class DefaultGetRoomMembersLoadStatusTask @Inject constructor(
|
||||
internal class RoomDataSource @Inject constructor(
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
) : GetRoomMembersLoadStatusTask {
|
||||
|
||||
override suspend fun execute(params: GetRoomMembersLoadStatusTask.Params): RoomMembersLoadStatusType {
|
||||
) {
|
||||
fun getRoomMembersLoadStatus(roomId: String): RoomMembersLoadStatusType {
|
||||
var result: RoomMembersLoadStatusType?
|
||||
Realm.getInstance(monarchy.realmConfiguration).use {
|
||||
result = RoomEntity.where(it, params.roomId).findFirst()?.membersLoadStatus
|
||||
result = RoomEntity.where(it, roomId).findFirst()?.membersLoadStatus
|
||||
}
|
||||
return result ?: RoomMembersLoadStatusType.NONE
|
||||
}
|
||||
|
||||
fun getRoomMembersLoadStatusLive(roomId: String): LiveData<Boolean> {
|
||||
val liveData = monarchy.findAllMappedWithChanges(
|
||||
{
|
||||
RoomEntity.where(it, roomId)
|
||||
},
|
||||
{
|
||||
it.membersLoadStatus == RoomMembersLoadStatusType.LOADED
|
||||
}
|
||||
)
|
||||
|
||||
return Transformations.map(liveData) { results ->
|
||||
results.firstOrNull().orFalse()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,9 +59,7 @@ import org.matrix.android.sdk.internal.session.room.location.SendLiveLocationTas
|
|||
import org.matrix.android.sdk.internal.session.room.location.SendStaticLocationTask
|
||||
import org.matrix.android.sdk.internal.session.room.location.StartLiveLocationShareTask
|
||||
import org.matrix.android.sdk.internal.session.room.location.StopLiveLocationShareTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.DefaultGetRoomMembersLoadStatusTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.DefaultLoadRoomMembersTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.GetRoomMembersLoadStatusTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.LoadRoomMembersTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.admin.DefaultMembershipAdminTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.admin.MembershipAdminTask
|
||||
|
@ -229,9 +227,6 @@ internal abstract class RoomModule {
|
|||
@Binds
|
||||
abstract fun bindLoadRoomMembersTask(task: DefaultLoadRoomMembersTask): LoadRoomMembersTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindGetRoomMembersLoadStatusTask(task: DefaultGetRoomMembersLoadStatusTask): GetRoomMembersLoadStatusTask
|
||||
|
||||
@Binds
|
||||
abstract fun bindSetReadMarkersTask(task: DefaultSetReadMarkersTask): SetReadMarkersTask
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
package org.matrix.android.sdk.internal.session.room.membership
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Transformations
|
||||
import com.zhuinden.monarchy.Monarchy
|
||||
import dagger.assisted.Assisted
|
||||
import dagger.assisted.AssistedFactory
|
||||
|
@ -29,18 +28,15 @@ import org.matrix.android.sdk.api.session.room.members.MembershipService
|
|||
import org.matrix.android.sdk.api.session.room.members.RoomMemberQueryParams
|
||||
import org.matrix.android.sdk.api.session.room.model.Membership
|
||||
import org.matrix.android.sdk.api.session.room.model.RoomMemberSummary
|
||||
import org.matrix.android.sdk.api.util.Optional
|
||||
import org.matrix.android.sdk.api.util.toOptional
|
||||
import org.matrix.android.sdk.internal.database.mapper.asDomain
|
||||
import org.matrix.android.sdk.internal.database.model.RoomEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntity
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMemberSummaryEntityFields
|
||||
import org.matrix.android.sdk.internal.database.model.RoomMembersLoadStatusType
|
||||
import org.matrix.android.sdk.internal.database.query.where
|
||||
import org.matrix.android.sdk.internal.di.SessionDatabase
|
||||
import org.matrix.android.sdk.internal.di.UserId
|
||||
import org.matrix.android.sdk.internal.query.QueryStringValueProcessor
|
||||
import org.matrix.android.sdk.internal.query.process
|
||||
import org.matrix.android.sdk.internal.session.room.RoomDataSource
|
||||
import org.matrix.android.sdk.internal.session.room.membership.admin.MembershipAdminTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.joining.InviteTask
|
||||
import org.matrix.android.sdk.internal.session.room.membership.threepid.InviteThreePidTask
|
||||
|
@ -53,7 +49,7 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
private val inviteTask: InviteTask,
|
||||
private val inviteThreePidTask: InviteThreePidTask,
|
||||
private val membershipAdminTask: MembershipAdminTask,
|
||||
private val getRoomMembersLoadStatusTask: GetRoomMembersLoadStatusTask,
|
||||
private val roomDataSource: RoomDataSource,
|
||||
@UserId
|
||||
private val userId: String,
|
||||
private val queryStringValueProcessor: QueryStringValueProcessor
|
||||
|
@ -70,23 +66,12 @@ internal class DefaultMembershipService @AssistedInject constructor(
|
|||
}
|
||||
|
||||
override suspend fun areAllMembersLoaded(): Boolean {
|
||||
val status = getRoomMembersLoadStatusTask.execute(GetRoomMembersLoadStatusTask.Params(roomId))
|
||||
val status = roomDataSource.getRoomMembersLoadStatus(roomId)
|
||||
return status == RoomMembersLoadStatusType.LOADED
|
||||
}
|
||||
|
||||
override fun areAllMembersLoadedLive(): LiveData<Optional<Boolean>> {
|
||||
val liveData = monarchy.findAllMappedWithChanges(
|
||||
{
|
||||
RoomEntity.where(it, roomId)
|
||||
},
|
||||
{
|
||||
it.membersLoadStatus == RoomMembersLoadStatusType.LOADED
|
||||
}
|
||||
)
|
||||
|
||||
return Transformations.map(liveData) { results ->
|
||||
results.firstOrNull().toOptional()
|
||||
}
|
||||
override fun areAllMembersLoadedLive(): LiveData<Boolean> {
|
||||
return roomDataSource.getRoomMembersLoadStatusLive(roomId)
|
||||
}
|
||||
|
||||
override fun getRoomMember(userId: String): RoomMemberSummary? {
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.matrix.android.sdk.internal.di.SessionDatabase
|
|||
import org.matrix.android.sdk.internal.network.GlobalErrorReceiver
|
||||
import org.matrix.android.sdk.internal.network.executeRequest
|
||||
import org.matrix.android.sdk.internal.session.room.RoomAPI
|
||||
import org.matrix.android.sdk.internal.session.room.RoomDataSource
|
||||
import org.matrix.android.sdk.internal.session.room.summary.RoomSummaryUpdater
|
||||
import org.matrix.android.sdk.internal.session.sync.SyncTokenStore
|
||||
import org.matrix.android.sdk.internal.task.Task
|
||||
|
@ -56,7 +57,7 @@ internal interface LoadRoomMembersTask : Task<LoadRoomMembersTask.Params, Unit>
|
|||
internal class DefaultLoadRoomMembersTask @Inject constructor(
|
||||
private val roomAPI: RoomAPI,
|
||||
@SessionDatabase private val monarchy: Monarchy,
|
||||
private val getRoomMembersLoadStatusTask: GetRoomMembersLoadStatusTask,
|
||||
private val roomDataSource: RoomDataSource,
|
||||
private val syncTokenStore: SyncTokenStore,
|
||||
private val roomSummaryUpdater: RoomSummaryUpdater,
|
||||
private val roomMemberEventHandler: RoomMemberEventHandler,
|
||||
|
@ -67,7 +68,7 @@ internal class DefaultLoadRoomMembersTask @Inject constructor(
|
|||
) : LoadRoomMembersTask {
|
||||
|
||||
override suspend fun execute(params: LoadRoomMembersTask.Params) {
|
||||
when (getRoomMembersLoadStatusTask.execute(GetRoomMembersLoadStatusTask.Params(params.roomId))) {
|
||||
when (roomDataSource.getRoomMembersLoadStatus(params.roomId)) {
|
||||
RoomMembersLoadStatusType.NONE -> doRequest(params)
|
||||
RoomMembersLoadStatusType.LOADING -> waitPreviousRequestToFinish(params)
|
||||
RoomMembersLoadStatusType.LOADED -> Unit
|
||||
|
|
|
@ -97,7 +97,6 @@ class RoomMemberListViewModel @AssistedInject constructor(
|
|||
}
|
||||
|
||||
roomFlow.liveAreAllMembersLoaded()
|
||||
.unwrap()
|
||||
.distinctUntilChanged()
|
||||
.onEach {
|
||||
setState {
|
||||
|
|
Loading…
Reference in a new issue