According to help text. apply account's Country Code setting only to contact lookup

This commit is contained in:
Juha Heinanen
2026-08-15 10:09:15 +03:00
parent 57bbc20af7
commit 8fb718fdd2
5 changed files with 61 additions and 23 deletions

View File

@ -1085,7 +1085,9 @@ class BaresipService: Service() {
getString(R.string.call_auto_rejected),
Utils.friendlyUri(this, peerUri, ua.account, unique = true)
)
else if (ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) {
else if (ua.account.blockUnknown &&
Contact.contactName(e164Uri(peerUri, ua.account.countryCode)) ==
e164Uri(peerUri, ua.account.countryCode)) {
blockedCall = true
String.format(
getString(R.string.call_blocked),
@ -1494,7 +1496,9 @@ class BaresipService: Service() {
}
val blockedHidden = ua.account.blockHidden && peerUri.contains("anonymous")
val blockedUnknown = ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri
val blockedUnknown = ua.account.blockUnknown &&
Contact.contactName(e164Uri(peerUri, ua.account.countryCode)) ==
e164Uri(peerUri, ua.account.countryCode)
if (blockedHidden || blockedUnknown) {
Log.d(TAG, "Auto-rejecting incoming message by $uap from $peerUri")
@ -1543,7 +1547,9 @@ class BaresipService: Service() {
val aor = ua.account.aor
if ((ua.account.blockUnknown && Contact.contactName(peerUri) == peerUri) ||
if ((ua.account.blockUnknown &&
Contact.contactName(e164Uri(peerUri, ua.account.countryCode)) ==
e164Uri(peerUri, ua.account.countryCode)) ||
(ua.account.blockHidden && peerUri.contains("anonymous")) ||
isBlocked(aor, peerUri)) {
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
@ -2311,8 +2317,7 @@ class BaresipService: Service() {
stopRinging()
stopMediaPlayer()
if (call.ua.account.callHistory) {
val historyPeerUri = e164Uri(call.peerUri, call.ua.account.countryCode)
val history = CallHistoryNew(call.ua.account.aor, historyPeerUri, call.dir)
val history = CallHistoryNew(call.ua.account.aor, call.peerUri, call.dir)
history.stopTime = GregorianCalendar()
history.startTime = call.startTime
history.rejected = call.rejected

View File

@ -560,7 +560,8 @@ private fun NewChatPeer(navController: NavController, account: Account) {
append(Utils.buildAnnotatedStringWithHighlight(userPart, newPeer))
append(restPart)
}
} else {
}
else {
val highlightPart = newPeer.filter { c -> c.isDigit() || c == '+' }
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
}
@ -595,12 +596,19 @@ private fun NewChatPeer(navController: NavController, account: Account) {
val normalizedInput = Utils.unaccent(input)
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
val currentAor = account.aor
val e164Input = if (numericInput.isNotEmpty())
Utils.e164Uri("tel:$numericInput", account.countryCode).substring(4)
else
""
BaresipService.contacts.flatMap { contact ->
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
val matchingUris = uris.filter { u ->
(u.uri.startsWith("tel:") && numericInput.isNotEmpty() && u.uri.substring(4).contains(numericInput)) ||
(u.uri.startsWith("sip:") && Utils.uriUserPart(u.uri).contains(normalizedInput, ignoreCase = true))
(u.uri.startsWith("tel:") && numericInput.isNotEmpty() &&
(u.uri.substring(4).contains(numericInput) ||
(e164Input != "" && u.uri.substring(4).contains(e164Input)))) ||
(u.uri.startsWith("sip:") &&
Utils.uriUserPart(u.uri).contains(normalizedInput, ignoreCase = true))
}
if (nameMatch) {
val annotatedName = Utils.buildAnnotatedStringWithHighlight(contact.name(), input)
@ -646,7 +654,7 @@ private fun NewChatPeer(navController: NavController, account: Account) {
showSuggestions = false
val peerText = newPeer.trim()
if (peerText.isNotEmpty()) {
val uris = Contact.contactContactUris(peerText, account.isMobile)
val uris = Contact.contactUrisOfNameOrNumber(peerText, account)
if (uris.isEmpty()) {
if (Contact.nameExists(peerText, BaresipService.contacts, true)) {
alertTitle.value = noticeText

View File

@ -130,7 +130,7 @@ sealed class Contact {
return null
}
fun contactContactUris(name: String, tel: Boolean = false): List<ContactUri> {
fun contactUris(name: String, tel: Boolean = false): List<ContactUri> {
synchronized(BaresipService.contacts) {
for (c in BaresipService.contacts) {
val contactUris = if (tel)
@ -153,6 +153,19 @@ sealed class Contact {
return emptyList()
}
fun contactUrisOfNameOrNumber(nameOrNumber: String, account: Account): List<ContactUri> {
var uris = contactUris(nameOrNumber, account.isMobile)
if (uris.isEmpty() && Utils.isTelNumber(nameOrNumber)) {
val contactWithUri = findContactWithUri("tel:$nameOrNumber")
?: findContactWithUri(Utils.e164Uri("tel:$nameOrNumber", account.countryCode))
if (contactWithUri != null)
uris = contactWithUri.first.uris().filter {
if (account.isMobile) it.uri.startsWith("tel:") else true
}
}
return uris
}
fun findContactWithUri(uri: String): Pair<Contact, ContactUri>? {
synchronized(BaresipService.contacts) {
for (c in BaresipService.contacts)
@ -309,9 +322,9 @@ sealed class Contact {
val uri = uPart.substringBeforeLast("[")
val label = uPart.substringAfterLast("[").substringBeforeLast("]")
uris.add(ContactUri(uri, label))
} else {
uris.add(ContactUri(uPart, ""))
}
else
uris.add(ContactUri(uPart, ""))
}
val params = uriParams.substringAfter(">;")
val email = Utils.paramValue(params, "email")

View File

@ -1219,11 +1219,18 @@ private fun CallUriRow(
val normalizedInput = Utils.unaccent(input)
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
val currentAor = viewModel.selectedAor.value
val account = Account.ofAor(currentAor)
val e164Input = if (account != null && numericInput.isNotEmpty())
Utils.e164Uri("tel:$numericInput", account.countryCode).substring(4)
else
""
filteredSuggestions = BaresipService.contacts.flatMap { contact ->
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
val matchingUris = uris.filter { u ->
(u.uri.startsWith("tel:") && numericInput.isNotEmpty() && u.uri.substring(4).contains(numericInput)) ||
(u.uri.startsWith("tel:") && numericInput.isNotEmpty() &&
(u.uri.substring(4).contains(numericInput) ||
(e164Input != "" && u.uri.substring(4).contains(e164Input)))) ||
(u.uri.startsWith("sip:") && Utils.uriUserPart(u.uri).contains(normalizedInput, ignoreCase = true))
}
if (nameMatch) {
@ -1345,9 +1352,9 @@ private fun CallUriRow(
if (account != null) {
dialerState.callUri.value = Utils.friendlyUri(ctx, uri, account, unique = true)
dialerState.redialUri = uri
} else {
dialerState.callUri.value = uri.substringAfter(":")
}
else
dialerState.callUri.value = uri.substringAfter(":")
dialerState.showSuggestions.value = false
}
.padding(12.dp)
@ -1367,7 +1374,8 @@ private fun CallUriRow(
append(Utils.buildAnnotatedStringWithHighlight(userPart, dialerState.callUri.value))
append(restPart)
}
} else {
}
else {
val highlightPart = dialerState.callUri.value.filter { c -> c.isDigit() || c == '+' }
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
}
@ -1788,7 +1796,8 @@ private fun CallRow(
append(Utils.buildAnnotatedStringWithHighlight(userPart, transferUri))
append(restPart)
}
} else {
}
else {
val highlightPart = transferUri.filter { c -> c.isDigit() || c == '+' }
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
}
@ -1862,7 +1871,7 @@ private fun CallRow(
call.showSuggestions.value = false
var uriText = transferUri.trim()
if (uriText.isNotEmpty()) {
val uris = Contact.contactContactUris(uriText)
val uris = Contact.contactUris(uriText)
if (uris.size > 1) {
selectItems.value = uris.map { it.label.ifEmpty { it.uri.substringAfter(":") } }
selectItemAction.value = { index ->
@ -2072,11 +2081,11 @@ private fun callClick(ctx: Context, viewModel: ViewModel, dialerState: ViewModel
uriText == Utils.friendlyUri(ctx, dialerState.redialUri, ua!!.account, unique = true))
dialerState.redialUri
else {
val uris = Contact.contactContactUris(uriText, ua?.account?.isMobile ?: false)
val uris = Contact.contactUrisOfNameOrNumber(uriText, ua!!.account)
if (uris.isEmpty()) {
if (Contact.nameExists(uriText, BaresipService.contacts, true)) {
alertTitle.value = ctx.getString(R.string.notice)
alertMessage.value = if (ua?.account?.isMobile == true)
alertMessage.value = if (ua.account.isMobile)
String.format(ctx.getString(R.string.contact_no_tel_uri), uriText)
else
String.format(ctx.getString(R.string.contact_no_sip_or_tel_uri), uriText)

View File

@ -597,7 +597,8 @@ object Utils {
if (DocumentsContract.deleteDocument(contentResolver, uri)) {
Log.d(TAG, "File deleted successfully: $uri")
return true
} else {
}
else {
Log.d(TAG, "File not found or could not be deleted: $uri")
return false
}
@ -1333,7 +1334,8 @@ object Utils {
if (i + 1 < bytesRead1) {
stereoBuffer[outIndex++] = buffer1[i]
stereoBuffer[outIndex++] = buffer1[i+1]
} else {
}
else {
// Padding if file1 ended
stereoBuffer[outIndex++] = 0
stereoBuffer[outIndex++] = 0
@ -1343,7 +1345,8 @@ object Utils {
if (i + 1 < bytesRead2) {
stereoBuffer[outIndex++] = buffer2[i]
stereoBuffer[outIndex++] = buffer2[i+1]
} else {
}
else {
// Padding if file2 ended
stereoBuffer[outIndex++] = 0
stereoBuffer[outIndex++] = 0