mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:05:28 +00:00
fix: Make Client.findDM return a Result (#4816)
This commit is contained in:
committed by
GitHub
parent
fa2ac28166
commit
07af7cc643
+1
-1
@@ -55,7 +55,7 @@ interface MatrixClient {
|
||||
val ignoredUsersFlow: StateFlow<ImmutableList<UserId>>
|
||||
suspend fun getJoinedRoom(roomId: RoomId): JoinedRoom?
|
||||
suspend fun getRoom(roomId: RoomId): BaseRoom?
|
||||
suspend fun findDM(userId: UserId): RoomId?
|
||||
suspend fun findDM(userId: UserId): Result<RoomId?>
|
||||
suspend fun ignoreUser(userId: UserId): Result<Unit>
|
||||
suspend fun unignoreUser(userId: UserId): Result<Unit>
|
||||
suspend fun createRoom(createRoomParams: CreateRoomParameters): Result<RoomId>
|
||||
|
||||
+17
-10
@@ -18,17 +18,24 @@ suspend fun MatrixClient.startDM(
|
||||
userId: UserId,
|
||||
createIfDmDoesNotExist: Boolean,
|
||||
): StartDMResult {
|
||||
val existingDM = findDM(userId)
|
||||
return if (existingDM != null) {
|
||||
StartDMResult.Success(existingDM, isNew = false)
|
||||
} else if (createIfDmDoesNotExist) {
|
||||
createDM(userId).fold(
|
||||
{ StartDMResult.Success(it, isNew = true) },
|
||||
{ StartDMResult.Failure(it) }
|
||||
return findDM(userId)
|
||||
.fold(
|
||||
onSuccess = { existingDM ->
|
||||
if (existingDM != null) {
|
||||
StartDMResult.Success(existingDM, isNew = false)
|
||||
} else if (createIfDmDoesNotExist) {
|
||||
createDM(userId).fold(
|
||||
{ StartDMResult.Success(it, isNew = true) },
|
||||
{ StartDMResult.Failure(it) }
|
||||
)
|
||||
} else {
|
||||
StartDMResult.DmDoesNotExist
|
||||
}
|
||||
},
|
||||
onFailure = { error ->
|
||||
StartDMResult.Failure(error)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
StartDMResult.DmDoesNotExist
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface StartDMResult {
|
||||
|
||||
Reference in New Issue
Block a user