mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 10:55:55 +03:00
Navigate to an existing DM instead of creating a new one.
This commit is contained in:
parent
b4f9d40767
commit
e7714da8e8
2 changed files with 26 additions and 1 deletions
|
@ -39,6 +39,7 @@ Improvements 🙌:
|
|||
- Add graphic resources for F-Droid (#812, #2220)
|
||||
- Highlight text in the body of the displayed result (#2200)
|
||||
- Considerably faster QR-code bitmap generation (#2331)
|
||||
- Open an existing DM instead of creating a new one (#2319)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fixed ringtone handling (#2100 & #2246)
|
||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.app.features.createdirect
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import com.airbnb.mvrx.ActivityViewModelContext
|
||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||
import com.airbnb.mvrx.Success
|
||||
import com.airbnb.mvrx.ViewModelContext
|
||||
import com.squareup.inject.assisted.Assisted
|
||||
import com.squareup.inject.assisted.AssistedInject
|
||||
|
@ -56,7 +57,30 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
|||
|
||||
override fun handle(action: CreateDirectRoomAction) {
|
||||
when (action) {
|
||||
is CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers -> createRoomAndInviteSelectedUsers(action.invitees)
|
||||
is CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers -> onSubmitInvitees(action.invitees)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If users already have a DM room then navigate to it instead of creating a new room.
|
||||
*/
|
||||
private fun onSubmitInvitees(invitees: Set<PendingInvitee>) {
|
||||
invitees
|
||||
.takeIf { it.size == 1 }
|
||||
?.first()
|
||||
?.let { invitee ->
|
||||
when (invitee) {
|
||||
is PendingInvitee.UserPendingInvitee -> session.getExistingDirectRoomWithUser(invitee.user.userId)
|
||||
is PendingInvitee.ThreePidPendingInvitee -> null
|
||||
}.exhaustive
|
||||
}
|
||||
?.let { roomId ->
|
||||
setState {
|
||||
copy(createAndInviteState = Success(roomId))
|
||||
}
|
||||
}
|
||||
?: run {
|
||||
createRoomAndInviteSelectedUsers(invitees)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue