Update friends lists subscription when switching default account

This commit is contained in:
Sylvain Berfini 2023-09-07 10:28:52 +02:00
parent b08aa2ae1f
commit 8057e9d0af
4 changed files with 17 additions and 2 deletions

View file

@ -151,8 +151,8 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
friend.nativeUri =
"${ContactsContract.Contacts.CONTENT_LOOKUP_URI}/$lookupKey"
// Disable short term presence
friend.isSubscribesEnabled = false
// Disable peer to peer short term presence
friend.incSubscribePolicy = SubscribePolicy.SPDeny
}

View file

@ -69,7 +69,6 @@ class ContactsManager @UiThread constructor(context: Context) {
override fun onFriendListCreated(core: Core, friendList: FriendList) {
Log.i("$TAG Friend list [${friendList.displayName}] created")
friendList.addListener(friendListListener)
friendList.updateSubscriptions()
}
@WorkerThread

View file

@ -28,6 +28,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.contacts.ContactLoader.Companion.LINPHONE_ADDRESS_BOOK_FRIEND_LIST
import org.linphone.core.Friend
import org.linphone.core.FriendList.Status
import org.linphone.core.SubscribePolicy
import org.linphone.core.tools.Log
import org.linphone.ui.main.contacts.model.NewOrEditNumberOrAddressModel
import org.linphone.utils.Event
@ -128,6 +129,9 @@ class ContactNewOrEditViewModel @UiThread constructor() : ViewModel() {
if (!::friend.isInitialized) {
friend = core.createFriend()
friend.isSubscribesEnabled = false
// Disable peer to peer short term presence
friend.incSubscribePolicy = SubscribePolicy.SPDeny
}
friend.name = "${firstName.value.orEmpty().trim()} ${lastName.value.orEmpty().trim()}"

View file

@ -88,7 +88,19 @@ class AccountModel @WorkerThread constructor(
fun setAsDefault() {
coreContext.postOnCoreThread { core ->
core.defaultAccount = account
for (friendList in core.friendsLists) {
if (friendList.isSubscriptionsEnabled) {
Log.i(
"$TAG Default account has changed, refreshing friend list [${friendList.displayName}] subscriptions"
)
// friendList.updateSubscriptions() won't trigger a refresh unless a friend has changed
friendList.isSubscriptionsEnabled = false
friendList.isSubscriptionsEnabled = true
}
}
}
isDefault.value = true
onSetAsDefault?.invoke(account)
}