Fix moving data to a Google Tasks account

When moving data to a Google Tasks account from any other synchronized
account, the app could fail to delete the data from the source account
pull/3881/head
Alex Baker 3 months ago
parent 703322f510
commit 0d8979b72c

@ -56,7 +56,7 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1)
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1)
val deleted = googleTaskDao.getDeletedByTaskId(1)
val deleted = googleTaskDao.getDeletedByTaskId(1, "account1")
assertEquals(1, deleted.size.toLong())
assertEquals(1, deleted[0].task)
assertTrue(deleted[0].deleted > 0)
@ -71,7 +71,7 @@ class TaskMoverTest : InjectingTestCase() {
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
googleTaskDao.insert(newCaldavTask(with(TASK, 2), with(CALENDAR, "1")))
moveToGoogleTasks("2", 1)
val deleted = googleTaskDao.getDeletedByTaskId(2)
val deleted = googleTaskDao.getDeletedByTaskId(2, "account1")
assertEquals(1, deleted.size.toLong())
assertEquals(2, deleted[0].task)
assertTrue(deleted[0].deleted > 0)
@ -249,7 +249,7 @@ class TaskMoverTest : InjectingTestCase() {
createTasks(1)
googleTaskDao.insert(newCaldavTask(with(TASK, 1), with(CALENDAR, "1")))
moveToGoogleTasks("1", 1)
assertTrue(googleTaskDao.getDeletedByTaskId(1).isEmpty())
assertTrue(googleTaskDao.getDeletedByTaskId(1, "account1").isEmpty())
assertEquals(1, googleTaskDao.getAllByTaskId(1).size.toLong())
}

@ -182,7 +182,7 @@ class GoogleTaskSynchronizer @Inject constructor(
private suspend fun pushLocalChanges(account: CaldavAccount, gtasksInvoker: GtasksInvoker): Long? {
val tasks = taskDao.getGoogleTasksToPush(account.uuid!!)
for (task in tasks) {
val staleTaskId = pushTask(task, gtasksInvoker)
val staleTaskId = pushTask(task, account.uuid!!, gtasksInvoker)
if (staleTaskId != null) {
return staleTaskId
}
@ -191,8 +191,8 @@ class GoogleTaskSynchronizer @Inject constructor(
}
@Throws(IOException::class)
private suspend fun pushTask(task: org.tasks.data.entity.Task, gtasksInvoker: GtasksInvoker): Long? {
for (deleted in googleTaskDao.getDeletedByTaskId(task.id)) {
private suspend fun pushTask(task: org.tasks.data.entity.Task, account: String, gtasksInvoker: GtasksInvoker): Long? {
for (deleted in googleTaskDao.getDeletedByTaskId(task.id, account)) {
deleted.remoteId?.let {
try {
gtasksInvoker.deleteGtask(deleted.calendar, it)

@ -83,8 +83,15 @@ abstract class GoogleTaskDao {
@Query("SELECT * FROM caldav_tasks WHERE cd_remote_id = :remoteId LIMIT 1")
abstract suspend fun getByRemoteId(remoteId: String): CaldavTask?
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId AND cd_deleted > 0")
abstract suspend fun getDeletedByTaskId(taskId: Long): List<CaldavTask>
@Query("""
SELECT caldav_tasks.*
FROM caldav_tasks
INNER JOIN caldav_lists ON cdl_uuid = cd_calendar
WHERE cd_task = :taskId
AND cd_deleted > 0
AND cdl_account = :account
""")
abstract suspend fun getDeletedByTaskId(taskId: Long, account: String): List<CaldavTask>
@Query("SELECT * FROM caldav_tasks WHERE cd_task = :taskId")
abstract suspend fun getAllByTaskId(taskId: Long): List<CaldavTask>

Loading…
Cancel
Save