Skip to content

Commit

Permalink
Fix SIP user to native user mapping is wrong #4176 (also clear dialpa…
Browse files Browse the repository at this point in the history
…d entry when call is started)
  • Loading branch information
ganfra committed Oct 6, 2021
1 parent 58b69b1 commit 0125c76
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/4176.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SIP user to native user mapping is wrong
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0125c76

Please sign in to comment.