Fixed find contact by phone number

This commit is contained in:
Sylvain Berfini 2023-09-18 09:36:00 +02:00
parent 08643df831
commit ce8aee9192
5 changed files with 27 additions and 11 deletions

View file

@ -131,10 +131,15 @@ class ContactsManager @UiThread constructor(context: Context) {
@WorkerThread
fun findContactByAddress(address: Address): Friend? {
val friend = coreContext.core.findFriend(address)
if (friend != null) return friend
return null
val username = address.username
val usernameIsPhoneNumber = !username.isNullOrEmpty() && username.startsWith("+")
return coreContext.core.findFriend(address) ?: if (usernameIsPhoneNumber) {
coreContext.core.findFriendByPhoneNumber(
username!!
)
} else {
null
}
}
@WorkerThread

View file

@ -42,7 +42,7 @@ class CallLogModel @WorkerThread constructor(private val callLog: CallLog) {
}
dateTime.postValue(displayedDate)
val friend = coreContext.core.findFriend(address)
val friend = coreContext.contactsManager.findContactByAddress(address)
if (friend != null) {
friendRefKey = friend.refKey
avatarModel = ContactAvatarModel(friend)

View file

@ -175,7 +175,7 @@ class StartCallViewModel @UiThread constructor() : ViewModel() {
for (result in results) {
val address = result.address
if (address != null) {
val friend = coreContext.core.findFriend(address)
val friend = coreContext.contactsManager.findContactByAddress(address)
if (friend != null) {
val model = ContactOrSuggestionModel(address, friend)
model.contactAvatarModel = ContactAvatarModel(friend)

View file

@ -382,7 +382,7 @@ class CurrentCallViewModel @UiThread constructor() : ViewModel() {
displayedAddress.postValue(address.asStringUriOnly())
val isDeviceTrusted = updateEncryption()
val friend = call.core.findFriend(address)
val friend = coreContext.contactsManager.findContactByAddress(address)
if (friend != null) {
displayedName.postValue(friend.name)
val model = ContactAvatarModel(friend)

View file

@ -207,7 +207,9 @@ fun AppCompatTextView.setColor(@ColorRes color: Int) {
@BindingAdapter("avatarInitials")
fun AvatarView.loadInitials(initials: String?) {
Log.i("[Data Binding Utils] Displaying initials [$initials] on AvatarView")
avatarInitials = initials.orEmpty()
if (initials.orEmpty() != "+") {
avatarInitials = initials.orEmpty()
}
}
@UiThread
@ -224,7 +226,10 @@ fun AvatarView.loadAccountAvatar(account: AccountModel?) {
data = uri,
onStart = {
// Use initials as placeholder
avatarInitials = account.initials.value.orEmpty()
val initials = account.initials.value.orEmpty()
if (initials != "+") {
avatarInitials = initials
}
if (account.showTrust.value == true) {
avatarBorderColor =
@ -246,7 +251,10 @@ fun AvatarView.loadAccountAvatar(account: AccountModel?) {
data = account.avatar.value,
onStart = {
// Use initials as placeholder
avatarInitials = account.initials.value.orEmpty()
val initials = account.initials.value.orEmpty()
if (initials != "+") {
avatarInitials = initials
}
if (account.showTrust.value == true) {
avatarBorderColor = resources.getColor(R.color.blue_trusted, context.theme)
@ -275,7 +283,10 @@ fun AvatarView.loadContactAvatar(contact: ContactAvatarModel?) {
data = uri,
onStart = {
// Use initials as placeholder
avatarInitials = contact.initials
val initials = contact.initials
if (initials != "+") {
avatarInitials = initials
}
if (contact.showTrust.value == true) {
avatarBorderColor =