Improved how local accounts are used when looking for a contact from a SIP URI
This commit is contained in:
parent
920c33b619
commit
e1e06a58be
10 changed files with 62 additions and 13 deletions
|
@ -85,6 +85,8 @@ class AccountLoginFragment : AbstractPhoneFragment<AssistantAccountLoginFragment
|
||||||
|
|
||||||
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
||||||
it.consume {
|
it.consume {
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
|
|
||||||
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
||||||
navigateToEchoCancellerCalibration()
|
navigateToEchoCancellerCalibration()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,6 +22,7 @@ package org.linphone.activities.assistant.fragments
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.GenericFragment
|
import org.linphone.activities.GenericFragment
|
||||||
import org.linphone.activities.assistant.AssistantActivity
|
import org.linphone.activities.assistant.AssistantActivity
|
||||||
|
@ -49,6 +50,8 @@ class EmailAccountValidationFragment : GenericFragment<AssistantEmailAccountVali
|
||||||
|
|
||||||
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
||||||
it.consume {
|
it.consume {
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
|
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putBoolean("AllowSkip", true)
|
args.putBoolean("AllowSkip", true)
|
||||||
args.putString("Username", viewModel.accountCreator.username)
|
args.putString("Username", viewModel.accountCreator.username)
|
||||||
|
|
|
@ -55,6 +55,8 @@ class GenericAccountLoginFragment : GenericFragment<AssistantGenericAccountLogin
|
||||||
|
|
||||||
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
viewModel.leaveAssistantEvent.observe(viewLifecycleOwner, {
|
||||||
it.consume {
|
it.consume {
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
|
|
||||||
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
||||||
navigateToEchoCancellerCalibration()
|
navigateToEchoCancellerCalibration()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -62,6 +62,8 @@ class PhoneAccountValidationFragment : GenericFragment<AssistantPhoneAccountVali
|
||||||
it.consume {
|
it.consume {
|
||||||
when {
|
when {
|
||||||
viewModel.isLogin.value == true || viewModel.isCreation.value == true -> {
|
viewModel.isLogin.value == true || viewModel.isCreation.value == true -> {
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
|
|
||||||
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
if (coreContext.core.isEchoCancellerCalibrationRequired) {
|
||||||
navigateToEchoCancellerCalibration()
|
navigateToEchoCancellerCalibration()
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -228,18 +228,9 @@ class ChatRoomViewModel(val chatRoom: ChatRoom) : ViewModel(), ContactDataInterf
|
||||||
private fun formatLastMessage(msg: ChatMessage?): String {
|
private fun formatLastMessage(msg: ChatMessage?): String {
|
||||||
if (msg == null) return ""
|
if (msg == null) return ""
|
||||||
|
|
||||||
val account = coreContext.core.accountList.find { account ->
|
|
||||||
account.params.identityAddress?.weakEqual(msg.fromAddress) ?: false
|
|
||||||
}
|
|
||||||
val localDisplayName = account?.params?.identityAddress?.displayName
|
|
||||||
|
|
||||||
val sender: String =
|
val sender: String =
|
||||||
if (msg.isOutgoing && localDisplayName != null) {
|
coreContext.contactsManager.findContactByAddress(msg.fromAddress)?.fullName
|
||||||
localDisplayName
|
?: LinphoneUtils.getDisplayName(msg.fromAddress)
|
||||||
} else {
|
|
||||||
coreContext.contactsManager.findContactByAddress(msg.fromAddress)?.fullName
|
|
||||||
?: LinphoneUtils.getDisplayName(msg.fromAddress)
|
|
||||||
}
|
|
||||||
var body = ""
|
var body = ""
|
||||||
for (content in msg.contents) {
|
for (content in msg.contents) {
|
||||||
if (content.isFile || content.isFileTransfer) body += content.name + " "
|
if (content.isFile || content.isFileTransfer) body += content.name + " "
|
||||||
|
|
|
@ -84,6 +84,9 @@ class AccountSettingsViewModel(val account: Account) : GenericSettingsViewModel(
|
||||||
deleteAccount(account)
|
deleteAccount(account)
|
||||||
} else {
|
} else {
|
||||||
update()
|
update()
|
||||||
|
if (state == RegistrationState.Ok) {
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,5 +101,6 @@ class SideMenuViewModel : ViewModel() {
|
||||||
fun setPictureFromPath(picturePath: String) {
|
fun setPictureFromPath(picturePath: String) {
|
||||||
corePreferences.defaultAccountAvatarPath = picturePath
|
corePreferences.defaultAccountAvatarPath = picturePath
|
||||||
defaultAccountAvatar.value = corePreferences.defaultAccountAvatarPath
|
defaultAccountAvatar.value = corePreferences.defaultAccountAvatarPath
|
||||||
|
coreContext.contactsManager.updateLocalContacts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,8 @@ open class Contact : Comparable<Contact> {
|
||||||
// Raw SIP addresses are only used for contact edition
|
// Raw SIP addresses are only used for contact edition
|
||||||
var rawSipAddresses = arrayListOf<String>()
|
var rawSipAddresses = arrayListOf<String>()
|
||||||
|
|
||||||
|
var thumbnailUri: Uri? = null
|
||||||
|
|
||||||
var friend: Friend? = null
|
var friend: Friend? = null
|
||||||
|
|
||||||
override fun compareTo(other: Contact): Int {
|
override fun compareTo(other: Contact): Int {
|
||||||
|
@ -126,7 +128,11 @@ open class Contact : Comparable<Contact> {
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getContactThumbnailPictureUri(): Uri? {
|
open fun getContactThumbnailPictureUri(): Uri? {
|
||||||
return null
|
return thumbnailUri
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setContactThumbnailPictureUri(uri: Uri) {
|
||||||
|
thumbnailUri = uri
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun getContactPictureUri(): Uri? {
|
open fun getContactPictureUri(): Uri? {
|
||||||
|
|
|
@ -60,7 +60,8 @@ open class GenericContactData(private val sipAddress: Address) : ContactDataInte
|
||||||
|
|
||||||
private fun contactLookup() {
|
private fun contactLookup() {
|
||||||
displayName.value = LinphoneUtils.getDisplayName(sipAddress)
|
displayName.value = LinphoneUtils.getDisplayName(sipAddress)
|
||||||
contact.value = LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
|
contact.value =
|
||||||
|
LinphoneApplication.coreContext.contactsManager.findContactByAddress(sipAddress)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,7 @@ import android.os.AsyncTask
|
||||||
import android.os.AsyncTask.THREAD_POOL_EXECUTOR
|
import android.os.AsyncTask.THREAD_POOL_EXECUTOR
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import android.util.Patterns
|
import android.util.Patterns
|
||||||
|
import java.io.File
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.LinphoneApplication.Companion.corePreferences
|
import org.linphone.LinphoneApplication.Companion.corePreferences
|
||||||
|
@ -78,6 +79,12 @@ class ContactsManager(private val context: Context) {
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private set
|
private set
|
||||||
|
|
||||||
|
var localAccountsContacts = ArrayList<Contact>()
|
||||||
|
@Synchronized
|
||||||
|
get
|
||||||
|
@Synchronized
|
||||||
|
private set
|
||||||
|
|
||||||
val magicSearch: MagicSearch by lazy {
|
val magicSearch: MagicSearch by lazy {
|
||||||
val magicSearch = coreContext.core.createMagicSearch()
|
val magicSearch = coreContext.core.createMagicSearch()
|
||||||
magicSearch.limitedSearch = false
|
magicSearch.limitedSearch = false
|
||||||
|
@ -155,6 +162,26 @@ class ContactsManager(private val context: Context) {
|
||||||
contacts.add(contact)
|
contacts.add(contact)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
|
fun updateLocalContacts() {
|
||||||
|
localAccountsContacts.clear()
|
||||||
|
|
||||||
|
for (account in coreContext.core.accountList) {
|
||||||
|
val localContact = Contact()
|
||||||
|
localContact.fullName = account.params.identityAddress?.displayName
|
||||||
|
val pictureUri = corePreferences.defaultAccountAvatarPath
|
||||||
|
if (pictureUri != null) {
|
||||||
|
localContact.setContactThumbnailPictureUri(Uri.fromFile(File(pictureUri)))
|
||||||
|
}
|
||||||
|
val address = account.params.identityAddress
|
||||||
|
if (address != null) {
|
||||||
|
localContact.sipAddresses.add(address)
|
||||||
|
localContact.rawSipAddresses.add(address.asStringUriOnly())
|
||||||
|
}
|
||||||
|
localAccountsContacts.add(localContact)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun updateContacts(all: ArrayList<Contact>, sip: ArrayList<Contact>) {
|
fun updateContacts(all: ArrayList<Contact>, sip: ArrayList<Contact>) {
|
||||||
contacts.clear()
|
contacts.clear()
|
||||||
|
@ -163,6 +190,8 @@ class ContactsManager(private val context: Context) {
|
||||||
contacts.addAll(all)
|
contacts.addAll(all)
|
||||||
sipContacts.addAll(sip)
|
sipContacts.addAll(sip)
|
||||||
|
|
||||||
|
updateLocalContacts()
|
||||||
|
|
||||||
Log.i("[Contacts Manager] Async fetching finished, notifying observers")
|
Log.i("[Contacts Manager] Async fetching finished, notifying observers")
|
||||||
for (listener in contactsUpdatedListeners) {
|
for (listener in contactsUpdatedListeners) {
|
||||||
listener.onContactsUpdated()
|
listener.onContactsUpdated()
|
||||||
|
@ -208,6 +237,13 @@ class ContactsManager(private val context: Context) {
|
||||||
|
|
||||||
@Synchronized
|
@Synchronized
|
||||||
fun findContactByAddress(address: Address): Contact? {
|
fun findContactByAddress(address: Address): Contact? {
|
||||||
|
val localContact = localAccountsContacts.find { localContact ->
|
||||||
|
localContact.sipAddresses.find { localAddress ->
|
||||||
|
address.weakEqual(localAddress)
|
||||||
|
} != null
|
||||||
|
}
|
||||||
|
if (localContact != null) return localContact
|
||||||
|
|
||||||
val friend: Friend? = coreContext.core.findFriend(address)
|
val friend: Friend? = coreContext.core.findFriend(address)
|
||||||
val contact: Contact? = friend?.userData as? Contact
|
val contact: Contact? = friend?.userData as? Contact
|
||||||
if (contact != null) return contact
|
if (contact != null) return contact
|
||||||
|
@ -220,10 +256,12 @@ class ContactsManager(private val context: Context) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun addListener(listener: ContactsUpdatedListener) {
|
fun addListener(listener: ContactsUpdatedListener) {
|
||||||
contactsUpdatedListeners.add(listener)
|
contactsUpdatedListeners.add(listener)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Synchronized
|
||||||
fun removeListener(listener: ContactsUpdatedListener) {
|
fun removeListener(listener: ContactsUpdatedListener) {
|
||||||
contactsUpdatedListeners.remove(listener)
|
contactsUpdatedListeners.remove(listener)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue