From f8157043380233050c836107f3a3654b5915228a Mon Sep 17 00:00:00 2001 From: Sylvain Berfini Date: Thu, 27 May 2021 11:24:35 +0200 Subject: [PATCH] When calling back from history, try to use the address that received/initiated the original call as From --- .../history/adapters/CallLogsListAdapter.kt | 7 +++-- .../fragments/DetailCallLogFragment.kt | 6 +++-- .../fragments/MasterCallLogsFragment.kt | 10 ++++--- .../history/viewmodels/CallLogViewModel.kt | 6 ++--- .../viewmodels/CallLogsListViewModel.kt | 6 +++-- .../java/org/linphone/core/CoreContext.kt | 27 +++++++++++++------ 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt b/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt index abb878d8f..b937bb6fa 100644 --- a/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt +++ b/app/src/main/java/org/linphone/activities/main/history/adapters/CallLogsListAdapter.kt @@ -33,7 +33,6 @@ import org.linphone.activities.main.adapters.SelectionListAdapter import org.linphone.activities.main.history.data.GroupedCallLogData import org.linphone.activities.main.history.viewmodels.CallLogViewModel import org.linphone.activities.main.viewmodels.ListTopBarViewModel -import org.linphone.core.Address import org.linphone.databinding.GenericListHeaderBinding import org.linphone.databinding.HistoryListCellBinding import org.linphone.utils.* @@ -46,8 +45,8 @@ class CallLogsListAdapter( MutableLiveData>() } - val startCallToEvent: MutableLiveData> by lazy { - MutableLiveData>() + val startCallToEvent: MutableLiveData> by lazy { + MutableLiveData>() } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { @@ -86,7 +85,7 @@ class CallLogsListAdapter( if (selectionViewModel.isEditionEnabled.value == true) { selectionViewModel.onToggleSelect(adapterPosition) } else { - startCallToEvent.value = Event(callLogGroup.lastCallLog.remoteAddress) + startCallToEvent.value = Event(callLogGroup) } } diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt index 5db564bb6..401a53301 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/DetailCallLogFragment.kt @@ -94,7 +94,8 @@ class DetailCallLogFragment : GenericFragment() { } viewModel.startCallEvent.observe(viewLifecycleOwner, { - it.consume { address -> + it.consume { callLog -> + val address = callLog.remoteAddress if (coreContext.core.callsNb > 0) { Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") val args = Bundle() @@ -103,7 +104,8 @@ class DetailCallLogFragment : GenericFragment() { args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it navigateToDialer(args) } else { - coreContext.startCall(address) + val localAddress = callLog.localAddress + coreContext.startCall(address, localAddress = localAddress) } } }) diff --git a/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt b/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt index fa7e44bdb..5b6a232d2 100644 --- a/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt +++ b/app/src/main/java/org/linphone/activities/main/history/fragments/MasterCallLogsFragment.kt @@ -164,16 +164,18 @@ class MasterCallLogsFragment : MasterFragment + it.consume { callLogGroup -> + val remoteAddress = callLogGroup.lastCallLog.remoteAddress if (coreContext.core.callsNb > 0) { - Log.i("[History] Starting dialer with pre-filled URI ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") + Log.i("[History] Starting dialer with pre-filled URI ${remoteAddress.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}") val args = Bundle() - args.putString("URI", address.asStringUriOnly()) + args.putString("URI", remoteAddress.asStringUriOnly()) args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it navigateToDialer(args) } else { - coreContext.startCall(address) + val localAddress = callLogGroup.lastCallLog.localAddress + coreContext.startCall(remoteAddress, localAddress = localAddress) } } }) diff --git a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt index b4f0c00dd..0b8b74d32 100644 --- a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogViewModel.kt @@ -97,8 +97,8 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r TimestampUtils.toString(callLog.startDate, shortDate = false, hideYear = false) } - val startCallEvent: MutableLiveData> by lazy { - MutableLiveData>() + val startCallEvent: MutableLiveData> by lazy { + MutableLiveData>() } val chatRoomCreatedEvent: MutableLiveData> by lazy { @@ -139,7 +139,7 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r } fun startCall() { - startCallEvent.value = Event(callLog.remoteAddress) + startCallEvent.value = Event(callLog) } fun startChat(isSecured: Boolean) { diff --git a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt index b7c9a1185..0849096be 100644 --- a/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt +++ b/app/src/main/java/org/linphone/activities/main/history/viewmodels/CallLogsListViewModel.kt @@ -102,7 +102,8 @@ class CallLogsListViewModel : ViewModel() { for (callLog in coreContext.core.callLogs) { if (previousCallLogGroup == null) { previousCallLogGroup = GroupedCallLogData(callLog) - } else if (previousCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && previousCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { + } else if (previousCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && + previousCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { if (TimestampUtils.isSameDay(previousCallLogGroup.lastCallLog.startDate, callLog.startDate)) { previousCallLogGroup.callLogs.add(callLog) previousCallLogGroup.lastCallLog = callLog @@ -118,7 +119,8 @@ class CallLogsListViewModel : ViewModel() { if (LinphoneUtils.isCallLogMissed(callLog)) { if (previousMissedCallLogGroup == null) { previousMissedCallLogGroup = GroupedCallLogData(callLog) - } else if (previousMissedCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && previousMissedCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { + } else if (previousMissedCallLogGroup.lastCallLog.localAddress.weakEqual(callLog.localAddress) && + previousMissedCallLogGroup.lastCallLog.remoteAddress.weakEqual(callLog.remoteAddress)) { if (TimestampUtils.isSameDay(previousMissedCallLogGroup.lastCallLog.startDate, callLog.startDate)) { previousMissedCallLogGroup.callLogs.add(callLog) previousMissedCallLogGroup.lastCallLog = callLog diff --git a/app/src/main/java/org/linphone/core/CoreContext.kt b/app/src/main/java/org/linphone/core/CoreContext.kt index d64f5bc7b..6bf079662 100644 --- a/app/src/main/java/org/linphone/core/CoreContext.kt +++ b/app/src/main/java/org/linphone/core/CoreContext.kt @@ -470,7 +470,7 @@ class CoreContext(val context: Context, coreConfig: Config) { startCall(address) } - fun startCall(address: Address, forceZRTP: Boolean = false) { + fun startCall(address: Address, forceZRTP: Boolean = false, localAddress: Address? = null) { if (!core.isNetworkReachable) { Log.e("[Context] Network unreachable, abort outgoing call") callErrorMessageResourceId.value = Event(context.getString(R.string.call_error_network_unreachable)) @@ -478,20 +478,31 @@ class CoreContext(val context: Context, coreConfig: Config) { } val params = core.createCallParams(null) + if (params == null) { + val call = core.inviteAddress(address) + Log.w("[Context] Starting call $call without params") + return + } + if (forceZRTP) { - params?.mediaEncryption = MediaEncryption.ZRTP + params.mediaEncryption = MediaEncryption.ZRTP } if (LinphoneUtils.checkIfNetworkHasLowBandwidth(context)) { Log.w("[Context] Enabling low bandwidth mode!") - params?.enableLowBandwidth(true) + params.enableLowBandwidth(true) } - params?.recordFile = LinphoneUtils.getRecordingFilePathForAddress(address) + params.recordFile = LinphoneUtils.getRecordingFilePathForAddress(address) - val call = if (params != null) { - core.inviteAddressWithParams(address, params) - } else { - core.inviteAddress(address) + if (localAddress != null) { + params.proxyConfig = core.proxyConfigList.find { proxyConfig -> + proxyConfig.identityAddress?.weakEqual(localAddress) ?: false + } + if (params.proxyConfig != null) { + Log.i("[Context] Using proxy config matching address ${localAddress.asStringUriOnly()} as From") + } } + + val call = core.inviteAddressWithParams(address, params) Log.i("[Context] Starting call $call") }