Fix not being able to decline an invite from the room list (#3466)
* Add `InvitedRoom` to wrap Rust SDK Rooms in 'invited' membership state. At the moment, this is a wrapper that allows us to call `Room.leave()` without having to initialise the room's timeline (which is impossible). * Add `MatrixRoom.getInvitedRoom(roomId)` to get one of these rooms. Also, `RustRoomFactory` now has a `createInvitedRoom` method for this. * Adapt `AcceptDeclineInvitePresenter` to use the new APIs.
This commit is contained in:
parent
764692b90b
commit
7238af7f7f
9 changed files with 122 additions and 15 deletions
|
|
@ -29,6 +29,7 @@ import io.element.android.libraries.matrix.api.notificationsettings.Notification
|
|||
import io.element.android.libraries.matrix.api.oidc.AccountManagementAction
|
||||
import io.element.android.libraries.matrix.api.pusher.PushersService
|
||||
import io.element.android.libraries.matrix.api.room.CurrentUserMembership
|
||||
import io.element.android.libraries.matrix.api.room.InvitedRoom
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoomInfo
|
||||
import io.element.android.libraries.matrix.api.room.RoomMembershipObserver
|
||||
|
|
@ -245,6 +246,10 @@ class RustMatrixClient(
|
|||
return roomFactory.create(roomId)
|
||||
}
|
||||
|
||||
override suspend fun getInvitedRoom(roomId: RoomId): InvitedRoom? {
|
||||
return roomFactory.createInvitedRoom(roomId)
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait for the room to be available in the room list, with a membership for the current user of [CurrentUserMembership.JOINED].
|
||||
* @param roomIdOrAlias the room id or alias to wait for
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2024 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
* Please see LICENSE in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.matrix.impl.room
|
||||
|
||||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.api.room.InvitedRoom
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
|
||||
class RustInvitedRoom(
|
||||
override val sessionId: SessionId,
|
||||
private val invitedRoom: Room,
|
||||
) : InvitedRoom {
|
||||
override val roomId = RoomId(invitedRoom.id())
|
||||
|
||||
override suspend fun declineInvite(): Result<Unit> = runCatching {
|
||||
invitedRoom.leave()
|
||||
}
|
||||
|
||||
override fun close() {
|
||||
invitedRoom.destroy()
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ import io.element.android.libraries.matrix.api.core.DeviceId
|
|||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.matrix.api.notificationsettings.NotificationSettingsService
|
||||
import io.element.android.libraries.matrix.api.room.InvitedRoom
|
||||
import io.element.android.libraries.matrix.api.room.MatrixRoom
|
||||
import io.element.android.libraries.matrix.api.roomlist.RoomListService
|
||||
import io.element.android.libraries.matrix.api.roomlist.awaitLoaded
|
||||
|
|
@ -27,6 +28,7 @@ import kotlinx.coroutines.sync.Mutex
|
|||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.matrix.rustcomponents.sdk.FilterTimelineEventType
|
||||
import org.matrix.rustcomponents.sdk.Membership
|
||||
import org.matrix.rustcomponents.sdk.Room
|
||||
import org.matrix.rustcomponents.sdk.RoomListException
|
||||
import org.matrix.rustcomponents.sdk.RoomListItem
|
||||
|
|
@ -123,6 +125,33 @@ class RustRoomFactory(
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun createInvitedRoom(roomId: RoomId): InvitedRoom? = withContext(dispatcher) {
|
||||
if (isDestroyed) {
|
||||
Timber.d("Room factory is destroyed, returning null for $roomId")
|
||||
return@withContext null
|
||||
}
|
||||
val roomListItem = innerRoomListService.roomOrNull(roomId.value)
|
||||
if (roomListItem == null) {
|
||||
Timber.d("Room not found for $roomId")
|
||||
return@withContext null
|
||||
}
|
||||
if (roomListItem.membership() != Membership.INVITED) {
|
||||
Timber.d("Room $roomId is not in invited state")
|
||||
return@withContext null
|
||||
}
|
||||
val invitedRoom = try {
|
||||
roomListItem.invitedRoom()
|
||||
} catch (e: RoomListException) {
|
||||
Timber.e(e, "Failed to get invited room for $roomId")
|
||||
return@withContext null
|
||||
}
|
||||
|
||||
RustInvitedRoom(
|
||||
sessionId = sessionId,
|
||||
invitedRoom = invitedRoom,
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun getRoomReferences(roomId: RoomId): RustRoomReferences? {
|
||||
cache[roomId]?.let {
|
||||
Timber.d("Room found in cache for $roomId")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue