mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
attachmentId type changed to Long
This commit is contained in:
parent
73c4e44711
commit
625e9f172a
@ -4,29 +4,45 @@ import android.content.Context
|
|||||||
import com.google.protobuf.ByteString
|
import com.google.protobuf.ByteString
|
||||||
import org.session.libsession.database.dto.DatabaseAttachmentDTO
|
import org.session.libsession.database.dto.DatabaseAttachmentDTO
|
||||||
import org.session.libsession.database.MessageDataProvider
|
import org.session.libsession.database.MessageDataProvider
|
||||||
|
import org.session.libsession.database.dto.AttachmentState
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
import org.thoughtcrime.securesms.database.Database
|
import org.thoughtcrime.securesms.database.Database
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||||
|
import org.thoughtcrime.securesms.database.SmsDatabase
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
|
import org.thoughtcrime.securesms.jobs.AttachmentUploadJob
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil
|
import org.thoughtcrime.securesms.util.MediaUtil
|
||||||
|
|
||||||
class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), MessageDataProvider {
|
class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), MessageDataProvider {
|
||||||
override fun getAttachment(uniqueID: String): DatabaseAttachmentDTO? {
|
override fun getAttachment(attachmentId: Long): DatabaseAttachmentDTO? {
|
||||||
|
|
||||||
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
||||||
val uniqueID = uniqueID.toLongOrNull() ?: return null
|
val databaseAttachment = attachmentDatabase.getAttachment(AttachmentId(attachmentId, 0)) ?: return null
|
||||||
val attachmentID = AttachmentId(0, uniqueID)
|
|
||||||
val databaseAttachment = attachmentDatabase.getAttachment(attachmentID) ?: return null
|
|
||||||
|
|
||||||
return databaseAttachment.toDTO()
|
return databaseAttachment.toDTO()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setAttachmentState(attachmentState: AttachmentState, attachment: DatabaseAttachmentDTO, messageID: Long) {
|
||||||
|
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
||||||
|
attachmentDatabase.setTransferState(messageID, AttachmentId(attachment.attachmentId, 0), attachmentState.value)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Throws(Exception::class)
|
||||||
|
override fun uploadAttachment(attachmentId: Long) {
|
||||||
|
val attachmentUploadJob = AttachmentUploadJob(AttachmentId(attachmentId, 0), null)
|
||||||
|
attachmentUploadJob.onRun()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isOutgoingMessage(timestamp: Long): Boolean {
|
||||||
|
val smsDatabase = DatabaseFactory.getSmsDatabase(context)
|
||||||
|
return smsDatabase.isOutgoingMessage(timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extension to DatabaseAttachment class
|
// Extension to DatabaseAttachment class
|
||||||
|
|
||||||
fun DatabaseAttachment.toDTO(): DatabaseAttachmentDTO {
|
fun DatabaseAttachment.toDTO(): DatabaseAttachmentDTO {
|
||||||
var databaseAttachmentDTO = DatabaseAttachmentDTO()
|
var databaseAttachmentDTO = DatabaseAttachmentDTO()
|
||||||
|
databaseAttachmentDTO.attachmentId = this.attachmentId.rowId
|
||||||
databaseAttachmentDTO.contentType = this.contentType
|
databaseAttachmentDTO.contentType = this.contentType
|
||||||
databaseAttachmentDTO.fileName = this.fileName
|
databaseAttachmentDTO.fileName = this.fileName
|
||||||
databaseAttachmentDTO.caption = this.caption
|
databaseAttachmentDTO.caption = this.caption
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
package org.session.libsession.database
|
package org.session.libsession.database
|
||||||
|
|
||||||
|
import org.session.libsession.database.dto.AttachmentState
|
||||||
import org.session.libsession.database.dto.DatabaseAttachmentDTO
|
import org.session.libsession.database.dto.DatabaseAttachmentDTO
|
||||||
|
import org.session.libsession.messaging.messages.visible.Attachment
|
||||||
|
|
||||||
interface MessageDataProvider {
|
interface MessageDataProvider {
|
||||||
|
|
||||||
fun getAttachment(uniqueID: String): DatabaseAttachmentDTO?
|
fun getAttachment(attachmentId: Long): DatabaseAttachmentDTO?
|
||||||
|
|
||||||
|
fun setAttachmentState(attachmentState: AttachmentState, attachment: DatabaseAttachmentDTO, messageID: Long)
|
||||||
|
|
||||||
|
fun isOutgoingMessage(timestamp: Long): Boolean
|
||||||
|
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun uploadAttachment(attachmentId: Long)
|
||||||
|
|
||||||
}
|
}
|
@ -6,6 +6,8 @@ import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|||||||
import kotlin.math.round
|
import kotlin.math.round
|
||||||
|
|
||||||
class DatabaseAttachmentDTO {
|
class DatabaseAttachmentDTO {
|
||||||
|
var attachmentId: Long = 0
|
||||||
|
|
||||||
var contentType: String? = null
|
var contentType: String? = null
|
||||||
|
|
||||||
var fileName: String? = null
|
var fileName: String? = null
|
||||||
|
@ -35,7 +35,7 @@ interface StorageProtocol {
|
|||||||
fun markJobAsSucceeded(job: Job)
|
fun markJobAsSucceeded(job: Job)
|
||||||
fun markJobAsFailed(job: Job)
|
fun markJobAsFailed(job: Job)
|
||||||
fun getAllPendingJobs(type: String): List<Job>
|
fun getAllPendingJobs(type: String): List<Job>
|
||||||
fun getAttachmentUploadJob(attachmentID: String): AttachmentUploadJob?
|
fun getAttachmentUploadJob(attachmentID: Long): AttachmentUploadJob?
|
||||||
fun getMessageSendJob(messageSendJobID: String): MessageSendJob?
|
fun getMessageSendJob(messageSendJobID: String): MessageSendJob?
|
||||||
fun resumeMessageSendJobIfNeeded(messageSendJobID: String)
|
fun resumeMessageSendJobIfNeeded(messageSendJobID: String)
|
||||||
fun isJobCanceled(job: Job): Boolean
|
fun isJobCanceled(job: Job): Boolean
|
||||||
|
@ -8,7 +8,7 @@ class LinkPreview() {
|
|||||||
|
|
||||||
var title: String? = null
|
var title: String? = null
|
||||||
var url: String? = null
|
var url: String? = null
|
||||||
var attachmentID: String? = null
|
var attachmentID: Long? = 0
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "LinkPreview"
|
const val TAG = "LinkPreview"
|
||||||
@ -21,7 +21,7 @@ class LinkPreview() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//constructor
|
//constructor
|
||||||
internal constructor(title: String?, url: String, attachmentID: String?) : this() {
|
internal constructor(title: String?, url: String, attachmentID: Long?) : this() {
|
||||||
this.title = title
|
this.title = title
|
||||||
this.url = url
|
this.url = url
|
||||||
this.attachmentID = attachmentID
|
this.attachmentID = attachmentID
|
||||||
|
@ -11,7 +11,7 @@ class Quote() {
|
|||||||
var timestamp: Long? = 0
|
var timestamp: Long? = 0
|
||||||
var publicKey: String? = null
|
var publicKey: String? = null
|
||||||
var text: String? = null
|
var text: String? = null
|
||||||
var attachmentID: String? = null
|
var attachmentID: Long? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "Quote"
|
const val TAG = "Quote"
|
||||||
@ -25,7 +25,7 @@ class Quote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//constructor
|
//constructor
|
||||||
internal constructor(timestamp: Long, publicKey: String, text: String?, attachmentID: String?) : this() {
|
internal constructor(timestamp: Long, publicKey: String, text: String?, attachmentID: Long?) : this() {
|
||||||
this.timestamp = timestamp
|
this.timestamp = timestamp
|
||||||
this.publicKey = publicKey
|
this.publicKey = publicKey
|
||||||
this.text = text
|
this.text = text
|
||||||
|
@ -11,7 +11,7 @@ import org.session.libsignal.service.internal.push.SignalServiceProtos
|
|||||||
class VisibleMessage : Message() {
|
class VisibleMessage : Message() {
|
||||||
|
|
||||||
var text: String? = null
|
var text: String? = null
|
||||||
var attachmentIDs = ArrayList<String>()
|
var attachmentIDs = ArrayList<Long>()
|
||||||
var quote: Quote? = null
|
var quote: Quote? = null
|
||||||
var linkPreview: LinkPreview? = null
|
var linkPreview: LinkPreview? = null
|
||||||
var contact: Contact? = null
|
var contact: Contact? = null
|
||||||
|
Loading…
Reference in New Issue
Block a user