Update SDK version to 25.03.13 and fix breaking changes (#4406)

Breaking changes addressed:
* Make `MatrixClient.getNotificationSettings()` async, cache its result.
* Use `RoomInfo` for accessing the updated room's info.
* Refactor `MatrixRoom` so it always receives an initial `MatrixRoomInfo` value: this value will be used to make `MatrixRoom.roomInfoFlow` a `StateFlow` so we can assume the initial updated Room data will be present.
* Fetch encryption state when loading a room if it's unknown
This commit is contained in:
Jorge Martin Espinosa 2025-03-19 12:52:57 +01:00 committed by GitHub
parent 0c07a8165f
commit fccd881b1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 647 additions and 431 deletions

View file

@ -40,11 +40,12 @@ fun getRoomMemberAsState(roomMembersState: MatrixRoomMembersState, userId: UserI
@Composable
fun MatrixRoom.getDirectRoomMember(roomMembersState: MatrixRoomMembersState): State<RoomMember?> {
val roomMembers = roomMembersState.roomMembers()
return remember(roomMembersState) {
val roomInfo by roomInfoFlow.collectAsState()
return remember(roomMembersState, roomInfo.isDirect) {
derivedStateOf {
roomMembers
?.filter { it.membership.isActive() }
?.takeIf { it.size == 2 && isDirect }
?.takeIf { it.size == 2 && roomInfo.isDirect == true }
?.find { it.userId != sessionId }
}
}

View file

@ -67,9 +67,9 @@ fun MatrixRoom.canPinUnpin(updateKey: Long): State<Boolean> {
}
@Composable
fun MatrixRoom.isDmAsState(updateKey: Long): State<Boolean> {
return produceState(initialValue = false, key1 = updateKey) {
value = isDm
fun MatrixRoom.isDmAsState(): State<Boolean> {
return produceState(initialValue = false) {
roomInfoFlow.collect { value = it.isDm }
}
}
@ -105,25 +105,25 @@ fun MatrixRoom.userPowerLevelAsState(updateKey: Long): State<Long> {
@Composable
fun MatrixRoom.isOwnUserAdmin(): Boolean {
val roomInfo by roomInfoFlow.collectAsState(initial = null)
val powerLevel = roomInfo?.userPowerLevels?.get(sessionId) ?: 0L
val roomInfo by roomInfoFlow.collectAsState()
val powerLevel = roomInfo.userPowerLevels[sessionId] ?: 0L
return RoomMember.Role.forPowerLevel(powerLevel) == RoomMember.Role.ADMIN
}
@Composable
fun MatrixRoom.rawName(): String? {
val roomInfo by roomInfoFlow.collectAsState(initial = null)
return roomInfo?.rawName
val roomInfo by roomInfoFlow.collectAsState()
return roomInfo.rawName
}
@Composable
fun MatrixRoom.topic(): String? {
val roomInfo by roomInfoFlow.collectAsState(initial = null)
return roomInfo?.topic
val roomInfo by roomInfoFlow.collectAsState()
return roomInfo.topic
}
@Composable
fun MatrixRoom.avatarUrl(): String? {
val roomInfo by roomInfoFlow.collectAsState(initial = null)
return roomInfo?.avatarUrl
val roomInfo by roomInfoFlow.collectAsState()
return roomInfo.avatarUrl
}

View file

@ -30,10 +30,10 @@ import kotlinx.coroutines.flow.onEach
@OptIn(ExperimentalCoroutinesApi::class)
fun MatrixRoom.roomMemberIdentityStateChange(): Flow<ImmutableList<RoomMemberIdentityStateChange>> {
return syncUpdateFlow
return roomInfoFlow
.filter {
// Room cannot become unencrypted, so we can just apply a filter here.
isEncrypted
it.isEncrypted == true
}
.distinctUntilChanged()
.flatMapLatest {

View file

@ -17,6 +17,7 @@ import io.element.android.libraries.matrix.test.A_USER_ID
import io.element.android.libraries.matrix.test.A_USER_ID_2
import io.element.android.libraries.matrix.test.A_USER_ID_3
import io.element.android.libraries.matrix.test.room.FakeMatrixRoom
import io.element.android.libraries.matrix.test.room.aRoomInfo
import io.element.android.libraries.matrix.test.room.aRoomMember
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.test.runTest
@ -31,8 +32,10 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emits other member for encrypted DM with 2 joined members`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = true,
initialRoomInfo = aRoomInfo(
isDirect = true,
joinedMembersCount = 2,
)
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
@ -47,8 +50,7 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emit null if the room is not a dm`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = false,
initialRoomInfo = aRoomInfo(isDirect = false)
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
@ -63,8 +65,10 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emits other member even if the room is not encrypted`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = false,
isDirect = true,
initialRoomInfo = aRoomInfo(
isDirect = true,
activeMembersCount = 2,
)
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
@ -79,8 +83,7 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emit null if the room has only 1 member`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = true,
initialRoomInfo = aRoomInfo(isDirect = true)
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
@ -95,9 +98,9 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emit null if the room has only 3 members`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = true,
)
).apply {
givenRoomInfo(aRoomInfo(isDirect = true))
}
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
MatrixRoomMembersState.Ready(persistentListOf(roomMember1, roomMember2, roomMember3))
@ -111,8 +114,7 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emit null if the other member is not active`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = true,
initialRoomInfo = aRoomInfo(isDirect = true),
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(
@ -132,8 +134,10 @@ class MatrixRoomMembersTest {
fun `getDirectRoomMember emit the other member if there are 2 active members`() = runTest {
val matrixRoom = FakeMatrixRoom(
sessionId = A_USER_ID,
isEncrypted = true,
isDirect = true,
initialRoomInfo = aRoomInfo(
isDirect = true,
activeMembersCount = 2,
)
)
moleculeFlow(RecompositionMode.Immediate) {
matrixRoom.getDirectRoomMember(