According to help text. apply account's Country Code setting only to contact lookup
This commit is contained in:
@ -1085,7 +1085,9 @@ class BaresipService: Service() {
|
|||||||
getString(R.string.call_auto_rejected),
|
getString(R.string.call_auto_rejected),
|
||||||
Utils.friendlyUri(this, peerUri, ua.account, unique = true)
|
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
|
blockedCall = true
|
||||||
String.format(
|
String.format(
|
||||||
getString(R.string.call_blocked),
|
getString(R.string.call_blocked),
|
||||||
@ -1494,7 +1496,9 @@ class BaresipService: Service() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val blockedHidden = ua.account.blockHidden && peerUri.contains("anonymous")
|
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) {
|
if (blockedHidden || blockedUnknown) {
|
||||||
Log.d(TAG, "Auto-rejecting incoming message by $uap from $peerUri")
|
Log.d(TAG, "Auto-rejecting incoming message by $uap from $peerUri")
|
||||||
@ -1543,7 +1547,9 @@ class BaresipService: Service() {
|
|||||||
|
|
||||||
val aor = ua.account.aor
|
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")) ||
|
(ua.account.blockHidden && peerUri.contains("anonymous")) ||
|
||||||
isBlocked(aor, peerUri)) {
|
isBlocked(aor, peerUri)) {
|
||||||
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
|
Log.d(TAG, "Auto-rejecting blocked message from $peerUri")
|
||||||
@ -2311,8 +2317,7 @@ class BaresipService: Service() {
|
|||||||
stopRinging()
|
stopRinging()
|
||||||
stopMediaPlayer()
|
stopMediaPlayer()
|
||||||
if (call.ua.account.callHistory) {
|
if (call.ua.account.callHistory) {
|
||||||
val historyPeerUri = e164Uri(call.peerUri, call.ua.account.countryCode)
|
val history = CallHistoryNew(call.ua.account.aor, call.peerUri, call.dir)
|
||||||
val history = CallHistoryNew(call.ua.account.aor, historyPeerUri, call.dir)
|
|
||||||
history.stopTime = GregorianCalendar()
|
history.stopTime = GregorianCalendar()
|
||||||
history.startTime = call.startTime
|
history.startTime = call.startTime
|
||||||
history.rejected = call.rejected
|
history.rejected = call.rejected
|
||||||
|
|||||||
@ -560,7 +560,8 @@ private fun NewChatPeer(navController: NavController, account: Account) {
|
|||||||
append(Utils.buildAnnotatedStringWithHighlight(userPart, newPeer))
|
append(Utils.buildAnnotatedStringWithHighlight(userPart, newPeer))
|
||||||
append(restPart)
|
append(restPart)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
val highlightPart = newPeer.filter { c -> c.isDigit() || c == '+' }
|
val highlightPart = newPeer.filter { c -> c.isDigit() || c == '+' }
|
||||||
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
||||||
}
|
}
|
||||||
@ -595,12 +596,19 @@ private fun NewChatPeer(navController: NavController, account: Account) {
|
|||||||
val normalizedInput = Utils.unaccent(input)
|
val normalizedInput = Utils.unaccent(input)
|
||||||
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
|
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
|
||||||
val currentAor = account.aor
|
val currentAor = account.aor
|
||||||
|
val e164Input = if (numericInput.isNotEmpty())
|
||||||
|
Utils.e164Uri("tel:$numericInput", account.countryCode).substring(4)
|
||||||
|
else
|
||||||
|
""
|
||||||
BaresipService.contacts.flatMap { contact ->
|
BaresipService.contacts.flatMap { contact ->
|
||||||
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
|
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
|
||||||
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
|
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
|
||||||
val matchingUris = uris.filter { u ->
|
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.startsWith("sip:") && Utils.uriUserPart(u.uri).contains(normalizedInput, ignoreCase = true))
|
(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) {
|
if (nameMatch) {
|
||||||
val annotatedName = Utils.buildAnnotatedStringWithHighlight(contact.name(), input)
|
val annotatedName = Utils.buildAnnotatedStringWithHighlight(contact.name(), input)
|
||||||
@ -646,7 +654,7 @@ private fun NewChatPeer(navController: NavController, account: Account) {
|
|||||||
showSuggestions = false
|
showSuggestions = false
|
||||||
val peerText = newPeer.trim()
|
val peerText = newPeer.trim()
|
||||||
if (peerText.isNotEmpty()) {
|
if (peerText.isNotEmpty()) {
|
||||||
val uris = Contact.contactContactUris(peerText, account.isMobile)
|
val uris = Contact.contactUrisOfNameOrNumber(peerText, account)
|
||||||
if (uris.isEmpty()) {
|
if (uris.isEmpty()) {
|
||||||
if (Contact.nameExists(peerText, BaresipService.contacts, true)) {
|
if (Contact.nameExists(peerText, BaresipService.contacts, true)) {
|
||||||
alertTitle.value = noticeText
|
alertTitle.value = noticeText
|
||||||
|
|||||||
@ -130,7 +130,7 @@ sealed class Contact {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
fun contactContactUris(name: String, tel: Boolean = false): List<ContactUri> {
|
fun contactUris(name: String, tel: Boolean = false): List<ContactUri> {
|
||||||
synchronized(BaresipService.contacts) {
|
synchronized(BaresipService.contacts) {
|
||||||
for (c in BaresipService.contacts) {
|
for (c in BaresipService.contacts) {
|
||||||
val contactUris = if (tel)
|
val contactUris = if (tel)
|
||||||
@ -153,6 +153,19 @@ sealed class Contact {
|
|||||||
return emptyList()
|
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>? {
|
fun findContactWithUri(uri: String): Pair<Contact, ContactUri>? {
|
||||||
synchronized(BaresipService.contacts) {
|
synchronized(BaresipService.contacts) {
|
||||||
for (c in BaresipService.contacts)
|
for (c in BaresipService.contacts)
|
||||||
@ -309,9 +322,9 @@ sealed class Contact {
|
|||||||
val uri = uPart.substringBeforeLast("[")
|
val uri = uPart.substringBeforeLast("[")
|
||||||
val label = uPart.substringAfterLast("[").substringBeforeLast("]")
|
val label = uPart.substringAfterLast("[").substringBeforeLast("]")
|
||||||
uris.add(ContactUri(uri, label))
|
uris.add(ContactUri(uri, label))
|
||||||
} else {
|
|
||||||
uris.add(ContactUri(uPart, ""))
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
uris.add(ContactUri(uPart, ""))
|
||||||
}
|
}
|
||||||
val params = uriParams.substringAfter(">;")
|
val params = uriParams.substringAfter(">;")
|
||||||
val email = Utils.paramValue(params, "email")
|
val email = Utils.paramValue(params, "email")
|
||||||
|
|||||||
@ -1219,11 +1219,18 @@ private fun CallUriRow(
|
|||||||
val normalizedInput = Utils.unaccent(input)
|
val normalizedInput = Utils.unaccent(input)
|
||||||
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
|
val numericInput = input.filter { c -> c.isDigit() || c == '+' }
|
||||||
val currentAor = viewModel.selectedAor.value
|
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 ->
|
filteredSuggestions = BaresipService.contacts.flatMap { contact ->
|
||||||
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
|
val nameMatch = Utils.unaccent(contact.name()).contains(normalizedInput, ignoreCase = true)
|
||||||
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
|
val uris = contact.uris().filter { !Utils.uriMatch(it.uri, currentAor) }
|
||||||
val matchingUris = uris.filter { u ->
|
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))
|
(u.uri.startsWith("sip:") && Utils.uriUserPart(u.uri).contains(normalizedInput, ignoreCase = true))
|
||||||
}
|
}
|
||||||
if (nameMatch) {
|
if (nameMatch) {
|
||||||
@ -1345,9 +1352,9 @@ private fun CallUriRow(
|
|||||||
if (account != null) {
|
if (account != null) {
|
||||||
dialerState.callUri.value = Utils.friendlyUri(ctx, uri, account, unique = true)
|
dialerState.callUri.value = Utils.friendlyUri(ctx, uri, account, unique = true)
|
||||||
dialerState.redialUri = uri
|
dialerState.redialUri = uri
|
||||||
} else {
|
|
||||||
dialerState.callUri.value = uri.substringAfter(":")
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
dialerState.callUri.value = uri.substringAfter(":")
|
||||||
dialerState.showSuggestions.value = false
|
dialerState.showSuggestions.value = false
|
||||||
}
|
}
|
||||||
.padding(12.dp)
|
.padding(12.dp)
|
||||||
@ -1367,7 +1374,8 @@ private fun CallUriRow(
|
|||||||
append(Utils.buildAnnotatedStringWithHighlight(userPart, dialerState.callUri.value))
|
append(Utils.buildAnnotatedStringWithHighlight(userPart, dialerState.callUri.value))
|
||||||
append(restPart)
|
append(restPart)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
val highlightPart = dialerState.callUri.value.filter { c -> c.isDigit() || c == '+' }
|
val highlightPart = dialerState.callUri.value.filter { c -> c.isDigit() || c == '+' }
|
||||||
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
||||||
}
|
}
|
||||||
@ -1788,7 +1796,8 @@ private fun CallRow(
|
|||||||
append(Utils.buildAnnotatedStringWithHighlight(userPart, transferUri))
|
append(Utils.buildAnnotatedStringWithHighlight(userPart, transferUri))
|
||||||
append(restPart)
|
append(restPart)
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
val highlightPart = transferUri.filter { c -> c.isDigit() || c == '+' }
|
val highlightPart = transferUri.filter { c -> c.isDigit() || c == '+' }
|
||||||
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
Utils.buildAnnotatedStringWithHighlight(uriPart, highlightPart)
|
||||||
}
|
}
|
||||||
@ -1862,7 +1871,7 @@ private fun CallRow(
|
|||||||
call.showSuggestions.value = false
|
call.showSuggestions.value = false
|
||||||
var uriText = transferUri.trim()
|
var uriText = transferUri.trim()
|
||||||
if (uriText.isNotEmpty()) {
|
if (uriText.isNotEmpty()) {
|
||||||
val uris = Contact.contactContactUris(uriText)
|
val uris = Contact.contactUris(uriText)
|
||||||
if (uris.size > 1) {
|
if (uris.size > 1) {
|
||||||
selectItems.value = uris.map { it.label.ifEmpty { it.uri.substringAfter(":") } }
|
selectItems.value = uris.map { it.label.ifEmpty { it.uri.substringAfter(":") } }
|
||||||
selectItemAction.value = { index ->
|
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))
|
uriText == Utils.friendlyUri(ctx, dialerState.redialUri, ua!!.account, unique = true))
|
||||||
dialerState.redialUri
|
dialerState.redialUri
|
||||||
else {
|
else {
|
||||||
val uris = Contact.contactContactUris(uriText, ua?.account?.isMobile ?: false)
|
val uris = Contact.contactUrisOfNameOrNumber(uriText, ua!!.account)
|
||||||
if (uris.isEmpty()) {
|
if (uris.isEmpty()) {
|
||||||
if (Contact.nameExists(uriText, BaresipService.contacts, true)) {
|
if (Contact.nameExists(uriText, BaresipService.contacts, true)) {
|
||||||
alertTitle.value = ctx.getString(R.string.notice)
|
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)
|
String.format(ctx.getString(R.string.contact_no_tel_uri), uriText)
|
||||||
else
|
else
|
||||||
String.format(ctx.getString(R.string.contact_no_sip_or_tel_uri), uriText)
|
String.format(ctx.getString(R.string.contact_no_sip_or_tel_uri), uriText)
|
||||||
|
|||||||
@ -597,7 +597,8 @@ object Utils {
|
|||||||
if (DocumentsContract.deleteDocument(contentResolver, uri)) {
|
if (DocumentsContract.deleteDocument(contentResolver, uri)) {
|
||||||
Log.d(TAG, "File deleted successfully: $uri")
|
Log.d(TAG, "File deleted successfully: $uri")
|
||||||
return true
|
return true
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
Log.d(TAG, "File not found or could not be deleted: $uri")
|
Log.d(TAG, "File not found or could not be deleted: $uri")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -1333,7 +1334,8 @@ object Utils {
|
|||||||
if (i + 1 < bytesRead1) {
|
if (i + 1 < bytesRead1) {
|
||||||
stereoBuffer[outIndex++] = buffer1[i]
|
stereoBuffer[outIndex++] = buffer1[i]
|
||||||
stereoBuffer[outIndex++] = buffer1[i+1]
|
stereoBuffer[outIndex++] = buffer1[i+1]
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Padding if file1 ended
|
// Padding if file1 ended
|
||||||
stereoBuffer[outIndex++] = 0
|
stereoBuffer[outIndex++] = 0
|
||||||
stereoBuffer[outIndex++] = 0
|
stereoBuffer[outIndex++] = 0
|
||||||
@ -1343,7 +1345,8 @@ object Utils {
|
|||||||
if (i + 1 < bytesRead2) {
|
if (i + 1 < bytesRead2) {
|
||||||
stereoBuffer[outIndex++] = buffer2[i]
|
stereoBuffer[outIndex++] = buffer2[i]
|
||||||
stereoBuffer[outIndex++] = buffer2[i+1]
|
stereoBuffer[outIndex++] = buffer2[i+1]
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
// Padding if file2 ended
|
// Padding if file2 ended
|
||||||
stereoBuffer[outIndex++] = 0
|
stereoBuffer[outIndex++] = 0
|
||||||
stereoBuffer[outIndex++] = 0
|
stereoBuffer[outIndex++] = 0
|
||||||
|
|||||||
Reference in New Issue
Block a user