RoomMemberDetailsPresenter: fallback to user profile data if the user is not a member of the room.
This can be displayed when the user click on a non-member user permalink.
This commit is contained in:
parent
87298803c6
commit
bec65c46fc
1 changed files with 24 additions and 10 deletions
|
|
@ -21,7 +21,6 @@ import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.MutableState
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.produceState
|
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
|
|
@ -37,6 +36,7 @@ import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
import io.element.android.libraries.matrix.api.core.RoomId
|
import io.element.android.libraries.matrix.api.core.RoomId
|
||||||
import io.element.android.libraries.matrix.api.core.UserId
|
import io.element.android.libraries.matrix.api.core.UserId
|
||||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||||
|
import io.element.android.libraries.matrix.api.user.MatrixUser
|
||||||
import io.element.android.libraries.matrix.ui.room.getRoomMemberAsState
|
import io.element.android.libraries.matrix.ui.room.getRoomMemberAsState
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
|
@ -60,6 +60,7 @@ class RoomMemberDetailsPresenter @AssistedInject constructor(
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
var confirmationDialog by remember { mutableStateOf<ConfirmationDialog?>(null) }
|
var confirmationDialog by remember { mutableStateOf<ConfirmationDialog?>(null) }
|
||||||
val roomMember by room.getRoomMemberAsState(roomMemberId)
|
val roomMember by room.getRoomMemberAsState(roomMemberId)
|
||||||
|
var userProfile by remember { mutableStateOf<MatrixUser?>(null) }
|
||||||
val startDmActionState: MutableState<AsyncAction<RoomId>> = remember { mutableStateOf(AsyncAction.Uninitialized) }
|
val startDmActionState: MutableState<AsyncAction<RoomId>> = remember { mutableStateOf(AsyncAction.Uninitialized) }
|
||||||
val isBlocked: MutableState<AsyncData<Boolean>> = remember { mutableStateOf(AsyncData.Uninitialized) }
|
val isBlocked: MutableState<AsyncData<Boolean>> = remember { mutableStateOf(AsyncData.Uninitialized) }
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
|
|
@ -74,6 +75,9 @@ class RoomMemberDetailsPresenter @AssistedInject constructor(
|
||||||
// We don't need to assign the result as it will be automatically propagated by `room.getRoomMemberAsState`
|
// We don't need to assign the result as it will be automatically propagated by `room.getRoomMemberAsState`
|
||||||
room.getUpdatedMember(roomMemberId)
|
room.getUpdatedMember(roomMemberId)
|
||||||
}
|
}
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
userProfile = client.getProfile(roomMemberId).getOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
fun handleEvents(event: RoomMemberDetailsEvents) {
|
fun handleEvents(event: RoomMemberDetailsEvents) {
|
||||||
when (event) {
|
when (event) {
|
||||||
|
|
@ -108,16 +112,26 @@ class RoomMemberDetailsPresenter @AssistedInject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val userName by produceState(initialValue = roomMember?.displayName) {
|
var userName: String? by remember { mutableStateOf(roomMember?.displayName ?: userProfile?.displayName) }
|
||||||
room.userDisplayName(roomMemberId).onSuccess { displayName ->
|
LaunchedEffect(roomMember, userProfile) {
|
||||||
if (displayName != null) value = displayName
|
userName = room.userDisplayName(roomMemberId)
|
||||||
}
|
.fold(
|
||||||
|
onSuccess = { it },
|
||||||
|
onFailure = {
|
||||||
|
// Fallback to user profile
|
||||||
|
userProfile?.displayName
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
val userAvatar by produceState(initialValue = roomMember?.avatarUrl) {
|
var userAvatar: String? by remember { mutableStateOf(roomMember?.avatarUrl ?: userProfile?.avatarUrl) }
|
||||||
room.userAvatarUrl(roomMemberId).onSuccess { avatarUrl ->
|
LaunchedEffect(roomMember, userProfile) {
|
||||||
if (avatarUrl != null) value = avatarUrl
|
userAvatar = room.userAvatarUrl(roomMemberId)
|
||||||
}
|
.fold(
|
||||||
|
onSuccess = { it },
|
||||||
|
onFailure = {
|
||||||
|
// Fallback to user profile
|
||||||
|
userProfile?.avatarUrl
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return RoomMemberDetailsState(
|
return RoomMemberDetailsState(
|
||||||
|
|
@ -127,7 +141,7 @@ class RoomMemberDetailsPresenter @AssistedInject constructor(
|
||||||
isBlocked = isBlocked.value,
|
isBlocked = isBlocked.value,
|
||||||
startDmActionState = startDmActionState.value,
|
startDmActionState = startDmActionState.value,
|
||||||
displayConfirmationDialog = confirmationDialog,
|
displayConfirmationDialog = confirmationDialog,
|
||||||
isCurrentUser = client.isMe(roomMember?.userId),
|
isCurrentUser = client.isMe(roomMemberId),
|
||||||
eventSink = ::handleEvents
|
eventSink = ::handleEvents
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue