Improved performances upon presence reception by reducing number of unecessary listener notification

This commit is contained in:
Sylvain Berfini 2022-05-25 09:51:43 +02:00
parent 06abe16bd1
commit 4acbfa2127
3 changed files with 4 additions and 22 deletions

View file

@ -46,20 +46,12 @@ open class GenericContactData(private val sipAddress: Address) : ContactDataInte
val initials = MutableLiveData<String>()
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
override fun onContactUpdated(friend: Friend) {
contactLookup()
}
}
init {
securityLevel.value = ChatRoomSecurityLevel.ClearText
coreContext.contactsManager.addListener(contactsUpdatedListener)
contactLookup()
}
open fun destroy() {
coreContext.contactsManager.removeListener(contactsUpdatedListener)
}
private fun contactLookup() {
@ -81,24 +73,11 @@ abstract class GenericContactViewModel(private val sipAddress: Address) : ErrorR
final override val displayName: MutableLiveData<String> = MutableLiveData<String>()
final override val securityLevel: MutableLiveData<ChatRoomSecurityLevel> = MutableLiveData<ChatRoomSecurityLevel>()
private val contactsUpdatedListener = object : ContactsUpdatedListenerStub() {
override fun onContactUpdated(friend: Friend) {
contactLookup()
}
}
init {
securityLevel.value = ChatRoomSecurityLevel.ClearText
coreContext.contactsManager.addListener(contactsUpdatedListener)
contactLookup()
}
override fun onCleared() {
coreContext.contactsManager.removeListener(contactsUpdatedListener)
super.onCleared()
}
private fun contactLookup() {
displayName.value = LinphoneUtils.getDisplayName(sipAddress)
contact.value = coreContext.contactsManager.findContactByAddress(sipAddress)

View file

@ -41,6 +41,7 @@ import org.linphone.R
import org.linphone.core.Factory
import org.linphone.core.Friend
import org.linphone.core.GlobalState
import org.linphone.core.SubscribePolicy
import org.linphone.core.tools.Log
import org.linphone.utils.LinphoneUtils
import org.linphone.utils.PhoneNumberUtils
@ -136,7 +137,10 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
friend.starred = starred
friend.nativeUri =
"${ContactsContract.Contacts.CONTENT_LOOKUP_URI}/$lookupKey"
// Disable short term presence
friend.isSubscribesEnabled = false
friend.incSubscribePolicy = SubscribePolicy.SPDeny
}
when (mime) {

View file

@ -277,7 +277,6 @@ class ContactsManager(private val context: Context) {
val id = friend.refKey
if (id != null) {
storePresenceInNativeContact(friend)
notifyListeners(friend)
}
}
}