Do not update friend list subscriptions when contacts loading has finished if default account isn't registered yet

This commit is contained in:
Sylvain Berfini 2023-02-21 11:51:46 +01:00
parent 8bcc9a2087
commit 785be0b1fd
2 changed files with 9 additions and 4 deletions

View file

@ -59,7 +59,8 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
}
override fun onCreateLoader(id: Int, args: Bundle?): Loader<Cursor> {
Log.i("[Contacts Loader] Loader created")
val lastFetch = coreContext.contactsManager.latestContactFetch
Log.i("[Contacts Loader] Loader created, ${if (lastFetch.isEmpty()) "first fetch" else "last fetch happened at [$lastFetch]"}")
coreContext.contactsManager.fetchInProgress.value = true
val mimeType = ContactsContract.Data.MIMETYPE
@ -267,8 +268,11 @@ class ContactLoader : LoaderManager.LoaderCallbacks<Cursor> {
friends.clear()
Log.i("[Contacts Loader] Friends added")
fl.updateSubscriptions()
Log.i("[Contacts Loader] Subscription(s) updated")
// Only update subscriptions when default account is registered or anytime if it isn't the first contacts fetch
if (core.defaultAccount?.state == RegistrationState.Ok || coreContext.contactsManager.latestContactFetch.isNotEmpty()) {
Log.i("[Contacts Loader] Updating friend list [$fl] subscriptions")
fl.updateSubscriptions()
}
coreContext.contactsManager.fetchFinished()
}

View file

@ -44,6 +44,7 @@ import org.linphone.core.tools.Log
import org.linphone.utils.ImageUtils
import org.linphone.utils.LinphoneUtils
import org.linphone.utils.PermissionHelper
import org.linphone.utils.TimestampUtils
interface ContactsUpdatedListener {
fun onContactsUpdated()
@ -111,7 +112,7 @@ class ContactsManager(private val context: Context) {
fun fetchFinished() {
Log.i("[Contacts Manager] Contacts loader have finished")
latestContactFetch = System.currentTimeMillis().toString()
latestContactFetch = TimestampUtils.timeToString(System.currentTimeMillis(), false)
updateLocalContacts()
fetchInProgress.value = false
notifyListeners()