mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 17:27:42 +00:00
implementation of persistAttachments + refactoring
This commit is contained in:
@@ -39,7 +39,7 @@ interface StorageProtocol {
|
||||
fun getOrGenerateRegistrationID(): Int
|
||||
|
||||
// Jobs
|
||||
fun persist(job: Job)
|
||||
fun persistJob(job: Job)
|
||||
fun markJobAsSucceeded(job: Job)
|
||||
fun markJobAsFailed(job: Job)
|
||||
fun getAllPendingJobs(type: String): List<Job>
|
||||
@@ -86,7 +86,7 @@ interface StorageProtocol {
|
||||
fun getReceivedMessageTimestamps(): Set<Long>
|
||||
fun addReceivedMessageTimestamp(timestamp: Long)
|
||||
// Returns the IDs of the saved attachments.
|
||||
fun persist(attachments: List<Attachment>): List<Long>
|
||||
fun persistAttachments(messageId: Long, attachments: List<Attachment>): List<Long>
|
||||
|
||||
fun getMessageIdInDatabase(timestamp: Long, author: String): Long?
|
||||
fun setOpenGroupServerMessageID(messageID: Long, serverID: Long)
|
||||
|
@@ -25,7 +25,7 @@ class JobQueue : JobDelegate {
|
||||
|
||||
fun addWithoutExecuting(job: Job) {
|
||||
job.id = System.currentTimeMillis().toString()
|
||||
MessagingConfiguration.shared.storage.persist(job)
|
||||
MessagingConfiguration.shared.storage.persistJob(job)
|
||||
job.delegate = this
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class JobQueue : JobDelegate {
|
||||
return
|
||||
}
|
||||
hasResumedPendingJobs = true
|
||||
val allJobTypes = listOf(AttachmentDownloadJob.collection, AttachmentDownloadJob.collection, MessageReceiveJob.collection, MessageSendJob.collection, NotifyPNServerJob.collection)
|
||||
val allJobTypes = listOf(AttachmentDownloadJob.KEY, AttachmentDownloadJob.KEY, MessageReceiveJob.KEY, MessageSendJob.KEY, NotifyPNServerJob.KEY)
|
||||
allJobTypes.forEach { type ->
|
||||
val allPendingJobs = MessagingConfiguration.shared.storage.getAllPendingJobs(type)
|
||||
allPendingJobs.sortedBy { it.id }.forEach { job ->
|
||||
@@ -54,7 +54,7 @@ class JobQueue : JobDelegate {
|
||||
job.failureCount += 1
|
||||
val storage = MessagingConfiguration.shared.storage
|
||||
if (storage.isJobCanceled(job)) { return Log.i("Jobs", "${job::class.simpleName} canceled.")}
|
||||
storage.persist(job)
|
||||
storage.persistJob(job)
|
||||
if (job.failureCount == job.maxFailureCount) {
|
||||
storage.markJobAsFailed(job)
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ class JobQueue : JobDelegate {
|
||||
override fun handleJobFailedPermanently(job: Job, error: Exception) {
|
||||
job.failureCount += 1
|
||||
val storage = MessagingConfiguration.shared.storage
|
||||
storage.persist(job)
|
||||
storage.persistJob(job)
|
||||
storage.markJobAsFailed(job)
|
||||
}
|
||||
|
||||
|
@@ -3,6 +3,7 @@ package org.session.libsession.messaging.messages.visible
|
||||
import android.util.Size
|
||||
import android.webkit.MimeTypeMap
|
||||
import org.session.libsession.database.MessageDataProvider
|
||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
|
||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||
import java.io.File
|
||||
|
||||
@@ -64,4 +65,10 @@ class Attachment {
|
||||
fun toProto(): SignalServiceProtos.AttachmentPointer? {
|
||||
TODO("Not implemented")
|
||||
}
|
||||
|
||||
fun toDatabaseAttachment(): org.session.libsession.messaging.sending_receiving.attachments.Attachment {
|
||||
return DatabaseAttachment(null, 0, true, true, contentType, 0,
|
||||
sizeInBytes?.toLong() ?: 0, fileName, null, key.toString(), null, digest, null, kind == Kind.VOICE_MESSAGE,
|
||||
size?.width ?: 0, size?.height ?: 0, false, caption, null, url)
|
||||
}
|
||||
}
|
@@ -117,7 +117,7 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalS
|
||||
return@mapNotNull attachment
|
||||
}
|
||||
}
|
||||
val attachmentIDs = storage.persist(attachments)
|
||||
val attachmentIDs = storage.persistAttachments(message.id ?: 0, attachments)
|
||||
message.attachmentIDs = attachmentIDs as ArrayList<Long>
|
||||
var attachmentsToDownload = attachmentIDs
|
||||
// Update profile if needed
|
||||
|
@@ -72,7 +72,7 @@ object MessageSender {
|
||||
attachments.add(attachment)
|
||||
}
|
||||
}
|
||||
val attachmentIDs = MessagingConfiguration.shared.storage.persist(attachments)
|
||||
val attachmentIDs = MessagingConfiguration.shared.storage.persistAttachments(message.id ?: 0, attachments)
|
||||
message.attachmentIDs.addAll(attachmentIDs)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user