mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-28 14:08:44 +03:00
Cleanup after rebase - avoid computing twice the existing roomId
This commit is contained in:
parent
458b4259fe
commit
12d8bd1743
8 changed files with 36 additions and 38 deletions
|
@ -5,7 +5,7 @@ Features ✨:
|
|||
-
|
||||
|
||||
Improvements 🙌:
|
||||
-
|
||||
- Open an existing DM instead of creating a new one (#2319)
|
||||
|
||||
Bugfix 🐛:
|
||||
- Fix issue when updating the avatar of a room
|
||||
|
@ -39,7 +39,6 @@ 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)
|
||||
|
|
|
@ -20,5 +20,8 @@ import im.vector.app.core.platform.VectorViewModelAction
|
|||
import im.vector.app.features.userdirectory.PendingInvitee
|
||||
|
||||
sealed class CreateDirectRoomAction : VectorViewModelAction {
|
||||
data class CreateRoomAndInviteSelectedUsers(val invitees: Set<PendingInvitee>) : CreateDirectRoomAction()
|
||||
data class CreateRoomAndInviteSelectedUsers(
|
||||
val invitees: Set<PendingInvitee>,
|
||||
val existingDmRoomId: String?
|
||||
) : CreateDirectRoomAction()
|
||||
}
|
||||
|
|
|
@ -122,7 +122,10 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() {
|
|||
|
||||
private fun onMenuItemSelected(action: UserDirectorySharedAction.OnMenuItemSelected) {
|
||||
if (action.itemId == R.id.action_create_direct_room) {
|
||||
viewModel.handle(CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers(action.invitees))
|
||||
viewModel.handle(CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers(
|
||||
action.invitees,
|
||||
action.existingDmRoomId
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,31 +57,23 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
|||
|
||||
override fun handle(action: CreateDirectRoomAction) {
|
||||
when (action) {
|
||||
is CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers -> onSubmitInvitees(action.invitees)
|
||||
}
|
||||
is CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers -> onSubmitInvitees(action)
|
||||
}.exhaustive
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
}
|
||||
private fun onSubmitInvitees(action: CreateDirectRoomAction.CreateRoomAndInviteSelectedUsers) {
|
||||
if (action.existingDmRoomId != null) {
|
||||
// Do not create a new DM, just tell that the creation is successful by passing the existing roomId
|
||||
setState {
|
||||
copy(createAndInviteState = Success(action.existingDmRoomId))
|
||||
}
|
||||
} else {
|
||||
// Create the DM
|
||||
createRoomAndInviteSelectedUsers(action.invitees)
|
||||
}
|
||||
}
|
||||
|
||||
private fun createRoomAndInviteSelectedUsers(invitees: Set<PendingInvitee>) {
|
||||
|
|
|
@ -92,7 +92,7 @@ class KnownUsersFragment @Inject constructor(
|
|||
menu.forEach { menuItem ->
|
||||
menuItem.isVisible = showMenuItem
|
||||
if (args.isCreatingRoom) {
|
||||
menuItem.setTitle(if (it.isThereAnExistingRoom) R.string.action_open else R.string.create_room_action_create)
|
||||
menuItem.setTitle(if (it.existingDmRoomId != null) R.string.action_open else R.string.create_room_action_create)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,11 @@ class KnownUsersFragment @Inject constructor(
|
|||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean = withState(viewModel) {
|
||||
sharedActionViewModel.post(UserDirectorySharedAction.OnMenuItemSelected(item.itemId, it.pendingInvitees))
|
||||
sharedActionViewModel.post(UserDirectorySharedAction.OnMenuItemSelected(
|
||||
item.itemId,
|
||||
it.pendingInvitees,
|
||||
it.existingDmRoomId
|
||||
))
|
||||
return@withState true
|
||||
}
|
||||
|
||||
|
|
|
@ -23,5 +23,7 @@ sealed class UserDirectorySharedAction : VectorSharedAction {
|
|||
object OpenPhoneBook : UserDirectorySharedAction()
|
||||
object Close : UserDirectorySharedAction()
|
||||
object GoBack : UserDirectorySharedAction()
|
||||
data class OnMenuItemSelected(val itemId: Int, val invitees: Set<PendingInvitee>) : UserDirectorySharedAction()
|
||||
data class OnMenuItemSelected(val itemId: Int,
|
||||
val invitees: Set<PendingInvitee>,
|
||||
val existingDmRoomId: String?) : UserDirectorySharedAction()
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
|
|||
setState {
|
||||
copy(
|
||||
pendingInvitees = selectedUsers,
|
||||
isThereAnExistingRoom = isThereAnExistingRoom(selectedUsers)
|
||||
existingDmRoomId = getExistingDmRoomId(selectedUsers)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -102,22 +102,17 @@ class UserDirectoryViewModel @AssistedInject constructor(@Assisted
|
|||
setState {
|
||||
copy(
|
||||
pendingInvitees = selectedUsers,
|
||||
isThereAnExistingRoom = isThereAnExistingRoom(selectedUsers)
|
||||
existingDmRoomId = getExistingDmRoomId(selectedUsers)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isThereAnExistingRoom(selectedUsers: Set<PendingInvitee>): Boolean {
|
||||
private fun getExistingDmRoomId(selectedUsers: Set<PendingInvitee>): String? {
|
||||
return selectedUsers
|
||||
.takeIf { it.size == 1 }
|
||||
?.filterIsInstance(PendingInvitee.UserPendingInvitee::class.java)
|
||||
?.firstOrNull()
|
||||
?.let { invitee ->
|
||||
return when (invitee) {
|
||||
is PendingInvitee.UserPendingInvitee -> session.getExistingDirectRoomWithUser(invitee.user.userId) != null
|
||||
is PendingInvitee.ThreePidPendingInvitee -> false
|
||||
}.exhaustive
|
||||
}
|
||||
?: false
|
||||
?.let { invitee -> session.getExistingDirectRoomWithUser(invitee.user.userId) }
|
||||
}
|
||||
|
||||
private fun observeDirectoryUsers() = withState { state ->
|
||||
|
|
|
@ -31,7 +31,7 @@ data class UserDirectoryViewState(
|
|||
val createAndInviteState: Async<String> = Uninitialized,
|
||||
val directorySearchTerm: String = "",
|
||||
val filterKnownUsersValue: Option<String> = Option.empty(),
|
||||
val isThereAnExistingRoom: Boolean = false
|
||||
val existingDmRoomId: String? = null
|
||||
) : MvRxState {
|
||||
|
||||
constructor(args: KnownUsersFragmentArgs) : this(excludedUserIds = args.excludedUserIds)
|
||||
|
|
Loading…
Reference in a new issue