StartDM : add tests

This commit is contained in:
ganfra 2023-11-30 18:05:26 +01:00
parent e55fab29e4
commit 3efbf4747d
19 changed files with 320 additions and 196 deletions

View file

@ -41,7 +41,7 @@ interface MatrixClient : Closeable {
val roomListService: RoomListService
val mediaLoader: MatrixMediaLoader
suspend fun getRoom(roomId: RoomId): MatrixRoom?
suspend fun findDM(userId: UserId): MatrixRoom?
suspend fun findDM(userId: UserId): RoomId?
suspend fun ignoreUser(userId: UserId): Result<Unit>
suspend fun unignoreUser(userId: UserId): Result<Unit>
suspend fun createRoom(createRoomParams: CreateRoomParameters): Result<RoomId>

View file

@ -24,11 +24,9 @@ import io.element.android.libraries.matrix.api.core.UserId
* Try to find an existing DM with the given user, or create one if none exists.
*/
suspend fun MatrixClient.startDM(userId: UserId): StartDMResult {
val existingRoomId = findDM(userId)?.use { existingDM ->
existingDM.roomId
}
return if (existingRoomId != null) {
StartDMResult.Success(existingRoomId, isNew = false)
val existingDM = findDM(userId)
return if (existingDM != null) {
StartDMResult.Success(existingDM, isNew = false)
} else {
createDM(userId).fold(
{ StartDMResult.Success(it, isNew = true) },