When calling back from history, try to use the address that received/initiated the original call as From

This commit is contained in:
Sylvain Berfini 2021-05-27 11:24:35 +02:00
parent 8df7cc1012
commit f815704338
6 changed files with 39 additions and 23 deletions

View file

@ -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<Event<GroupedCallLogData>>()
}
val startCallToEvent: MutableLiveData<Event<Address>> by lazy {
MutableLiveData<Event<Address>>()
val startCallToEvent: MutableLiveData<Event<GroupedCallLogData>> by lazy {
MutableLiveData<Event<GroupedCallLogData>>()
}
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)
}
}

View file

@ -94,7 +94,8 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
}
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<HistoryDetailFragmentBinding>() {
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)
}
}
})

View file

@ -164,16 +164,18 @@ class MasterCallLogsFragment : MasterFragment<HistoryMasterFragmentBinding, Call
})
adapter.startCallToEvent.observe(viewLifecycleOwner, {
it.consume { address ->
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)
}
}
})

View file

@ -97,8 +97,8 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
TimestampUtils.toString(callLog.startDate, shortDate = false, hideYear = false)
}
val startCallEvent: MutableLiveData<Event<Address>> by lazy {
MutableLiveData<Event<Address>>()
val startCallEvent: MutableLiveData<Event<CallLog>> by lazy {
MutableLiveData<Event<CallLog>>()
}
val chatRoomCreatedEvent: MutableLiveData<Event<ChatRoom>> 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) {

View file

@ -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

View file

@ -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")
}