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 2 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 @@ -77,7 +84,20 @@ 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 syncDataType = if (collection.type == TYPE_ADDRESSBOOK) {
SyncDataType.CONTACTS
} else {
SyncDataType.EVENTS
}
syncWorkerManager.enqueueOneTime(account, syncDataType, fromPush = true)

// If the collection supports tasks, also schedule the tasks type
if (collection.supportsVJOURNAL != false || collection.supportsVTODO != false) {
// Make sure there's a tasks provider installed
if (tasksAppManager.get().currentProvider() != null) {
syncWorkerManager.enqueueOneTime(account, SyncDataType.TASKS, fromPush = true)
}
}
ArnyminerZ marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
Loading