use of SessionServiceAttachment instead if SignalSA

This commit is contained in:
Brice
2020-12-17 14:45:57 +11:00
parent c286efae9d
commit 0467147cfe
6 changed files with 45 additions and 36 deletions

View File

@@ -1,14 +1,18 @@
package org.session.libsession.database
import org.session.libsession.database.dto.AttachmentState
import org.session.libsession.database.dto.DatabaseAttachmentDTO
import org.session.libsession.messaging.messages.visible.Attachment
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentState
import org.session.libsession.messaging.sending_receiving.attachments.SessionServiceAttachmentPointer
import org.session.libsession.messaging.sending_receiving.attachments.SessionServiceAttachmentStream
interface MessageDataProvider {
fun getAttachment(attachmentId: Long): DatabaseAttachmentDTO?
//fun getAttachment(attachmentId: Long): SignalServiceAttachmentStream?
fun setAttachmentState(attachmentState: AttachmentState, attachment: DatabaseAttachmentDTO, messageID: Long)
fun getAttachmentStream(attachmentId: Long): SessionServiceAttachmentStream?
fun getAttachmentPointer(attachmentId: Long): SessionServiceAttachmentPointer?
fun setAttachmentState(attachmentState: AttachmentState, attachmentId: Long, messageID: Long)
fun isOutgoingMessage(timestamp: Long): Boolean

View File

@@ -27,7 +27,7 @@ class MessageSendJob(val message: Message, val destination: Destination) : Job {
val message = message as? VisibleMessage
message?.let {
if(!messageDataProvider.isOutgoingMessage(message.sentTimestamp!!)) return // The message has been deleted
val attachments = message.attachmentIDs.map { messageDataProvider.getAttachment(it) }.filterNotNull()
val attachments = message.attachmentIDs.map { messageDataProvider.getAttachmentStream(it) }.filterNotNull()
val attachmentsToUpload = attachments.filter { !it.isUploaded }
attachmentsToUpload.forEach {
if(MessagingConfiguration.shared.storage.getAttachmentUploadJob(it.attachmentId) != null) {

View File

@@ -44,7 +44,7 @@ class LinkPreview() {
title?.let { linkPreviewProto.title = title }
val attachmentID = attachmentID
attachmentID?.let {
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachment(attachmentID)
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID)
attachmentProto?.let { linkPreviewProto.image = attachmentProto.toProto() }
}
// Build

View File

@@ -60,7 +60,7 @@ class Quote() {
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder, messageDataProvider: MessageDataProvider) {
val attachmentID = attachmentID ?: return
val attachmentProto = messageDataProvider.getAttachment(attachmentID)
val attachmentProto = messageDataProvider.getAttachmentStream(attachmentID)
if (attachmentProto == null) {
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
return
@@ -74,7 +74,7 @@ class Quote() {
}
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
quotedAttachmentProto.contentType = attachmentProto.contentType
val fileName = attachmentProto.fileName
val fileName = attachmentProto.fileName?.get()
fileName?.let { quotedAttachmentProto.fileName = fileName }
quotedAttachmentProto.thumbnail = attachmentProto.toProto()
try {

View File

@@ -90,7 +90,7 @@ class VisibleMessage : Message() {
}
}
//Attachments
val attachments = attachmentIDs.mapNotNull { MessagingConfiguration.shared.messageDataProvider.getAttachment(it) }
val attachments = attachmentIDs.mapNotNull { MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(it) }
if (!attachments.all { it.isUploaded }) {
if (BuildConfig.DEBUG) {
//TODO equivalent to iOS's preconditionFailure