count 404/deleted as archived
This commit is contained in:
1 file changed
+33
-8
@@ -67,6 +67,12 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
return networkConnected && !offlineMode
|
return networkConnected && !offlineMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun removeDeletedRemoteProject(project: DBProject) {
|
||||||
|
dbHelper.deleteProject(project.id)
|
||||||
|
projectIdsToSync.removeAll { it == project.id }
|
||||||
|
appContext.sendBroadcast(Intent(MainConstants.BROADCAST_PROJECT_SYNCED))
|
||||||
|
}
|
||||||
|
|
||||||
fun addCallbackPull(callback: ICallback) {
|
fun addCallbackPull(callback: ICallback) {
|
||||||
// Callers register on every resume but the list is only drained when a task actually
|
// Callers register on every resume but the list is only drained when a task actually
|
||||||
// starts, so refuse duplicates rather than letting the same callback pile up.
|
// starts, so refuse duplicates rather than letting the same callback pile up.
|
||||||
@@ -167,8 +173,8 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
private var newBillsDialogText = ""
|
private var newBillsDialogText = ""
|
||||||
private var updatedBillsDialogText = ""
|
private var updatedBillsDialogText = ""
|
||||||
private var deletedBillsDialogText = ""
|
private var deletedBillsDialogText = ""
|
||||||
|
|
||||||
private var deferred: Deferred<LoginStatus>? = null
|
private var deferred: Deferred<LoginStatus>? = null
|
||||||
|
private var archivedAfterNotFound = false
|
||||||
|
|
||||||
init {
|
init {
|
||||||
Log.i(TAG, "SYNC TASK project : ${project.remoteId}")
|
Log.i(TAG, "SYNC TASK project : ${project.remoteId}")
|
||||||
@@ -230,9 +236,11 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
}
|
}
|
||||||
Log.i(TAG, "STARTING SYNCHRONIZATION with Cospend version($version)")
|
Log.i(TAG, "STARTING SYNCHRONIZATION with Cospend version($version)")
|
||||||
var status = pushLocalChanges()
|
var status = pushLocalChanges()
|
||||||
|
if (archivedAfterNotFound) return LoginStatus.OK
|
||||||
if (status == LoginStatus.OK) {
|
if (status == LoginStatus.OK) {
|
||||||
status = pullRemoteChanges()
|
status = pullRemoteChanges()
|
||||||
}
|
}
|
||||||
|
if (archivedAfterNotFound) return LoginStatus.OK
|
||||||
Log.i(TAG, "SYNCHRONIZATION FINISHED")
|
Log.i(TAG, "SYNCHRONIZATION FINISHED")
|
||||||
return status
|
return status
|
||||||
}
|
}
|
||||||
@@ -254,6 +262,15 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
preferences.edit { putString(versionKey(), version) }
|
preferences.edit { putString(versionKey(), version) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun archiveOnRemoteNotFound(e: NextcloudHttpRequestFailedException): Boolean {
|
||||||
|
if (project.type != ProjectType.COSPEND || e.statusCode != 404) return false
|
||||||
|
val archivedTs = System.currentTimeMillis() / 1000
|
||||||
|
project.archivedTs = archivedTs
|
||||||
|
dbHelper.updateProject(projId = project.id, newArchivedTs = archivedTs)
|
||||||
|
archivedAfterNotFound = true
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
private fun pushLocalChanges(): LoginStatus {
|
private fun pushLocalChanges(): LoginStatus {
|
||||||
Log.d(TAG, "PUSH LOCAL CHANGES")
|
Log.d(TAG, "PUSH LOCAL CHANGES")
|
||||||
|
|
||||||
@@ -570,9 +587,13 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
LoginStatus.SSO_TOKEN_MISMATCH
|
LoginStatus.SSO_TOKEN_MISMATCH
|
||||||
} catch (e: NextcloudHttpRequestFailedException) {
|
} catch (e: NextcloudHttpRequestFailedException) {
|
||||||
Log.e(TAG, "Catch SSO HTTP req FAILED", e)
|
Log.e(TAG, "Catch SSO HTTP req FAILED", e)
|
||||||
errorMessages.add(getErrorMessageFromException(e))
|
if (archiveOnRemoteNotFound(e)) {
|
||||||
e.cause?.let { exceptions.add(it) }
|
LoginStatus.OK
|
||||||
LoginStatus.REQ_FAILED
|
} else {
|
||||||
|
errorMessages.add(getErrorMessageFromException(e))
|
||||||
|
e.cause?.let { exceptions.add(it) }
|
||||||
|
LoginStatus.REQ_FAILED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,9 +667,13 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
LoginStatus.SSO_TOKEN_MISMATCH
|
LoginStatus.SSO_TOKEN_MISMATCH
|
||||||
} catch (e: NextcloudHttpRequestFailedException) {
|
} catch (e: NextcloudHttpRequestFailedException) {
|
||||||
Log.e(TAG, "Catch NC REQ failed", e)
|
Log.e(TAG, "Catch NC REQ failed", e)
|
||||||
errorMessages.add(getErrorMessageFromException(e))
|
if (archiveOnRemoteNotFound(e)) {
|
||||||
e.cause?.let { exceptions.add(it) }
|
LoginStatus.OK
|
||||||
LoginStatus.REQ_FAILED
|
} else {
|
||||||
|
errorMessages.add(getErrorMessageFromException(e))
|
||||||
|
e.cause?.let { exceptions.add(it) }
|
||||||
|
LoginStatus.REQ_FAILED
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private fun updateLocalProject(projResponse: ServerResponse.ProjectResponse) {
|
private fun updateLocalProject(projResponse: ServerResponse.ProjectResponse) {
|
||||||
@@ -1356,7 +1381,7 @@ class CowspentServerSyncHelper private constructor(private val dbHelper: Cowspen
|
|||||||
appContext.sendBroadcast(Intent(MainConstants.BROADCAST_SSO_TOKEN_MISMATCH))
|
appContext.sendBroadcast(Intent(MainConstants.BROADCAST_SSO_TOKEN_MISMATCH))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dbHelper.deleteProject(project!!.id)
|
removeDeletedRemoteProject(project!!)
|
||||||
}
|
}
|
||||||
callback.onFinish(project?.id?.toString() ?: "", errorString)
|
callback.onFinish(project?.id?.toString() ?: "", errorString)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user