Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native lookup fixes #6101

Merged
merged 5 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6101.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor - better naming, return native user id and not sip user id and create a dm with the native user instead of with the sip user.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import im.vector.app.features.call.vectorCallService
import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.createdirect.DirectRoomHelper
import org.matrix.android.sdk.api.session.Session
import timber.log.Timber
import javax.inject.Inject

class DialPadLookup @Inject constructor(
Expand All @@ -42,18 +43,23 @@ class DialPadLookup @Inject constructor(
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()) {
if (nativeLookupResults.isNotEmpty()) {
val nativeUserId = nativeLookupResults.first().userId
if (nativeUserId == session.myUserId) {
throw Failure.NumberIsYours
}
session.roomService().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)
var nativeRoomId = session.roomService().getExistingDirectRoomWithUser(nativeUserId)
if (nativeRoomId == null) {
// if there is no existing native room with the existing native user,
// just create a DM with the native user
nativeRoomId = directRoomHelper.ensureDMExists(nativeUserId)
}
Timber.d("lookupPhoneNumber with nativeUserId: $nativeUserId and nativeRoomId: $nativeRoomId")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An import of Timber is missing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sorry 🙈

return Result(userId = nativeUserId, roomId = nativeRoomId)
}
return Result(userId = sipUserId, roomId = roomId)
// If there is no native user then we return sipUserId and sipRoomId - this is usually a PSTN call.
val sipRoomId = directRoomHelper.ensureDMExists(sipUserId)
Timber.d("lookupPhoneNumber with sipRoomId: $sipRoomId and sipUserId: $sipUserId")
return Result(userId = sipUserId, roomId = sipRoomId)
}
}