Remove AuthInfo when creating CardDAV entry if synchronization fails

This commit is contained in:
Sylvain Berfini 2025-11-18 14:38:22 +01:00
parent 41e6776b32
commit 5ed68e0171

View file

@ -26,6 +26,7 @@ import org.linphone.LinphoneApplication.Companion.coreContext
import org.linphone.LinphoneApplication.Companion.corePreferences
import org.linphone.R
import org.linphone.contacts.ContactLoader.Companion.LINPHONE_ADDRESS_BOOK_FRIEND_LIST
import org.linphone.core.AuthInfo
import org.linphone.core.Factory
import org.linphone.core.FriendList
import org.linphone.core.FriendListListenerStub
@ -60,6 +61,8 @@ class CardDavViewModel
val isReadOnly = MutableLiveData<Boolean>()
var pendingAuthInfo: AuthInfo? = null
val syncSuccessfulEvent: MutableLiveData<Event<Boolean>> by lazy {
MutableLiveData<Event<Boolean>>()
}
@ -109,9 +112,16 @@ class CardDavViewModel
syncInProgress.postValue(false)
showRedToast(R.string.settings_contacts_carddav_sync_error_toast, R.drawable.warning_circle)
if (isEdit.value == false) {
Log.e("$TAG Synchronization failed, removing Friend list from Core")
Log.e("$TAG Synchronization failed, removing Friend list & AuthInfo from Core")
friendList.removeListener(this)
coreContext.core.removeFriendList(friendList)
val authInfo = pendingAuthInfo
if (authInfo != null) {
Log.i("$TAG Removing pending auth info [${authInfo.username}] with realm [${authInfo.realm}]")
coreContext.core.removeAuthInfo(authInfo)
pendingAuthInfo = null
}
}
}
else -> {}
@ -147,6 +157,7 @@ class CardDavViewModel
friendList = found
friendList.addListener(friendListListener)
isReadOnly.postValue(friendList.isReadOnly)
pendingAuthInfo = null
displayName.postValue(name)
storeNewContactsInIt.postValue(
@ -168,6 +179,14 @@ class CardDavViewModel
)
corePreferences.friendListInWhichStoreNewlyCreatedFriends = LINPHONE_ADDRESS_BOOK_FRIEND_LIST
}
val authInfo = pendingAuthInfo
if (authInfo != null) {
Log.i("$TAG Removing pending auth info [${authInfo.username}] with realm [${authInfo.realm}]")
core.removeAuthInfo(authInfo)
pendingAuthInfo = null
}
core.removeFriendList(friendList)
Log.i("$TAG Removed friends list with display name [$name]")
showGreenToast(R.string.settings_contacts_carddav_deleted_toast, R.drawable.trash_simple)
@ -224,6 +243,7 @@ class CardDavViewModel
authRealm,
null
)
pendingAuthInfo = authInfo
core.addAuthInfo(authInfo)
}