Skip to content

Commit

Permalink
Revert "Update modification timestamp logic (tasks#2585)"
Browse files Browse the repository at this point in the history
This reverts commit 775289b.
  • Loading branch information
abaker committed Nov 26, 2023
1 parent 14599eb commit ac35002
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 50 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/com/todoroo/astrid/dao/TaskDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,9 @@ class TaskDao @Inject constructor(
}

suspend fun save(task: Task, original: Task?) {
val updated = taskDao.update(task, original)
afterUpdate(updated, original)
if (taskDao.update(task, original)) {
afterUpdate(task, original)
}
}

private suspend fun afterUpdate(task: Task, original: Task?) {
Expand Down
44 changes: 25 additions & 19 deletions app/src/main/java/com/todoroo/astrid/data/Task.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,25 +187,31 @@ data class Task(
val isNew: Boolean
get() = id == NO_ID

fun significantChange(task: Task): Boolean =
id != task.id
|| title != task.title
|| priority != task.priority
|| dueDate != task.dueDate
|| hideUntil != task.hideUntil
|| creationDate != task.creationDate
|| modificationDate != task.modificationDate
|| completionDate != task.completionDate
|| deletionDate != task.deletionDate
|| notes != task.notes
|| estimatedSeconds != task.estimatedSeconds
|| elapsedSeconds != task.elapsedSeconds
|| ringFlags != task.ringFlags
|| recurrence != task.recurrence
|| calendarURI != task.calendarURI
|| parent != task.parent
|| remoteId != task.remoteId
|| order != task.order
fun insignificantChange(task: Task?): Boolean {
if (this === task) {
return true
}
return if (task == null) {
false
} else id == task.id
&& title == task.title
&& priority == task.priority
&& dueDate == task.dueDate
&& hideUntil == task.hideUntil
&& creationDate == task.creationDate
&& modificationDate == task.modificationDate
&& completionDate == task.completionDate
&& deletionDate == task.deletionDate
&& notes == task.notes
&& estimatedSeconds == task.estimatedSeconds
&& elapsedSeconds == task.elapsedSeconds
&& ringFlags == task.ringFlags
&& recurrence == task.recurrence
&& calendarURI == task.calendarURI
&& parent == task.parent
&& remoteId == task.remoteId
&& order == task.order
}

fun googleTaskUpToDate(original: Task?): Boolean {
if (this === original) {
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/java/org/tasks/caldav/iCalendar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ class iCalendar @Inject constructor(
`object` = obj
)
val isNew = caldavTask.id == com.todoroo.astrid.data.Task.NO_ID
val dirty = !isNew && task.modificationDate > caldavTask.lastSync
val dirty = task.modificationDate > caldavTask.lastSync || caldavTask.lastSync == 0L
val local = vtodoCache.getVtodo(calendar, caldavTask)?.let { fromVtodo(it) }
task.applyRemote(remote, local)
caldavTask.applyRemote(remote, local)
Expand Down Expand Up @@ -263,11 +263,7 @@ class iCalendar @Inject constructor(

task.suppressSync()
task.suppressRefresh()
if (isNew) {
taskDao.save(task, null)
} else {
taskDao.save(task)
}
taskDao.save(task)
vtodoCache.putVtodo(calendar, caldavTask, vtodo)
caldavTask.etag = eTag
if (!dirty) {
Expand Down
13 changes: 1 addition & 12 deletions app/src/main/java/org/tasks/caldav/iCalendarMerge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.tasks.caldav

import at.bitfire.ical4android.Task
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.andlib.utility.DateUtilities.now
import com.todoroo.astrid.data.Task.Priority.Companion.HIGH
import com.todoroo.astrid.data.Task.Priority.Companion.LOW
import com.todoroo.astrid.data.Task.Priority.Companion.MEDIUM
Expand All @@ -24,7 +23,6 @@ fun com.todoroo.astrid.data.Task.applyRemote(
): com.todoroo.astrid.data.Task {
applyCompletedAt(remote, local)
applyCreatedAt(remote, local)
applyModified(remote, local)
applyTitle(remote, local)
applyDescription(remote, local)
applyPriority(remote, local)
Expand Down Expand Up @@ -63,16 +61,7 @@ private fun com.todoroo.astrid.data.Task.applyCreatedAt(remote: Task, local: Tas
val localCreated = local?.createdAt?.let { newDateTime(it, UTC) }?.toLocal()?.millis
if (localCreated == null || localCreated == creationDate) {
remote.createdAt?.let {
creationDate = newDateTime(it, UTC).toLocal().millis.coerceAtMost(now())
}
}
}

private fun com.todoroo.astrid.data.Task.applyModified(remote: Task, local: Task?) {
val localModified = local?.lastModified?.let { newDateTime(it, UTC) }?.toLocal()?.millis
if (localModified == null || localModified == modificationDate) {
remote.lastModified?.let {
modificationDate = newDateTime(it, UTC).toLocal().millis.coerceAtMost(now())
creationDate = newDateTime(it, UTC).toLocal().millis
}
}
}
Expand Down
18 changes: 7 additions & 11 deletions app/src/main/java/org/tasks/data/TaskDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,19 +188,15 @@ FROM recursive_tasks
@Insert
abstract suspend fun insert(task: Task): Long

suspend fun update(task: Task, original: Task?): Task =
task
.copy(
modificationDate = when {
original?.let { task.significantChange(it) } == true -> now()
task.modificationDate == 0L -> task.creationDate
else -> task.modificationDate
}
)
.also { updateInternal(it) }
suspend fun update(task: Task, original: Task? = null): Boolean {
if (!task.insignificantChange(original)) {
task.modificationDate = now()
}
return updateInternal(task) == 1
}

@Update
internal abstract suspend fun updateInternal(task: Task)
internal abstract suspend fun updateInternal(task: Task): Int

suspend fun createNew(task: Task): Long {
task.id = NO_ID
Expand Down

0 comments on commit ac35002

Please sign in to comment.