When calling Android contact, use the latest peer URI if contact has it
This commit is contained in:
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user