diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt index dda3b7d7eb..bc0f896a54 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/SessionJobDatabase.kt @@ -23,6 +23,14 @@ class SessionJobDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa fun persistJob(job: Job) { val database = databaseHelper.writableDatabase val contentValues = ContentValues(4) + val existing = database.get(sessionJobTable, "$jobID = ?", arrayOf(job.id!!)) { cursor -> + cursor.count + } ?: 0 + // When adding multiple jobs in rapid succession, timestamps might not be good enough as a unique ID. To + // deal with this we keep track of the number of jobs with a given timestamp and that to the end of the + // timestamp to make it a unique ID. We can't use a random number because we do still want to keep track + // of the order in which the jobs were added. + job.id += existing contentValues.put(jobID, job.id) contentValues.put(jobType, job.getFactoryKey()) contentValues.put(failureCount, job.failureCount)