Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Push] Upon notification, only enqueue sync for the respective service type #1175

Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
package at.bitfire.davdroid.push

import android.content.Context
import at.bitfire.davdroid.db.Collection.Companion.TYPE_ADDRESSBOOK
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.SyncDataType
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 +47,9 @@ class UnifiedPushReceiver: MessagingReceiver() {
@Inject
lateinit var pushRegistrationWorkerManager: PushRegistrationWorkerManager

@Inject
lateinit var tasksAppManager: Lazy<TasksAppManager>

@Inject
lateinit var syncWorkerManager: SyncWorkerManager

Expand Down Expand Up @@ -76,8 +83,28 @@ class UnifiedPushReceiver: MessagingReceiver() {
// Later: only sync affected collection and authorities
collectionRepository.getSyncableByTopic(topic)?.let { collection ->
serviceRepository.get(collection.serviceId)?.let { service ->
val syncDataTypes = mutableSetOf<SyncDataType>()
if (collection.type == TYPE_ADDRESSBOOK) {
// If the type is an address book, sync contacts
syncDataTypes.add(SyncDataType.CONTACTS)
} else {
// If not an address book, must be a calendar, add events
syncDataTypes.add(SyncDataType.EVENTS)
ArnyminerZ marked this conversation as resolved.
Show resolved Hide resolved

// If the collection supports tasks, also add the tasks type
if (collection.supportsVJOURNAL != false || collection.supportsVTODO != false) {
// Make sure there's a tasks provider installed
if (tasksAppManager.get().currentProvider() != null) {
syncDataTypes.add(SyncDataType.TASKS)
}
}
}

// Schedule sync for all the types identified
val account = accountRepository.fromName(service.accountName)
syncWorkerManager.enqueueOneTimeAllAuthorities(account, fromPush = true)
for (syncDataType in syncDataTypes) {
syncWorkerManager.enqueueOneTime(account, syncDataType, fromPush = true)
}
}
}

Expand Down
Loading