mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 13:48:26 +00:00
fix sending attachments including link previews
This commit is contained in:
parent
0fcef2d542
commit
c51593a914
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.attachments
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import com.google.protobuf.ByteString
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
import org.session.libsession.database.MessageDataProvider
|
||||
@ -8,16 +9,19 @@ import org.session.libsession.messaging.sending_receiving.attachments.*
|
||||
import org.session.libsession.messaging.threads.Address
|
||||
import org.session.libsession.messaging.utilities.DotNetAPI
|
||||
import org.session.libsession.utilities.Util
|
||||
import org.session.libsession.utilities.Util.toIntExact
|
||||
import org.session.libsignal.libsignal.util.guava.Optional
|
||||
import org.session.libsignal.service.api.messages.SignalServiceAttachment
|
||||
import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer
|
||||
import org.session.libsignal.service.api.messages.SignalServiceAttachmentStream
|
||||
import org.session.libsignal.utilities.Base64
|
||||
import org.session.libsignal.utilities.logging.Log
|
||||
import org.thoughtcrime.securesms.database.AttachmentDatabase
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.events.PartProgressEvent
|
||||
import org.thoughtcrime.securesms.jobs.PushSendJob
|
||||
import org.thoughtcrime.securesms.mms.MediaConstraints
|
||||
import org.thoughtcrime.securesms.mms.PartAuthority
|
||||
import org.thoughtcrime.securesms.transport.UndeliverableMessageException
|
||||
@ -202,8 +206,28 @@ fun DatabaseAttachment.toAttachmentStream(context: Context): SessionServiceAttac
|
||||
return attachmentStream
|
||||
}
|
||||
|
||||
fun DatabaseAttachment.toSignalAttachmentPointer(): SignalServiceAttachmentPointer {
|
||||
return SignalServiceAttachmentPointer(attachmentId.rowId, contentType, key?.toByteArray(), Optional.fromNullable(size.toInt()), Optional.absent(), width, height, Optional.fromNullable(digest), Optional.fromNullable(fileName), isVoiceNote, Optional.fromNullable(caption), url)
|
||||
fun DatabaseAttachment.toSignalAttachmentPointer(): SignalServiceAttachmentPointer? {
|
||||
if (TextUtils.isEmpty(location)) { return null }
|
||||
if (TextUtils.isEmpty(key)) { return null }
|
||||
|
||||
return try {
|
||||
val id: Long = location!!.toLong()
|
||||
val key: ByteArray = Base64.decode(key!!)
|
||||
SignalServiceAttachmentPointer(id,
|
||||
contentType,
|
||||
key,
|
||||
Optional.of(toIntExact(size)),
|
||||
Optional.absent(),
|
||||
width,
|
||||
height,
|
||||
Optional.fromNullable(digest),
|
||||
Optional.fromNullable(fileName),
|
||||
isVoiceNote,
|
||||
Optional.fromNullable(caption),
|
||||
url)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
fun DatabaseAttachment.toSignalAttachmentStream(context: Context): SignalServiceAttachmentStream {
|
||||
|
@ -107,7 +107,7 @@ class AttachmentUploadJob(val attachmentID: Long, val threadID: String, val mess
|
||||
private fun failAssociatedMessageSendJob(e: Exception) {
|
||||
val storage = MessagingConfiguration.shared.storage
|
||||
val messageSendJob = storage.getMessageSendJob(messageSendJobID)
|
||||
MessageSender.handleFailedMessageSend(this.message!!, e)
|
||||
MessageSender.handleFailedMessageSend(this.message, e)
|
||||
if (messageSendJob != null) {
|
||||
storage.markJobAsFailed(messageSendJob)
|
||||
}
|
||||
|
@ -59,25 +59,6 @@ object MessageSender {
|
||||
}
|
||||
}
|
||||
|
||||
// Preparation
|
||||
fun prep(signalAttachments: List<SignalAttachment>, message: VisibleMessage) {
|
||||
val attachments = mutableListOf<Attachment>()
|
||||
for (signalAttachment in signalAttachments) {
|
||||
val attachment = Attachment()
|
||||
attachment.fileName = signalAttachment.fileName
|
||||
attachment.caption = signalAttachment.caption
|
||||
attachment.contentType = signalAttachment.contentType
|
||||
attachment.digest = signalAttachment.digest
|
||||
attachment.key = Base64.decode(signalAttachment.key ?: "")
|
||||
attachment.sizeInBytes = signalAttachment.size.toInt()
|
||||
attachment.url = signalAttachment.url
|
||||
attachment.size = Size(signalAttachment.width, signalAttachment.height)
|
||||
attachments.add(attachment)
|
||||
}
|
||||
val attachmentIDs = MessagingConfiguration.shared.messageDataProvider.getAttachmentIDsFor(message.id!!)
|
||||
message.attachmentIDs.addAll(attachmentIDs)
|
||||
}
|
||||
|
||||
// Convenience
|
||||
fun send(message: Message, destination: Destination): Promise<Unit, Exception> {
|
||||
if (destination is Destination.OpenGroup) {
|
||||
@ -299,7 +280,8 @@ object MessageSender {
|
||||
// Convenience
|
||||
@JvmStatic
|
||||
fun send(message: VisibleMessage, address: Address, attachments: List<SignalAttachment>, quote: SignalQuote?, linkPreview: SignalLinkPreview?) {
|
||||
prep(attachments, message)
|
||||
val attachmentIDs = MessagingConfiguration.shared.messageDataProvider.getAttachmentIDsFor(message.id!!)
|
||||
message.attachmentIDs.addAll(attachmentIDs)
|
||||
message.quote = Quote.from(quote)
|
||||
message.linkPreview = LinkPreview.from(linkPreview)
|
||||
send(message, address)
|
||||
@ -315,7 +297,8 @@ object MessageSender {
|
||||
}
|
||||
|
||||
fun sendNonDurably(message: VisibleMessage, attachments: List<SignalAttachment>, address: Address): Promise<Unit, Exception> {
|
||||
prep(attachments, message)
|
||||
val attachmentIDs = MessagingConfiguration.shared.messageDataProvider.getAttachmentIDsFor(message.id!!)
|
||||
message.attachmentIDs.addAll(attachmentIDs)
|
||||
return sendNonDurably(message, address)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user