StartDM : add tests
This commit is contained in:
+1
-1
@@ -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>
|
||||
|
||||
+3
-5
@@ -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) },
|
||||
|
||||
Reference in New Issue
Block a user