fix quote attachments

pull/469/head
Ryan ZHAO 3 years ago
parent 3b2ea4e95d
commit 4218073a69

@ -84,7 +84,8 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
}
override fun getAttachmentIDsFor(messageID: Long): List<Long> {
return DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageID).map {
return DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(messageID).mapNotNull {
if (it.isQuote) return@mapNotNull null
it.attachmentId.rowId
}
}

@ -45,6 +45,7 @@ public class PagingMediaLoader extends AsyncLoader<Pair<Cursor, Integer>> {
return new Pair<>(cursor, leftIsRecent ? cursor.getPosition() : cursor.getCount() - 1 - cursor.getPosition());
}
}
cursor.close();
return null;
}

@ -2,8 +2,10 @@ package org.session.libsession.messaging.messages.visible
import android.util.Size
import android.webkit.MimeTypeMap
import com.google.protobuf.ByteString
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer
import org.session.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
import org.session.libsignal.service.internal.push.SignalServiceProtos
import java.io.File
@ -50,6 +52,35 @@ class Attachment {
result. url = proto.url
return result
}
fun createAttachmentPointer(attachment: SignalServiceAttachmentPointer): SignalServiceProtos.AttachmentPointer? {
val builder = SignalServiceProtos.AttachmentPointer.newBuilder()
.setContentType(attachment.contentType)
.setId(attachment.id)
.setKey(ByteString.copyFrom(attachment.key))
.setDigest(ByteString.copyFrom(attachment.digest.get()))
.setSize(attachment.size.get())
.setUrl(attachment.url)
if (attachment.fileName.isPresent) {
builder.fileName = attachment.fileName.get()
}
if (attachment.preview.isPresent) {
builder.thumbnail = ByteString.copyFrom(attachment.preview.get())
}
if (attachment.width > 0) {
builder.width = attachment.width
}
if (attachment.height > 0) {
builder.height = attachment.height
}
if (attachment.voiceNote) {
builder.flags = SignalServiceProtos.AttachmentPointer.Flags.VOICE_MESSAGE_VALUE
}
if (attachment.caption.isPresent) {
builder.caption = attachment.caption.get()
}
return builder.build()
}
}
enum class Kind {

@ -69,13 +69,13 @@ class Quote() {
}
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) {
val attachmentID = attachmentID ?: return
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID)
if (attachmentProto == null) {
if (attachmentID == null) return
val attachment = MessagingConfiguration.shared.messageDataProvider.getSignalAttachmentPointer(attachmentID!!)
if (attachment == null) {
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
return
}
if (!attachmentProto.isUploaded) {
if (attachment.url.isNullOrEmpty()) {
if (BuildConfig.DEBUG) {
//TODO equivalent to iOS's preconditionFailure
Log.d(TAG,"Sending a message before all associated attachments have been uploaded.")
@ -83,10 +83,10 @@ class Quote() {
}
}
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
quotedAttachmentProto.contentType = attachmentProto.contentType
val fileName = attachmentProto.fileName?.get()
quotedAttachmentProto.contentType = attachment.contentType
val fileName = attachment.fileName?.get()
fileName?.let { quotedAttachmentProto.fileName = fileName }
quotedAttachmentProto.thumbnail = attachmentProto.toProto()
quotedAttachmentProto.thumbnail = Attachment.createAttachmentPointer(attachment)
try {
quoteProto.addAttachments(quotedAttachmentProto.build())
} catch (e: Exception) {

@ -1,13 +1,10 @@
package org.session.libsession.messaging.messages.visible
import com.google.protobuf.ByteString
import com.goterl.lazycode.lazysodium.BuildConfig
import org.session.libsession.messaging.MessagingConfiguration
import org.session.libsession.messaging.messages.Message
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
import org.session.libsignal.service.api.messages.SignalServiceAttachmentPointer
import org.session.libsignal.service.internal.push.SignalServiceProtos
import org.session.libsignal.service.internal.push.SignalServiceProtos.AttachmentPointer
import org.session.libsignal.utilities.logging.Log
import org.session.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
@ -72,7 +69,7 @@ class VisibleMessage : Message() {
override fun toProto(): SignalServiceProtos.Content? {
val proto = SignalServiceProtos.Content.newBuilder()
var attachmentIDs = this.attachmentIDs
val attachmentIDs = this.attachmentIDs
val dataMessage: SignalServiceProtos.DataMessage.Builder
// Profile
val profile = profile
@ -116,7 +113,7 @@ class VisibleMessage : Message() {
Log.d(TAG, "Sending a message before all associated attachments have been uploaded.")
}
}
val attachmentPointers = attachments.mapNotNull { createAttachmentPointer(it) }
val attachmentPointers = attachments.mapNotNull { Attachment.createAttachmentPointer(it) }
dataMessage.addAllAttachments(attachmentPointers)
// Sync target
if (syncTarget != null) {
@ -132,33 +129,4 @@ class VisibleMessage : Message() {
return null
}
}
private fun createAttachmentPointer(attachment: SignalServiceAttachmentPointer): AttachmentPointer? {
val builder = AttachmentPointer.newBuilder()
.setContentType(attachment.contentType)
.setId(attachment.id)
.setKey(ByteString.copyFrom(attachment.key))
.setDigest(ByteString.copyFrom(attachment.digest.get()))
.setSize(attachment.size.get())
.setUrl(attachment.url)
if (attachment.fileName.isPresent) {
builder.fileName = attachment.fileName.get()
}
if (attachment.preview.isPresent) {
builder.thumbnail = ByteString.copyFrom(attachment.preview.get())
}
if (attachment.width > 0) {
builder.width = attachment.width
}
if (attachment.height > 0) {
builder.height = attachment.height
}
if (attachment.voiceNote) {
builder.flags = AttachmentPointer.Flags.VOICE_MESSAGE_VALUE
}
if (attachment.caption.isPresent) {
builder.caption = attachment.caption.get()
}
return builder.build()
}
}
Loading…
Cancel
Save