Room navigation : more reliable roomInfoFlow method
This commit is contained in:
@@ -30,14 +30,13 @@ import io.element.android.libraries.architecture.Presenter
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoomInfo
|
||||
import java.util.Optional
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
class JoinRoomPresenter @AssistedInject constructor(
|
||||
@Assisted private val roomId: RoomId,
|
||||
private val matrixClient: MatrixClient,
|
||||
private val roomListService: RoomListService,
|
||||
private val acceptDeclineInvitePresenter: AcceptDeclineInvitePresenter,
|
||||
) : Presenter<JoinRoomState> {
|
||||
|
||||
@@ -47,23 +46,24 @@ class JoinRoomPresenter @AssistedInject constructor(
|
||||
|
||||
@Composable
|
||||
override fun present(): JoinRoomState {
|
||||
val userMembership by roomListService.getUserMembershipForRoom(roomId).collectAsState(initial = Optional.empty())
|
||||
val joinAuthorisationStatus = joinAuthorisationStatus(userMembership)
|
||||
val mxRoomInfo by matrixClient.getRoomInfoFlow(roomId).collectAsState(initial = Optional.empty())
|
||||
val joinAuthorisationStatus = joinAuthorisationStatus(mxRoomInfo)
|
||||
val acceptDeclineInviteState = acceptDeclineInvitePresenter.present()
|
||||
val roomInfo by produceState<AsyncData<RoomInfo>>(initialValue = AsyncData.Uninitialized, key1 = userMembership) {
|
||||
val roomInfo by produceState<AsyncData<RoomInfo>>(initialValue = AsyncData.Uninitialized, key1 = mxRoomInfo) {
|
||||
value = when {
|
||||
userMembership.isPresent -> {
|
||||
val roomInfo = matrixClient.getRoom(roomId)?.use {
|
||||
mxRoomInfo.isPresent -> {
|
||||
val roomInfo = mxRoomInfo.get().let {
|
||||
RoomInfo(
|
||||
roomId = it.roomId,
|
||||
roomName = it.displayName,
|
||||
roomAlias = it.alias,
|
||||
memberCount = it.activeMemberCount,
|
||||
roomId = roomId,
|
||||
roomName = it.name,
|
||||
roomAlias = it.canonicalAlias,
|
||||
memberCount = it.activeMembersCount,
|
||||
isDirect = it.isDirect,
|
||||
topic = it.topic,
|
||||
roomAvatarUrl = it.avatarUrl
|
||||
)
|
||||
}
|
||||
roomInfo?.let { AsyncData.Success(it) } ?: AsyncData.Failure(Exception("Failed to load room info"))
|
||||
AsyncData.Success(roomInfo)
|
||||
}
|
||||
else -> AsyncData.Uninitialized
|
||||
}
|
||||
@@ -103,9 +103,10 @@ class JoinRoomPresenter @AssistedInject constructor(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun joinAuthorisationStatus(userMembership: Optional<CurrentUserMembership>): JoinAuthorisationStatus {
|
||||
private fun joinAuthorisationStatus(roomInfo: Optional<MatrixRoomInfo>): JoinAuthorisationStatus {
|
||||
val userMembership = roomInfo.getOrNull()?.currentUserMembership
|
||||
return when {
|
||||
userMembership.getOrNull() == CurrentUserMembership.INVITED -> return JoinAuthorisationStatus.IsInvited
|
||||
userMembership == CurrentUserMembership.INVITED -> return JoinAuthorisationStatus.IsInvited
|
||||
else -> JoinAuthorisationStatus.Unknown
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,15 +29,16 @@ data class JoinRoomState(
|
||||
val joinAuthorisationStatus: JoinAuthorisationStatus,
|
||||
val acceptDeclineInviteState: AcceptDeclineInviteState,
|
||||
val eventSink: (JoinRoomEvents) -> Unit
|
||||
){
|
||||
) {
|
||||
val showMemberCount = roomInfo.dataOrNull()?.memberCount != null
|
||||
}
|
||||
|
||||
data class RoomInfo(
|
||||
val roomId: RoomId,
|
||||
val roomName: String,
|
||||
val roomName: String?,
|
||||
val roomAlias: String?,
|
||||
val memberCount: Long?,
|
||||
val topic: String?,
|
||||
val isDirect: Boolean,
|
||||
val roomAvatarUrl: String?,
|
||||
) {
|
||||
|
||||
@@ -48,6 +48,7 @@ fun aJoinRoomState(
|
||||
roomAlias = "#exa:matrix.org",
|
||||
memberCount = null,
|
||||
isDirect = false,
|
||||
topic = null,
|
||||
roomAvatarUrl = null
|
||||
)
|
||||
),
|
||||
|
||||
@@ -203,7 +203,11 @@ private fun JoinRoomTopBar(
|
||||
when (asyncRoomInfo) {
|
||||
is AsyncData.Success -> {
|
||||
val roomInfo = asyncRoomInfo.data
|
||||
RoomAvatarAndNameRow(roomName = roomInfo.roomName, roomAvatar = roomInfo.avatarData(AvatarSize.TimelineRoom))
|
||||
if(roomInfo.roomName == null){
|
||||
IconTitlePlaceholdersRowMolecule(iconSize = AvatarSize.TimelineRoom.dp)
|
||||
}else {
|
||||
RoomAvatarAndNameRow(roomName = roomInfo.roomName, roomAvatar = roomInfo.avatarData(AvatarSize.TimelineRoom))
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
IconTitlePlaceholdersRowMolecule(iconSize = AvatarSize.TimelineRoom.dp)
|
||||
|
||||
@@ -40,7 +40,6 @@ object JoinRoomModule {
|
||||
return JoinRoomPresenter(
|
||||
roomId = roomId,
|
||||
matrixClient = client,
|
||||
roomListService = roomListService,
|
||||
acceptDeclineInvitePresenter = acceptDeclineInvitePresenter,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class RoomListDataSource @Inject constructor(
|
||||
fun launchIn(coroutineScope: CoroutineScope) {
|
||||
roomListService
|
||||
.allRooms
|
||||
.summaries
|
||||
.filteredSummaries
|
||||
.onEach { roomSummaries ->
|
||||
replaceWith(roomSummaries)
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class RoomListSearchDataSource @Inject constructor(
|
||||
source = RoomList.Source.All,
|
||||
)
|
||||
|
||||
val roomSummaries: Flow<PersistentList<RoomListRoomSummary>> = roomList.summaries
|
||||
val roomSummaries: Flow<PersistentList<RoomListRoomSummary>> = roomList.filteredSummaries
|
||||
.map { roomSummaries ->
|
||||
roomSummaries
|
||||
.filterIsInstance<RoomSummary.Filled>()
|
||||
|
||||
Reference in New Issue
Block a user