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 }
|
return BaresipService.callHistory.count { it.aor == aor }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun aorLatestHistory(aor: String): NewCallHistory? {
|
fun aorLatestPeerUri(aor: String): String? {
|
||||||
for (h in BaresipService.callHistory.reversed())
|
for (h in BaresipService.callHistory.reversed())
|
||||||
if (h.aor == aor) return h
|
if (h.aor == aor) return h.peerUri
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class ChatsActivity: AppCompatActivity() {
|
|||||||
plusButton.setOnClickListener {
|
plusButton.setOnClickListener {
|
||||||
val uriText = peerUri.text.toString().trim()
|
val uriText = peerUri.text.toString().trim()
|
||||||
if (uriText.isNotEmpty()) {
|
if (uriText.isNotEmpty()) {
|
||||||
var uri = Contact.contactUri(uriText)
|
var uri = Contact.contactUri(uriText, null)
|
||||||
if (uri == null)
|
if (uri == null)
|
||||||
uri = if (Utils.isTelNumber(uriText))
|
uri = if (Utils.isTelNumber(uriText))
|
||||||
"tel:$uriText"
|
"tel:$uriText"
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ sealed class Contact {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Return uri of contact name or null if contact is not found
|
// 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())
|
for (c in contacts())
|
||||||
when (c) {
|
when (c) {
|
||||||
is BaresipContact -> {
|
is BaresipContact -> {
|
||||||
@@ -62,10 +63,19 @@ sealed class Contact {
|
|||||||
}
|
}
|
||||||
is AndroidContact -> {
|
is AndroidContact -> {
|
||||||
if (c.name == name) {
|
if (c.name == name) {
|
||||||
return if (c.uris.isNotEmpty())
|
return if (c.uris.isNotEmpty()) {
|
||||||
c.uris.first()
|
var uri = c.uris.first()
|
||||||
else
|
if (c.uris.size > 1 && latest != null) {
|
||||||
|
for (u in c.uris)
|
||||||
|
if (u == latest) {
|
||||||
|
uri = latest
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uri
|
||||||
|
} else {
|
||||||
null
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1413,7 +1413,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
var uriText = transferUri.text.toString().trim()
|
var uriText = transferUri.text.toString().trim()
|
||||||
if (uriText.isNotEmpty()) {
|
if (uriText.isNotEmpty()) {
|
||||||
uriText = Contact.contactUri(uriText) ?: uriText
|
uriText = Contact.contactUri(uriText, null) ?: uriText
|
||||||
if (Utils.isTelNumber(uriText))
|
if (Utils.isTelNumber(uriText))
|
||||||
uriText = "tel:$uriText"
|
uriText = "tel:$uriText"
|
||||||
val uri = if (Utils.isTelUri(uriText))
|
val uri = if (Utils.isTelUri(uriText))
|
||||||
@@ -1737,7 +1737,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
if (Call.calls().isEmpty()) {
|
if (Call.calls().isEmpty()) {
|
||||||
var uriText = callUri.text.toString().trim()
|
var uriText = callUri.text.toString().trim()
|
||||||
if (uriText.isNotEmpty()) {
|
if (uriText.isNotEmpty()) {
|
||||||
uriText = Contact.contactUri(uriText) ?: uriText
|
uriText = Contact.contactUri(uriText, NewCallHistory.aorLatestPeerUri(aor)) ?: uriText
|
||||||
if (Utils.isTelNumber(uriText))
|
if (Utils.isTelNumber(uriText))
|
||||||
uriText = "tel:$uriText"
|
uriText = "tel:$uriText"
|
||||||
val uri = if (Utils.isTelUri(uriText)) {
|
val uri = if (Utils.isTelUri(uriText)) {
|
||||||
@@ -1787,9 +1787,9 @@ class MainActivity : AppCompatActivity() {
|
|||||||
callHandler.postDelayed(callRunnable!!, 1000)
|
callHandler.postDelayed(callRunnable!!, 1000)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val latest = NewCallHistory.aorLatestHistory(aor)
|
val latestPeerUri = NewCallHistory.aorLatestPeerUri(aor)
|
||||||
if (latest != null)
|
if (latestPeerUri != null)
|
||||||
callUri.setText(Utils.friendlyUri(this, latest.peerUri, ua.account))
|
callUri.setText(Utils.friendlyUri(this, latestPeerUri, ua.account))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user