Navigate to an existing DM instead of creating a new one.
This commit is contained in:
parent
b4f9d40767
commit
e7714da8e8
|
@ -39,6 +39,7 @@ Improvements 🙌:
|
||||||
- Add graphic resources for F-Droid (#812, #2220)
|
- Add graphic resources for F-Droid (#812, #2220)
|
||||||
- Highlight text in the body of the displayed result (#2200)
|
- Highlight text in the body of the displayed result (#2200)
|
||||||
- Considerably faster QR-code bitmap generation (#2331)
|
- Considerably faster QR-code bitmap generation (#2331)
|
||||||
|
- Open an existing DM instead of creating a new one (#2319)
|
||||||
|
|
||||||
Bugfix 🐛:
|
Bugfix 🐛:
|
||||||
- Fixed ringtone handling (#2100 & #2246)
|
- Fixed ringtone handling (#2100 & #2246)
|
||||||
|
|
|
@ -19,6 +19,7 @@ package im.vector.app.features.createdirect
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.airbnb.mvrx.ActivityViewModelContext
|
import com.airbnb.mvrx.ActivityViewModelContext
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
|
import com.airbnb.mvrx.Success
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import com.squareup.inject.assisted.Assisted
|
import com.squareup.inject.assisted.Assisted
|
||||||
import com.squareup.inject.assisted.AssistedInject
|
import com.squareup.inject.assisted.AssistedInject
|
||||||
|
@ -56,7 +57,30 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
||||||
|
|
||||||
override fun handle(action: CreateDirectRoomAction) {
|
override fun handle(action: CreateDirectRoomAction) {
|
||||||
when (action) {
|
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 New Issue