mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-12 13:37:56 +00:00
refactor: make storage reference jobId by string in deletion, don't persist jobs we are about to delete, delete jobs that fail to serialize from storage (probably from corrupt or moved data classes) in temporary message send jobs
This commit is contained in:
@@ -103,7 +103,6 @@ import dagger.ObjectGraph;
|
||||
import kotlin.Unit;
|
||||
import kotlinx.coroutines.Job;
|
||||
import network.loki.messenger.BuildConfig;
|
||||
import nl.komponents.kovenant.Kovenant;
|
||||
|
||||
import static nl.komponents.kovenant.android.KovenantAndroid.startKovenant;
|
||||
import static nl.komponents.kovenant.android.KovenantAndroid.stopKovenant;
|
||||
|
@@ -185,15 +185,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
DatabaseFactory.getSessionJobDatabase(context).persistJob(job)
|
||||
}
|
||||
|
||||
override fun markJobAsSucceeded(job: Job) {
|
||||
DatabaseFactory.getSessionJobDatabase(context).markJobAsSucceeded(job)
|
||||
override fun markJobAsSucceeded(jobId: String) {
|
||||
DatabaseFactory.getSessionJobDatabase(context).markJobAsSucceeded(jobId)
|
||||
}
|
||||
|
||||
override fun markJobAsFailed(job: Job) {
|
||||
DatabaseFactory.getSessionJobDatabase(context).markJobAsFailed(job)
|
||||
override fun markJobAsFailed(jobId: String) {
|
||||
DatabaseFactory.getSessionJobDatabase(context).markJobAsFailed(jobId)
|
||||
}
|
||||
|
||||
override fun getAllPendingJobs(type: String): List<Job> {
|
||||
override fun getAllPendingJobs(type: String): Map<String, Job?> {
|
||||
return DatabaseFactory.getSessionJobDatabase(context).getAllPendingJobs(type)
|
||||
}
|
||||
|
||||
|
@@ -4,6 +4,7 @@ import android.content.ContentValues
|
||||
import android.content.Context
|
||||
import net.sqlcipher.Cursor
|
||||
import org.session.libsession.messaging.jobs.*
|
||||
import org.session.libsignal.utilities.logging.Log
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.jobmanager.impl.JsonDataSerializer
|
||||
@@ -30,19 +31,25 @@ class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
||||
database.insertOrUpdate(sessionJobTable, contentValues, "$jobID = ?", arrayOf(jobID))
|
||||
}
|
||||
|
||||
fun markJobAsSucceeded(job: Job) {
|
||||
databaseHelper.writableDatabase.delete(sessionJobTable, "$jobID = ?", arrayOf(job.id))
|
||||
fun markJobAsSucceeded(jobId: String) {
|
||||
databaseHelper.writableDatabase.delete(sessionJobTable, "$jobID = ?", arrayOf(jobId))
|
||||
}
|
||||
|
||||
fun markJobAsFailed(job: Job) {
|
||||
databaseHelper.writableDatabase.delete(sessionJobTable, "$jobID = ?", arrayOf(job.id))
|
||||
fun markJobAsFailed(jobId: String) {
|
||||
databaseHelper.writableDatabase.delete(sessionJobTable, "$jobID = ?", arrayOf(jobId))
|
||||
}
|
||||
|
||||
fun getAllPendingJobs(type: String): List<Job> {
|
||||
fun getAllPendingJobs(type: String): Map<String, Job?> {
|
||||
val database = databaseHelper.readableDatabase
|
||||
return database.getAll(sessionJobTable, "$jobType = ?", arrayOf(type)) { cursor ->
|
||||
jobFromCursor(cursor)
|
||||
}
|
||||
val jobId = cursor.getString(jobID)
|
||||
try {
|
||||
jobId to jobFromCursor(cursor)
|
||||
} catch (e: Exception) {
|
||||
Log.e("Loki", "Error serializing Job of type $type",e)
|
||||
jobId to null
|
||||
}
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
fun getAttachmentUploadJob(attachmentID: Long): AttachmentUploadJob? {
|
||||
|
Reference in New Issue
Block a user