Skip to content

Commit

Permalink
Added enqueuing of the correct authority
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <[email protected]>
  • Loading branch information
ArnyminerZ committed Dec 16, 2024
1 parent d892dd2 commit d5be215
Showing 1 changed file with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
package at.bitfire.davdroid.push

import android.content.Context
import android.provider.CalendarContract
import at.bitfire.davdroid.R
import at.bitfire.davdroid.db.Collection.Companion.TYPE_ADDRESSBOOK
import at.bitfire.davdroid.db.Collection.Companion.TYPE_CALENDAR
import at.bitfire.davdroid.db.Collection.Companion.TYPE_WEBCAL
import at.bitfire.davdroid.repository.AccountRepository
import at.bitfire.davdroid.repository.DavCollectionRepository
import at.bitfire.davdroid.repository.DavServiceRepository
import at.bitfire.davdroid.repository.PreferenceRepository
import at.bitfire.davdroid.sync.TasksAppManager
import at.bitfire.davdroid.sync.worker.SyncWorkerManager
import dagger.Lazy
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -43,6 +50,9 @@ class UnifiedPushReceiver: MessagingReceiver() {
@Inject
lateinit var pushRegistrationWorkerManager: PushRegistrationWorkerManager

@Inject
lateinit var tasksAppManager: Lazy<TasksAppManager>

@Inject
lateinit var syncWorkerManager: SyncWorkerManager

Expand Down Expand Up @@ -77,7 +87,24 @@ class UnifiedPushReceiver: MessagingReceiver() {
collectionRepository.getSyncableByTopic(topic)?.let { collection ->
serviceRepository.get(collection.serviceId)?.let { service ->
val account = accountRepository.fromName(service.accountName)
syncWorkerManager.enqueueOneTimeAllAuthorities(account, fromPush = true)
val authority = when (collection.type) {
TYPE_ADDRESSBOOK -> context.getString(R.string.address_books_authority)
TYPE_CALENDAR -> CalendarContract.AUTHORITY
TYPE_WEBCAL -> CalendarContract.AUTHORITY
else -> null
}
if (authority == null) {
logger.warning("Tried to sync collection ${collection.id} with an unknown type: ${collection.type}")
return@let
}
syncWorkerManager.enqueueOneTime(account, authority, fromPush = true)

// If the collection supports tasks, also schedule the tasks authority if any
if (collection.supportsVJOURNAL != false || collection.supportsVTODO != false) {
tasksAppManager.get().currentProvider()?.let { taskProvider ->
syncWorkerManager.enqueueOneTime(account, taskProvider.authority, fromPush = true)
}
}
}
}

Expand Down

0 comments on commit d5be215

Please sign in to comment.