Disable alarm sync for synology calendar

pull/1811/head
Alex Baker 3 years ago
parent e8f231b288
commit 494c449fe6

@ -199,9 +199,9 @@ class CaldavSynchronizer @Inject constructor(
resource
.principals(account, calendar)
.let { principalDao.deleteRemoved(calendar.id, it.map(PrincipalAccess::id)) }
fetchChanges(calendar, resource, caldavClient.httpClient)
fetchChanges(account, calendar, resource, caldavClient.httpClient)
if (calendar.access != ACCESS_READ_ONLY) {
pushLocalChanges(calendar, caldavClient.httpClient, resource.href)
pushLocalChanges(account, calendar, caldavClient.httpClient, resource.href)
}
}
setError(account, "")
@ -225,9 +225,11 @@ class CaldavSynchronizer @Inject constructor(
}
private suspend fun fetchChanges(
caldavCalendar: CaldavCalendar,
resource: Response,
httpClient: OkHttpClient) {
account: CaldavAccount,
caldavCalendar: CaldavCalendar,
resource: Response,
httpClient: OkHttpClient
) {
val httpUrl = resource.href
val remoteCtag = resource.ctag
if (caldavCalendar.ctag?.equals(remoteCtag) == true) {
@ -275,7 +277,7 @@ class CaldavSynchronizer @Inject constructor(
return
}
val caldavTask = caldavDao.getTask(caldavCalendar.uuid!!, fileName)
iCal.fromVtodo(caldavCalendar, caldavTask, remote, vtodo, fileName, eTag)
iCal.fromVtodo(account, caldavCalendar, caldavTask, remote, vtodo, fileName, eTag)
}
}
caldavDao
@ -294,13 +296,17 @@ class CaldavSynchronizer @Inject constructor(
}
private suspend fun pushLocalChanges(
caldavCalendar: CaldavCalendar, httpClient: OkHttpClient, httpUrl: HttpUrl) {
account: CaldavAccount,
caldavCalendar: CaldavCalendar,
httpClient: OkHttpClient,
httpUrl: HttpUrl
) {
for (task in caldavDao.getMoved(caldavCalendar.uuid!!)) {
deleteRemoteResource(httpClient, httpUrl, caldavCalendar, task)
}
for (task in taskDao.getCaldavTasksToPush(caldavCalendar.uuid!!)) {
try {
pushTask(caldavCalendar, task, httpClient, httpUrl)
pushTask(account, caldavCalendar, task, httpClient, httpUrl)
} catch (e: IOException) {
Timber.e(e)
}
@ -334,6 +340,7 @@ class CaldavSynchronizer @Inject constructor(
}
private suspend fun pushTask(
account: CaldavAccount,
calendar: CaldavCalendar,
task: Task,
httpClient: OkHttpClient,
@ -347,7 +354,7 @@ class CaldavSynchronizer @Inject constructor(
}
return
}
val data = iCal.toVtodo(calendar, caldavTask, task)
val data = iCal.toVtodo(account, calendar, caldavTask, task)
val requestBody = RequestBody.create(MIME_ICALENDAR, data)
try {
val remote = DavResource(

@ -36,6 +36,8 @@ import org.tasks.data.Alarm
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.AlarmDao
import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavAccount.Companion.SERVER_SYNOLOGY_CALENDAR
import org.tasks.data.CaldavCalendar
import org.tasks.data.CaldavDao
import org.tasks.data.CaldavTask
@ -129,6 +131,7 @@ class iCalendar @Inject constructor(
}
suspend fun toVtodo(
account: CaldavAccount,
calendar: CaldavCalendar,
caldavTask: CaldavTask,
task: com.todoroo.astrid.data.Task
@ -146,10 +149,15 @@ class iCalendar @Inject constructor(
remoteModel = Task()
}
return toVtodo(caldavTask, task, remoteModel)
return toVtodo(account, caldavTask, task, remoteModel)
}
suspend fun toVtodo(caldavTask: CaldavTask, task: com.todoroo.astrid.data.Task, remoteModel: Task): ByteArray {
suspend fun toVtodo(
account: CaldavAccount,
caldavTask: CaldavTask,
task: com.todoroo.astrid.data.Task,
remoteModel: Task
): ByteArray {
remoteModel.applyLocal(caldavTask, task)
val categories = remoteModel.categories
categories.clear()
@ -166,22 +174,25 @@ class iCalendar @Inject constructor(
if (localGeo == null || !localGeo.equalish(remoteModel.geoPosition)) {
remoteModel.geoPosition = localGeo
}
remoteModel.alarms.removeAll(remoteModel.alarms.filtered)
val alarms = alarmDao.getAlarms(task.id)
remoteModel.snooze = alarms.find { it.type == TYPE_SNOOZE }?.time
remoteModel.alarms.addAll(alarms.toVAlarms())
if (account.reminderSync) {
remoteModel.alarms.removeAll(remoteModel.alarms.filtered)
val alarms = alarmDao.getAlarms(task.id)
remoteModel.snooze = alarms.find { it.type == TYPE_SNOOZE }?.time
remoteModel.alarms.addAll(alarms.toVAlarms())
}
val os = ByteArrayOutputStream()
remoteModel.write(os)
return os.toByteArray()
}
suspend fun fromVtodo(
calendar: CaldavCalendar,
existing: CaldavTask?,
remote: Task,
vtodo: String?,
obj: String? = null,
eTag: String? = null
account: CaldavAccount,
calendar: CaldavCalendar,
existing: CaldavTask?,
remote: Task,
vtodo: String?,
obj: String? = null,
eTag: String? = null
) {
val task = existing?.task?.let { taskDao.fetch(it) }
?: taskCreator.createWithValues("").apply {
@ -209,18 +220,21 @@ class iCalendar @Inject constructor(
tagDao.applyTags(task, tagDataDao, getTags(remote.categories))
}
val alarms = alarmDao.getAlarms(task.id).onEach {
it.id = 0
it.task = 0
}
val randomReminders = alarms.filter { it.type == TYPE_RANDOM }
val localReminders =
local?.reminders?.plus(randomReminders) ?: randomReminders
if (alarms.toSet() == localReminders.toSet()) {
val remoteReminders = remote.reminders.plus(randomReminders)
val changed = alarmService.synchronizeAlarms(caldavTask.task, remoteReminders.toMutableSet())
if (changed) {
task.modificationDate = DateUtilities.now()
if (account.reminderSync) {
val alarms = alarmDao.getAlarms(task.id).onEach {
it.id = 0
it.task = 0
}
val randomReminders = alarms.filter { it.type == TYPE_RANDOM }
val localReminders =
local?.reminders?.plus(randomReminders) ?: randomReminders
if (alarms.toSet() == localReminders.toSet()) {
val remoteReminders = remote.reminders.plus(randomReminders)
val changed =
alarmService.synchronizeAlarms(caldavTask.task, remoteReminders.toMutableSet())
if (changed) {
task.modificationDate = DateUtilities.now()
}
}
}

@ -122,6 +122,9 @@ class CaldavAccount : Parcelable {
else -> false
}
val reminderSync: Boolean
get() = serverType != SERVER_SYNOLOGY_CALENDAR
override fun describeContents() = 0
override fun writeToParcel(dest: Parcel, flags: Int) {

@ -98,8 +98,8 @@ class EtebaseSynchronizer @Inject constructor(
caldavDao.update(calendar)
localBroadcastManager.broadcastRefreshList()
}
fetchChanges(client, calendar, collection)
pushLocalChanges(client, calendar, collection)
fetchChanges(account, client, calendar, collection)
pushLocalChanges(account, client, calendar, collection)
}
setError(account, "")
}
@ -117,9 +117,10 @@ class EtebaseSynchronizer @Inject constructor(
}
private suspend fun fetchChanges(
client: EtebaseClient,
caldavCalendar: CaldavCalendar,
collection: Collection
account: CaldavAccount,
client: EtebaseClient,
caldavCalendar: CaldavCalendar,
collection: Collection
) {
if (caldavCalendar.ctag?.equals(collection.stoken) == true) {
Timber.d("${caldavCalendar.name} up to date")
@ -127,7 +128,7 @@ class EtebaseSynchronizer @Inject constructor(
}
Timber.d("updating $caldavCalendar")
client.fetchItems(collection, caldavCalendar) { (stoken, items) ->
applyEntries(caldavCalendar, items, stoken)
applyEntries(account, caldavCalendar, items, stoken)
client.updateCache(collection, items)
}
Timber.d("UPDATE %s", caldavCalendar)
@ -137,9 +138,10 @@ class EtebaseSynchronizer @Inject constructor(
}
private suspend fun pushLocalChanges(
client: EtebaseClient,
caldavCalendar: CaldavCalendar,
collection: Collection
account: CaldavAccount,
client: EtebaseClient,
caldavCalendar: CaldavCalendar,
collection: Collection
) {
val changes = ArrayList<Item>()
for (caldavTask in caldavDao.getMoved(caldavCalendar.uuid!!)) {
@ -163,23 +165,25 @@ class EtebaseSynchronizer @Inject constructor(
client.updateItem(
collection,
caldavTask,
iCal.toVtodo(caldavCalendar, caldavTask, task)
iCal.toVtodo(account, caldavCalendar, caldavTask, task)
)
)
}
}
if (changes.isNotEmpty()) {
client.uploadChanges(collection, changes)
applyEntries(caldavCalendar, changes, isLocalChange = true)
applyEntries(account, caldavCalendar, changes, isLocalChange = true)
client.updateCache(collection, changes)
}
}
private suspend fun applyEntries(
caldavCalendar: CaldavCalendar,
items: List<Item>,
stoken: String? = null,
isLocalChange: Boolean = false) {
account: CaldavAccount,
caldavCalendar: CaldavCalendar,
items: List<Item>,
stoken: String? = null,
isLocalChange: Boolean = false
) {
for (item in items) {
val vtodo = item.contentString
val task = fromVtodo(vtodo) ?: continue
@ -202,7 +206,7 @@ class EtebaseSynchronizer @Inject constructor(
}
} else {
caldavTask?.`object` = item.uid
iCal.fromVtodo(caldavCalendar, caldavTask, task, vtodo, item.uid, null)
iCal.fromVtodo(account, caldavCalendar, caldavTask, task, vtodo, item.uid, null)
}
}
stoken?.let {

@ -90,9 +90,8 @@ class OpenTasksSynchronizer @Inject constructor(
.forEach { taskDeleter.delete(it) }
lists.forEach {
val calendar = toLocalCalendar(it)
val isEteSync = account.uuid?.isEteSync() == true
pushChanges(isEteSync, calendar, it.id)
fetchChanges(isEteSync, calendar, it.ctag, it.id)
pushChanges(account, calendar, it.id)
fetchChanges(account, calendar, it.ctag, it.id)
}
}
@ -113,7 +112,11 @@ class OpenTasksSynchronizer @Inject constructor(
return local
}
private suspend fun pushChanges(isEteSync: Boolean, calendar: CaldavCalendar, listId: Long) {
private suspend fun pushChanges(
account: CaldavAccount,
calendar: CaldavCalendar,
listId: Long
) {
val moved = caldavDao.getMoved(calendar.uuid!!)
val (deleted, updated) = taskDao
.getCaldavTasksToPush(calendar.uuid!!)
@ -127,12 +130,12 @@ class OpenTasksSynchronizer @Inject constructor(
taskDeleter.delete(deleted.map { it.id })
updated.forEach {
push(it, listId, isEteSync)
push(account, it, listId)
}
}
private suspend fun fetchChanges(
isEteSync: Boolean,
account: CaldavAccount,
calendar: CaldavCalendar,
ctag: String?,
listId: Long
@ -146,9 +149,9 @@ class OpenTasksSynchronizer @Inject constructor(
val etags = openTaskDao.getEtags(listId)
etags.forEach { (uid, sync1, version) ->
val caldavTask = caldavDao.getTaskByRemoteId(calendar.uuid!!, uid)
val etag = if (isEteSync) version else sync1
val etag = if (account.isEteSync) version else sync1
if (caldavTask?.etag == null || caldavTask.etag != etag) {
applyChanges(calendar, listId, uid, etag, caldavTask)
applyChanges(account, calendar, listId, uid, etag, caldavTask)
}
}
removeDeleted(calendar.uuid!!, etags.map { it.first })
@ -180,16 +183,16 @@ class OpenTasksSynchronizer @Inject constructor(
}
}
private suspend fun push(task: Task, listId: Long, isEteSync: Boolean) {
private suspend fun push(account: CaldavAccount, task: Task, listId: Long) {
val caldavTask = caldavDao.getTask(task.id) ?: return
val uid = caldavTask.remoteId!!
val androidTask = openTaskDao.getTask(listId, uid)
?: MyAndroidTask(at.bitfire.ical4android.Task())
iCalendar.toVtodo(caldavTask, task, androidTask.task!!)
iCalendar.toVtodo(account, caldavTask, task, androidTask.task!!)
val operations = ArrayList<BatchOperation.CpoBuilder>()
val builder = androidTask.toBuilder(openTaskDao.tasks)
val idxTask = if (androidTask.isNew) {
if (isEteSync) {
if (account.isEteSync) {
builder.withValue(Tasks.SYNC2, uid)
}
builder.withValue(Tasks.LIST_ID, listId)
@ -216,14 +219,20 @@ class OpenTasksSynchronizer @Inject constructor(
}
private suspend fun applyChanges(
calendar: CaldavCalendar,
listId: Long,
uid: String,
etag: String?,
existing: CaldavTask?
account: CaldavAccount,
calendar: CaldavCalendar,
listId: Long,
uid: String,
etag: String?,
existing: CaldavTask?
) {
openTaskDao.getTask(listId, uid)?.let {
iCalendar.fromVtodo(calendar, existing, it.task!!, null, null, etag)
iCalendar.fromVtodo(account, calendar, existing, it.task!!, null, null, etag)
}
}
companion object {
private val CaldavAccount.isEteSync: Boolean
get() = uuid?.isEteSync() == true
}
}
Loading…
Cancel
Save