diff --git a/changelog.d/4176.bugfix b/changelog.d/4176.bugfix new file mode 100644 index 0000000000..6134dfca7c --- /dev/null +++ b/changelog.d/4176.bugfix @@ -0,0 +1 @@ +SIP user to native user mapping is wrong \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt index 5e2a569188..16e7c01b5c 100644 --- a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt +++ b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadFragment.kt @@ -170,8 +170,10 @@ class DialPadFragment : Fragment(), TextWatcher { } } - private fun clear() { - digits.setText("") + fun clear() { + if (::digits.isInitialized) { + digits.setText("") + } } private fun formatNumber(dialString: String): String { diff --git a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt index d256156d15..eadccab4f6 100644 --- a/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt +++ b/vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt @@ -39,15 +39,21 @@ class DialPadLookup @Inject constructor( suspend fun lookupPhoneNumber(phoneNumber: String): Result { session.vectorCallService.protocolChecker.awaitCheckProtocols() val thirdPartyUser = session.pstnLookup(phoneNumber, webRtcCallManager.supportedPSTNProtocol).firstOrNull() ?: throw Failure.NoResult - // check to see if this is a virtual user, in which case we should find the native user - val nativeUserId = if (webRtcCallManager.supportsVirtualRooms) { - val nativeLookupResults = session.sipNativeLookup(thirdPartyUser.userId) - nativeLookupResults.firstOrNull()?.userId ?: thirdPartyUser.userId + val sipUserId = thirdPartyUser.userId + val nativeLookupResults = session.sipNativeLookup(thirdPartyUser.userId) + // If I have a native user I check for an existing native room with him... + val roomId = if (nativeLookupResults.isNotEmpty()) { + val nativeUserId = nativeLookupResults.first().userId + if (nativeUserId == session.myUserId) { + throw Failure.NumberIsYours + } + session.getExistingDirectRoomWithUser(nativeUserId) + // if there is not, just create a DM with the sip user + ?: directRoomHelper.ensureDMExists(sipUserId) } else { - thirdPartyUser.userId + // do the same if there is no corresponding native user. + directRoomHelper.ensureDMExists(sipUserId) } - if (nativeUserId == session.myUserId) throw Failure.NumberIsYours - val roomId = directRoomHelper.ensureDMExists(nativeUserId) - return Result(userId = nativeUserId, roomId = roomId) + return Result(userId = sipUserId, roomId = roomId) } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt index 627f4b4581..24677cf940 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeDetailFragment.kt @@ -155,7 +155,7 @@ class HomeDetailFragment @Inject constructor( viewModel.observeViewEvents { viewEvent -> when (viewEvent) { - HomeDetailViewEvents.CallStarted -> dismissLoadingDialog() + HomeDetailViewEvents.CallStarted -> handleCallStarted() is HomeDetailViewEvents.FailToCall -> showFailure(viewEvent.failure) HomeDetailViewEvents.Loading -> showLoadingDialog() } @@ -190,10 +190,16 @@ class HomeDetailFragment @Inject constructor( sharedCallActionViewModel .liveKnownCalls - .observe(viewLifecycleOwner, { + .observe(viewLifecycleOwner) { currentCallsViewPresenter.updateCall(callManager.getCurrentCall(), callManager.getCalls()) invalidateOptionsMenu() - }) + } + } + + private fun handleCallStarted() { + dismissLoadingDialog() + val fragmentTag = HomeTab.DialPad.toFragmentTag() + (childFragmentManager.findFragmentByTag(fragmentTag) as? DialPadFragment)?.clear() } override fun onDestroyView() { @@ -370,8 +376,10 @@ class HomeDetailFragment @Inject constructor( invalidateOptionsMenu() } + private fun HomeTab.toFragmentTag() = "FRAGMENT_TAG_$this" + private fun updateSelectedFragment(tab: HomeTab) { - val fragmentTag = "FRAGMENT_TAG_$tab" + val fragmentTag = tab.toFragmentTag() val fragmentToShow = childFragmentManager.findFragmentByTag(fragmentTag) childFragmentManager.commitTransaction { childFragmentManager.fragments