@@ -22,6 +22,7 @@ import im.vector.app.features.call.vectorCallService
22
22
import im.vector.app.features.call.webrtc.WebRtcCallManager
23
23
import im.vector.app.features.createdirect.DirectRoomHelper
24
24
import org.matrix.android.sdk.api.session.Session
25
+ import timber.log.Timber
25
26
import javax.inject.Inject
26
27
27
28
class DialPadLookup @Inject constructor(
@@ -42,18 +43,23 @@ class DialPadLookup @Inject constructor(
42
43
val sipUserId = thirdPartyUser.userId
43
44
val nativeLookupResults = session.sipNativeLookup(thirdPartyUser.userId)
44
45
// 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()) {
46
47
val nativeUserId = nativeLookupResults.first().userId
47
48
if (nativeUserId == session.myUserId) {
48
49
throw Failure .NumberIsYours
49
50
}
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)
56
59
}
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)
58
64
}
59
65
}
0 commit comments