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.data.GroupedCallLogData
import org.linphone.activities.main.history.viewmodels.CallLogViewModel import org.linphone.activities.main.history.viewmodels.CallLogViewModel
import org.linphone.activities.main.viewmodels.ListTopBarViewModel import org.linphone.activities.main.viewmodels.ListTopBarViewModel
import org.linphone.core.Address
import org.linphone.databinding.GenericListHeaderBinding import org.linphone.databinding.GenericListHeaderBinding
import org.linphone.databinding.HistoryListCellBinding import org.linphone.databinding.HistoryListCellBinding
import org.linphone.utils.* import org.linphone.utils.*
@ -46,8 +45,8 @@ class CallLogsListAdapter(
MutableLiveData<Event<GroupedCallLogData>>() MutableLiveData<Event<GroupedCallLogData>>()
} }
val startCallToEvent: MutableLiveData<Event<Address>> by lazy { val startCallToEvent: MutableLiveData<Event<GroupedCallLogData>> by lazy {
MutableLiveData<Event<Address>>() MutableLiveData<Event<GroupedCallLogData>>()
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
@ -86,7 +85,7 @@ class CallLogsListAdapter(
if (selectionViewModel.isEditionEnabled.value == true) { if (selectionViewModel.isEditionEnabled.value == true) {
selectionViewModel.onToggleSelect(adapterPosition) selectionViewModel.onToggleSelect(adapterPosition)
} else { } 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, { viewModel.startCallEvent.observe(viewLifecycleOwner, {
it.consume { address -> it.consume { callLog ->
val address = callLog.remoteAddress
if (coreContext.core.callsNb > 0) { 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 ${address.asStringUriOnly()}, is transfer? ${sharedViewModel.pendingCallTransfer}")
val args = Bundle() val args = Bundle()
@ -103,7 +104,8 @@ class DetailCallLogFragment : GenericFragment<HistoryDetailFragmentBinding>() {
args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it
navigateToDialer(args) navigateToDialer(args)
} else { } 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, { adapter.startCallToEvent.observe(viewLifecycleOwner, {
it.consume { address -> it.consume { callLogGroup ->
val remoteAddress = callLogGroup.lastCallLog.remoteAddress
if (coreContext.core.callsNb > 0) { 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() val args = Bundle()
args.putString("URI", address.asStringUriOnly()) args.putString("URI", remoteAddress.asStringUriOnly())
args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer) args.putBoolean("Transfer", sharedViewModel.pendingCallTransfer)
args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it args.putBoolean("SkipAutoCallStart", true) // If auto start call setting is enabled, ignore it
navigateToDialer(args) navigateToDialer(args)
} else { } 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) TimestampUtils.toString(callLog.startDate, shortDate = false, hideYear = false)
} }
val startCallEvent: MutableLiveData<Event<Address>> by lazy { val startCallEvent: MutableLiveData<Event<CallLog>> by lazy {
MutableLiveData<Event<Address>>() MutableLiveData<Event<CallLog>>()
} }
val chatRoomCreatedEvent: MutableLiveData<Event<ChatRoom>> by lazy { val chatRoomCreatedEvent: MutableLiveData<Event<ChatRoom>> by lazy {
@ -139,7 +139,7 @@ class CallLogViewModel(val callLog: CallLog) : GenericContactViewModel(callLog.r
} }
fun startCall() { fun startCall() {
startCallEvent.value = Event(callLog.remoteAddress) startCallEvent.value = Event(callLog)
} }
fun startChat(isSecured: Boolean) { fun startChat(isSecured: Boolean) {

View file

@ -102,7 +102,8 @@ class CallLogsListViewModel : ViewModel() {
for (callLog in coreContext.core.callLogs) { for (callLog in coreContext.core.callLogs) {
if (previousCallLogGroup == null) { if (previousCallLogGroup == null) {
previousCallLogGroup = GroupedCallLogData(callLog) 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)) { if (TimestampUtils.isSameDay(previousCallLogGroup.lastCallLog.startDate, callLog.startDate)) {
previousCallLogGroup.callLogs.add(callLog) previousCallLogGroup.callLogs.add(callLog)
previousCallLogGroup.lastCallLog = callLog previousCallLogGroup.lastCallLog = callLog
@ -118,7 +119,8 @@ class CallLogsListViewModel : ViewModel() {
if (LinphoneUtils.isCallLogMissed(callLog)) { if (LinphoneUtils.isCallLogMissed(callLog)) {
if (previousMissedCallLogGroup == null) { if (previousMissedCallLogGroup == null) {
previousMissedCallLogGroup = GroupedCallLogData(callLog) 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)) { if (TimestampUtils.isSameDay(previousMissedCallLogGroup.lastCallLog.startDate, callLog.startDate)) {
previousMissedCallLogGroup.callLogs.add(callLog) previousMissedCallLogGroup.callLogs.add(callLog)
previousMissedCallLogGroup.lastCallLog = callLog previousMissedCallLogGroup.lastCallLog = callLog

View file

@ -470,7 +470,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
startCall(address) startCall(address)
} }
fun startCall(address: Address, forceZRTP: Boolean = false) { fun startCall(address: Address, forceZRTP: Boolean = false, localAddress: Address? = null) {
if (!core.isNetworkReachable) { if (!core.isNetworkReachable) {
Log.e("[Context] Network unreachable, abort outgoing call") Log.e("[Context] Network unreachable, abort outgoing call")
callErrorMessageResourceId.value = Event(context.getString(R.string.call_error_network_unreachable)) 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) val params = core.createCallParams(null)
if (params == null) {
val call = core.inviteAddress(address)
Log.w("[Context] Starting call $call without params")
return
}
if (forceZRTP) { if (forceZRTP) {
params?.mediaEncryption = MediaEncryption.ZRTP params.mediaEncryption = MediaEncryption.ZRTP
} }
if (LinphoneUtils.checkIfNetworkHasLowBandwidth(context)) { if (LinphoneUtils.checkIfNetworkHasLowBandwidth(context)) {
Log.w("[Context] Enabling low bandwidth mode!") 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) { if (localAddress != null) {
core.inviteAddressWithParams(address, params) params.proxyConfig = core.proxyConfigList.find { proxyConfig ->
} else { proxyConfig.identityAddress?.weakEqual(localAddress) ?: false
core.inviteAddress(address)
} }
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") Log.i("[Context] Starting call $call")
} }