Improved friendlyUri function
This commit is contained in:
@@ -123,41 +123,36 @@ object Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun friendlyUri(ctx: Context, uri: String, account: Account, e164Check: Boolean = true): String {
|
fun friendlyUri(ctx: Context, uri: String, account: Account, e164Check: Boolean = true): String {
|
||||||
|
Log.d(TAG, "******* uri=$uri, country_code=${account.countryCode}, aor=${account.aor}")
|
||||||
var u = Contact.contactName(uri)
|
var u = Contact.contactName(uri)
|
||||||
|
Log.d(TAG, "******* Contact.contactName=$u")
|
||||||
if (u != uri)
|
if (u != uri)
|
||||||
return u
|
return u
|
||||||
if (e164Check) {
|
if (e164Check) {
|
||||||
u = Contact.contactName(e164Uri(uri, account.countryCode))
|
u = Contact.contactName(e164Uri(uri, account.countryCode))
|
||||||
if (u != uri)
|
Log.d(TAG, "******* Contact.contactName(e164Uri)=$u")
|
||||||
return u
|
|
||||||
u = friendlyUri(ctx, uri, account, false)
|
|
||||||
if (u != uri)
|
if (u != uri)
|
||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
val params = uriParams(u)
|
if (u.contains("@")) {
|
||||||
if (uri.startsWith("<") && (uri.endsWith(">")))
|
|
||||||
u = uri.substring(1).substringBeforeLast(">")
|
|
||||||
u = u.substringBefore("?")
|
|
||||||
u = u.replace(":5060", "")
|
|
||||||
u = u.replace(";transport=udp", "", true)
|
|
||||||
if (u.split(":").size == 3 ||
|
|
||||||
(params.isNotEmpty() && !params.contains("user=phone")))
|
|
||||||
return u
|
|
||||||
return if (u.contains("@")) {
|
|
||||||
val user = uriUserPart(u)
|
val user = uriUserPart(u)
|
||||||
val host = uriHostPart(u)
|
val host = uriHostPart(u)
|
||||||
if (isTelNumber(user) || host == aorDomain(account.aor))
|
val params = uriParams(u)
|
||||||
|
return if (host == aorDomain(account.aor) || params.contains("user=phone"))
|
||||||
user
|
user
|
||||||
else
|
else if (host == "anonymous.invalid")
|
||||||
if (host == "anonymous.invalid")
|
|
||||||
ctx.getString(R.string.anonymous)
|
ctx.getString(R.string.anonymous)
|
||||||
else if (host == "unknown.invalid")
|
else if (host == "unknown.invalid")
|
||||||
ctx.getString(R.string.unknown)
|
ctx.getString(R.string.unknown)
|
||||||
else
|
else
|
||||||
"$user@$host"
|
"$user@$host"
|
||||||
} else {
|
|
||||||
u
|
|
||||||
}
|
}
|
||||||
|
if (uri.startsWith("<") && (uri.endsWith(">")))
|
||||||
|
u = uri.substring(1).substringBeforeLast(">")
|
||||||
|
u = u.substringBefore("?")
|
||||||
|
u = u.replace(":5060", "")
|
||||||
|
u = u.replace(";transport=udp", "", true)
|
||||||
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
fun e164Uri(uri: String, countryCode: String): String {
|
fun e164Uri(uri: String, countryCode: String): String {
|
||||||
|
|||||||
Reference in New Issue
Block a user