mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 21:48:26 +00:00
fix: duplicate message send bug on attachments
This commit is contained in:
parent
f7bec07503
commit
f4e5e5e36a
@ -27,7 +27,6 @@ import org.session.libsignal.utilities.KeyHelper
|
||||
import org.session.libsignal.utilities.guava.Optional
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.jobs.RetrieveProfileAvatarJob
|
||||
import org.thoughtcrime.securesms.loki.api.OpenGroupManager
|
||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase
|
||||
@ -190,7 +189,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
|
||||
override fun resumeMessageSendJobIfNeeded(messageSendJobID: String) {
|
||||
val job = DatabaseFactory.getSessionJobDatabase(context).getMessageSendJob(messageSendJobID) ?: return
|
||||
JobQueue.shared.add(job)
|
||||
JobQueue.shared.resumePendingSendMessage(job)
|
||||
}
|
||||
|
||||
override fun isJobCanceled(job: Job): Boolean {
|
||||
|
@ -92,7 +92,7 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
||||
}
|
||||
|
||||
private fun handleSuccess() {
|
||||
Log.w(AttachmentUploadJob.TAG, "Attachment downloaded successfully.")
|
||||
Log.w("AttachmentDownloadJob", "Attachment downloaded successfully.")
|
||||
delegate?.handleJobSucceeded(this)
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ class JobQueue : JobDelegate {
|
||||
private val attachmentDispatcher = Executors.newFixedThreadPool(2).asCoroutineDispatcher()
|
||||
private val scope = GlobalScope + SupervisorJob()
|
||||
private val queue = Channel<Job>(UNLIMITED)
|
||||
private val pendingJobIds = mutableSetOf<String>()
|
||||
|
||||
val timer = Timer()
|
||||
|
||||
@ -86,6 +87,19 @@ class JobQueue : JobDelegate {
|
||||
MessagingModuleConfiguration.shared.storage.persistJob(job)
|
||||
}
|
||||
|
||||
fun resumePendingSendMessage(job: Job) {
|
||||
val id = job.id ?: run {
|
||||
Log.e("Loki", "tried to resume pending send job with no ID")
|
||||
return
|
||||
}
|
||||
if (!pendingJobIds.add(id)) {
|
||||
Log.e("Loki","tried to re-queue pending/in-progress job")
|
||||
return
|
||||
}
|
||||
queue.offer(job)
|
||||
Log.d("Loki", "resumed pending send message $id")
|
||||
}
|
||||
|
||||
fun resumePendingJobs() {
|
||||
if (hasResumedPendingJobs) {
|
||||
Log.d("Loki", "resumePendingJobs() should only be called once.")
|
||||
@ -120,6 +134,7 @@ class JobQueue : JobDelegate {
|
||||
override fun handleJobSucceeded(job: Job) {
|
||||
val jobId = job.id ?: return
|
||||
MessagingModuleConfiguration.shared.storage.markJobAsSucceeded(jobId)
|
||||
pendingJobIds.remove(jobId)
|
||||
}
|
||||
|
||||
override fun handleJobFailed(job: Job, error: Exception) {
|
||||
@ -169,4 +184,7 @@ class JobQueue : JobDelegate {
|
||||
val maxBackoff = (10 * 60).toDouble() // 10 minutes
|
||||
return (1000 * 0.25 * min(maxBackoff, (2.0).pow(job.failureCount))).roundToLong()
|
||||
}
|
||||
|
||||
private fun Job.isSend() = this is MessageSendJob || this is AttachmentUploadJob
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user