StartDM : add tests
This commit is contained in:
parent
e55fab29e4
commit
3efbf4747d
19 changed files with 320 additions and 196 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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) },
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue