Skip to content

Commit 6fda2cc

Browse files
authored
Merge pull request #6101 from chagai95/native-lookup-fixes
Native lookup fixes
2 parents 80b9482 + c2707d4 commit 6fda2cc

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

changelog.d/6101.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

vector/src/main/java/im/vector/app/features/call/dialpad/DialPadLookup.kt

+14-8
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import im.vector.app.features.call.vectorCallService
2222
import im.vector.app.features.call.webrtc.WebRtcCallManager
2323
import im.vector.app.features.createdirect.DirectRoomHelper
2424
import org.matrix.android.sdk.api.session.Session
25+
import timber.log.Timber
2526
import javax.inject.Inject
2627

2728
class DialPadLookup @Inject constructor(
@@ -42,18 +43,23 @@ class DialPadLookup @Inject constructor(
4243
val sipUserId = thirdPartyUser.userId
4344
val nativeLookupResults = session.sipNativeLookup(thirdPartyUser.userId)
4445
// If I have a native user I check for an existing native room with him...
45-
val roomId = if (nativeLookupResults.isNotEmpty()) {
46+
if (nativeLookupResults.isNotEmpty()) {
4647
val nativeUserId = nativeLookupResults.first().userId
4748
if (nativeUserId == session.myUserId) {
4849
throw Failure.NumberIsYours
4950
}
50-
session.roomService().getExistingDirectRoomWithUser(nativeUserId)
51-
// if there is not, just create a DM with the sip user
52-
?: directRoomHelper.ensureDMExists(sipUserId)
53-
} else {
54-
// do the same if there is no corresponding native user.
55-
directRoomHelper.ensureDMExists(sipUserId)
51+
var nativeRoomId = session.roomService().getExistingDirectRoomWithUser(nativeUserId)
52+
if (nativeRoomId == null) {
53+
// if there is no existing native room with the existing native user,
54+
// just create a DM with the native user
55+
nativeRoomId = directRoomHelper.ensureDMExists(nativeUserId)
56+
}
57+
Timber.d("lookupPhoneNumber with nativeUserId: $nativeUserId and nativeRoomId: $nativeRoomId")
58+
return Result(userId = nativeUserId, roomId = nativeRoomId)
5659
}
57-
return Result(userId = sipUserId, roomId = roomId)
60+
// If there is no native user then we return sipUserId and sipRoomId - this is usually a PSTN call.
61+
val sipRoomId = directRoomHelper.ensureDMExists(sipUserId)
62+
Timber.d("lookupPhoneNumber with sipRoomId: $sipRoomId and sipUserId: $sipUserId")
63+
return Result(userId = sipUserId, roomId = sipRoomId)
5864
}
5965
}

0 commit comments

Comments
 (0)