When calling Android contact, use the latest peer URI if contact has it

This commit is contained in:
Juha Heinanen
2022-08-13 09:52:38 +03:00
parent ae36f56981
commit 589bd3079c
4 changed files with 22 additions and 12 deletions

View File

@ -36,9 +36,9 @@ class NewCallHistory(val aor: String, val peerUri: String, val direction: String
return BaresipService.callHistory.count { it.aor == aor }
}
fun aorLatestHistory(aor: String): NewCallHistory? {
fun aorLatestPeerUri(aor: String): String? {
for (h in BaresipService.callHistory.reversed())
if (h.aor == aor) return h
if (h.aor == aor) return h.peerUri
return null
}

View File

@ -130,7 +130,7 @@ class ChatsActivity: AppCompatActivity() {
plusButton.setOnClickListener {
val uriText = peerUri.text.toString().trim()
if (uriText.isNotEmpty()) {
var uri = Contact.contactUri(uriText)
var uri = Contact.contactUri(uriText, null)
if (uri == null)
uri = if (Utils.isTelNumber(uriText))
"tel:$uriText"

View File

@ -51,7 +51,8 @@ sealed class Contact {
}
// Return uri of contact name or null if contact is not found
fun contactUri(name: String): String? {
// If Android contact has more than one uri, return latest if given and found
fun contactUri(name: String, latest: String?): String? {
for (c in contacts())
when (c) {
is BaresipContact -> {
@ -62,10 +63,19 @@ sealed class Contact {
}
is AndroidContact -> {
if (c.name == name) {
return if (c.uris.isNotEmpty())
c.uris.first()
else
return if (c.uris.isNotEmpty()) {
var uri = c.uris.first()
if (c.uris.size > 1 && latest != null) {
for (u in c.uris)
if (u == latest) {
uri = latest
break
}
}
uri
} else {
null
}
}
}
}

View File

@ -1413,7 +1413,7 @@ class MainActivity : AppCompatActivity() {
dialog.dismiss()
var uriText = transferUri.text.toString().trim()
if (uriText.isNotEmpty()) {
uriText = Contact.contactUri(uriText) ?: uriText
uriText = Contact.contactUri(uriText, null) ?: uriText
if (Utils.isTelNumber(uriText))
uriText = "tel:$uriText"
val uri = if (Utils.isTelUri(uriText))
@ -1737,7 +1737,7 @@ class MainActivity : AppCompatActivity() {
if (Call.calls().isEmpty()) {
var uriText = callUri.text.toString().trim()
if (uriText.isNotEmpty()) {
uriText = Contact.contactUri(uriText) ?: uriText
uriText = Contact.contactUri(uriText, NewCallHistory.aorLatestPeerUri(aor)) ?: uriText
if (Utils.isTelNumber(uriText))
uriText = "tel:$uriText"
val uri = if (Utils.isTelUri(uriText)) {
@ -1787,9 +1787,9 @@ class MainActivity : AppCompatActivity() {
callHandler.postDelayed(callRunnable!!, 1000)
}
} else {
val latest = NewCallHistory.aorLatestHistory(aor)
if (latest != null)
callUri.setText(Utils.friendlyUri(this, latest.peerUri, ua.account))
val latestPeerUri = NewCallHistory.aorLatestPeerUri(aor)
if (latestPeerUri != null)
callUri.setText(Utils.friendlyUri(this, latestPeerUri, ua.account))
}
}
}