mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-17 13:58:25 +00:00
fix sending link preview
This commit is contained in:
parent
4218073a69
commit
0a7fecfb52
@ -9,7 +9,6 @@ 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
|
||||
@ -90,6 +89,11 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLinkPreviewAttachmentIDFor(messageID: Long): Long? {
|
||||
val message = DatabaseFactory.getMmsDatabase(context).getOutgoingMessage(messageID)
|
||||
return message.linkPreviews.firstOrNull()?.attachmentId?.rowId
|
||||
}
|
||||
|
||||
override fun insertAttachment(messageId: Long, attachmentId: Long, stream: InputStream) {
|
||||
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
||||
attachmentDatabase.insertAttachmentsForPlaceholder(messageId, AttachmentId(attachmentId, 0), stream)
|
||||
@ -216,7 +220,7 @@ fun DatabaseAttachment.toSignalAttachmentPointer(): SignalServiceAttachmentPoint
|
||||
SignalServiceAttachmentPointer(id,
|
||||
contentType,
|
||||
key,
|
||||
Optional.of(toIntExact(size)),
|
||||
Optional.of(Util.toIntExact(size)),
|
||||
Optional.absent(),
|
||||
width,
|
||||
height,
|
||||
|
@ -196,15 +196,6 @@ public class AttachmentDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsStickerPackId(@NonNull String stickerPackId) {
|
||||
String selection = STICKER_PACK_ID + " = ?";
|
||||
String[] args = new String[] { stickerPackId };
|
||||
|
||||
try (Cursor cursor = databaseHelper.getReadableDatabase().query(TABLE_NAME, null, selection, args, null, null, "1")) {
|
||||
return cursor != null && cursor.moveToFirst();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTransferProgressFailed(AttachmentId attachmentId, long mmsId)
|
||||
throws MmsException
|
||||
{
|
||||
|
@ -36,5 +36,6 @@ interface MessageDataProvider {
|
||||
fun getMessageBodyFor(messageID: Long): String
|
||||
|
||||
fun getAttachmentIDsFor(messageID: Long): List<Long>
|
||||
fun getLinkPreviewAttachmentIDFor(messageID: Long): Long?
|
||||
|
||||
}
|
@ -32,7 +32,11 @@ 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.mapNotNull { messageDataProvider.getDatabaseAttachment(it) }
|
||||
val attachmentIDs = mutableListOf<Long>()
|
||||
attachmentIDs.addAll(message.attachmentIDs)
|
||||
message.quote?.let { it.attachmentID?.let { attachmentID -> attachmentIDs.add(attachmentID) } }
|
||||
message.linkPreview?.let { it.attachmentID?.let { attachmentID -> attachmentIDs.add(attachmentID) } }
|
||||
val attachments = attachmentIDs.mapNotNull { messageDataProvider.getDatabaseAttachment(it) }
|
||||
val attachmentsToUpload = attachments.filter { it.url.isNullOrEmpty() }
|
||||
attachmentsToUpload.forEach {
|
||||
if (MessagingConfiguration.shared.storage.getAttachmentUploadJob(it.attachmentId.rowId) != null) {
|
||||
|
@ -53,8 +53,10 @@ class LinkPreview() {
|
||||
title?.let { linkPreviewProto.title = title }
|
||||
val attachmentID = attachmentID
|
||||
attachmentID?.let {
|
||||
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID)
|
||||
attachmentProto?.let { linkPreviewProto.image = attachmentProto.toProto() }
|
||||
MessagingConfiguration.shared.messageDataProvider.getSignalAttachmentPointer(attachmentID)?.let {
|
||||
val attachmentProto = Attachment.createAttachmentPointer(it)
|
||||
linkPreviewProto.image = attachmentProto
|
||||
}
|
||||
}
|
||||
// Build
|
||||
try {
|
||||
|
@ -69,7 +69,6 @@ class VisibleMessage : Message() {
|
||||
|
||||
override fun toProto(): SignalServiceProtos.Content? {
|
||||
val proto = SignalServiceProtos.Content.newBuilder()
|
||||
val attachmentIDs = this.attachmentIDs
|
||||
val dataMessage: SignalServiceProtos.DataMessage.Builder
|
||||
// Profile
|
||||
val profile = profile
|
||||
|
@ -282,10 +282,19 @@ object MessageSender {
|
||||
// Convenience
|
||||
@JvmStatic
|
||||
fun send(message: VisibleMessage, address: Address, attachments: List<SignalAttachment>, quote: SignalQuote?, linkPreview: SignalLinkPreview?) {
|
||||
val attachmentIDs = MessagingConfiguration.shared.messageDataProvider.getAttachmentIDsFor(message.id!!)
|
||||
val dataProvider = MessagingConfiguration.shared.messageDataProvider
|
||||
val attachmentIDs = dataProvider.getAttachmentIDsFor(message.id!!)
|
||||
message.attachmentIDs.addAll(attachmentIDs)
|
||||
message.quote = Quote.from(quote)
|
||||
message.linkPreview = LinkPreview.from(linkPreview)
|
||||
message.linkPreview?.let {
|
||||
if (it.attachmentID == null) {
|
||||
dataProvider.getLinkPreviewAttachmentIDFor(message.id!!)?.let {
|
||||
message.linkPreview!!.attachmentID = it
|
||||
message.attachmentIDs.remove(it)
|
||||
}
|
||||
}
|
||||
}
|
||||
send(message, address)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user