Fix SIP user to native user mapping is wrong #4176 (also clear dialpad entry when call is started)

This commit is contained in:
ganfra 2021-10-06 19:34:04 +02:00
parent 58b69b1fe4
commit 0125c7675d
4 changed files with 31 additions and 14 deletions

1
changelog.d/4176.bugfix Normal file
View file

@ -0,0 +1 @@
SIP user to native user mapping is wrong

View file

@ -170,9 +170,11 @@ class DialPadFragment : Fragment(), TextWatcher {
}
}
private fun clear() {
fun clear() {
if (::digits.isInitialized) {
digits.setText("")
}
}
private fun formatNumber(dialString: String): String {
val networkPortion = PhoneNumberUtils.extractNetworkPortion(dialString)

View file

@ -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 sipUserId = thirdPartyUser.userId
val nativeLookupResults = session.sipNativeLookup(thirdPartyUser.userId)
nativeLookupResults.firstOrNull()?.userId ?: thirdPartyUser.userId
} else {
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
}
if (nativeUserId == session.myUserId) throw Failure.NumberIsYours
val roomId = directRoomHelper.ensureDMExists(nativeUserId)
return Result(userId = nativeUserId, roomId = roomId)
session.getExistingDirectRoomWithUser(nativeUserId)
// if there is not, just create a DM with the sip user
?: directRoomHelper.ensureDMExists(sipUserId)
} else {
// do the same if there is no corresponding native user.
directRoomHelper.ensureDMExists(sipUserId)
}
return Result(userId = sipUserId, roomId = roomId)
}
}

View file

@ -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