From 2b88ad68960faa2db082b4f3b94790888af38425 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 10 Sep 2020 18:09:07 +0300 Subject: [PATCH] Sync notifications: fix changes notifications to not show for items we pushed. --- .../syncadapter/syncadapter/SyncManager.kt | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt index 0b15fd2d..0722be42 100644 --- a/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt +++ b/app/src/main/java/com/etesync/syncadapter/syncadapter/SyncManager.kt @@ -381,7 +381,18 @@ constructor(protected val context: Context, protected val account: Account, prot private fun persistItem(item: Item) { synchronized(etebaseLocalCache) { - etebaseLocalCache.itemSet(itemMgr, cachedCollection.col.uid, item) + // FIXME: it's terrible that we are fetching and decrypting the item here - we really don't have to + val cached = etebaseLocalCache.itemGet(itemMgr, cachedCollection.col.uid, item.uid) + if (cached?.item?.etag != item.etag) { + syncItemsTotal++ + + if (item.isDeleted) { + syncItemsDeleted++ + } else { + syncItemsChanged++ + } + etebaseLocalCache.itemSet(itemMgr, cachedCollection.col.uid, item) + } } } @@ -415,6 +426,12 @@ constructor(protected val context: Context, protected val account: Account, prot throw e } } + + when (syncEntry.action) { + ADD -> syncItemsChanged++ + SyncEntry.Actions.DELETE -> syncItemsDeleted++ + SyncEntry.Actions.CHANGE -> syncItemsChanged++ + } } @Throws(IOException::class, CalendarStorageException::class, ContactsStorageException::class) @@ -442,7 +459,6 @@ constructor(protected val context: Context, protected val account: Account, prot // Process new vcards from server val size = items.size var i = 0 - syncItemsTotal += size for (item in items) { if (Thread.interrupted()) { @@ -451,12 +467,6 @@ constructor(protected val context: Context, protected val account: Account, prot i++ Logger.log.info("Processing (${i}/${size}) UID=${item.uid} Etag=${item.etag}") - if (item.isDeleted) { - syncItemsDeleted++ - } else { - syncItemsChanged++ - } - processItem(item) persistItem(item) } @@ -516,13 +526,6 @@ constructor(protected val context: Context, protected val account: Account, prot error = e.toString() } - val action = cEntry.action - when (action) { - ADD -> syncItemsChanged++ - SyncEntry.Actions.DELETE -> syncItemsDeleted++ - SyncEntry.Actions.CHANGE -> syncItemsChanged++ - } - persistSyncEntry(entry.uid, cEntry, error) remoteCTag = entry.uid