mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-21 12:38:27 +00:00
fix quote attachments
This commit is contained in:
parent
3b2ea4e95d
commit
4218073a69
@ -84,7 +84,8 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAttachmentIDsFor(messageID: Long): List<Long> {
|
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
|
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());
|
return new Pair<>(cursor, leftIsRecent ? cursor.getPosition() : cursor.getCount() - 1 - cursor.getPosition());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ package org.session.libsession.messaging.messages.visible
|
|||||||
|
|
||||||
import android.util.Size
|
import android.util.Size
|
||||||
import android.webkit.MimeTypeMap
|
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.AttachmentTransferProgress
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
|
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.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||||
import java.io.File
|
import java.io.File
|
||||||
@ -50,6 +52,35 @@ class Attachment {
|
|||||||
result. url = proto.url
|
result. url = proto.url
|
||||||
return result
|
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 {
|
enum class Kind {
|
||||||
|
@ -69,13 +69,13 @@ class Quote() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) {
|
private fun addAttachmentsIfNeeded(quoteProto: SignalServiceProtos.DataMessage.Quote.Builder) {
|
||||||
val attachmentID = attachmentID ?: return
|
if (attachmentID == null) return
|
||||||
val attachmentProto = MessagingConfiguration.shared.messageDataProvider.getAttachmentStream(attachmentID)
|
val attachment = MessagingConfiguration.shared.messageDataProvider.getSignalAttachmentPointer(attachmentID!!)
|
||||||
if (attachmentProto == null) {
|
if (attachment == null) {
|
||||||
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
|
Log.w(TAG, "Ignoring invalid attachment for quoted message.")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (!attachmentProto.isUploaded) {
|
if (attachment.url.isNullOrEmpty()) {
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
//TODO equivalent to iOS's preconditionFailure
|
//TODO equivalent to iOS's preconditionFailure
|
||||||
Log.d(TAG,"Sending a message before all associated attachments have been uploaded.")
|
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()
|
val quotedAttachmentProto = SignalServiceProtos.DataMessage.Quote.QuotedAttachment.newBuilder()
|
||||||
quotedAttachmentProto.contentType = attachmentProto.contentType
|
quotedAttachmentProto.contentType = attachment.contentType
|
||||||
val fileName = attachmentProto.fileName?.get()
|
val fileName = attachment.fileName?.get()
|
||||||
fileName?.let { quotedAttachmentProto.fileName = fileName }
|
fileName?.let { quotedAttachmentProto.fileName = fileName }
|
||||||
quotedAttachmentProto.thumbnail = attachmentProto.toProto()
|
quotedAttachmentProto.thumbnail = Attachment.createAttachmentPointer(attachment)
|
||||||
try {
|
try {
|
||||||
quoteProto.addAttachments(quotedAttachmentProto.build())
|
quoteProto.addAttachments(quotedAttachmentProto.build())
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
package org.session.libsession.messaging.messages.visible
|
package org.session.libsession.messaging.messages.visible
|
||||||
|
|
||||||
import com.google.protobuf.ByteString
|
|
||||||
import com.goterl.lazycode.lazysodium.BuildConfig
|
import com.goterl.lazycode.lazysodium.BuildConfig
|
||||||
import org.session.libsession.messaging.MessagingConfiguration
|
import org.session.libsession.messaging.MessagingConfiguration
|
||||||
import org.session.libsession.messaging.messages.Message
|
import org.session.libsession.messaging.messages.Message
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment
|
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
|
||||||
import org.session.libsignal.service.internal.push.SignalServiceProtos.AttachmentPointer
|
|
||||||
import org.session.libsignal.utilities.logging.Log
|
import org.session.libsignal.utilities.logging.Log
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
|
import org.session.libsession.messaging.sending_receiving.attachments.Attachment as SignalAttachment
|
||||||
|
|
||||||
@ -72,7 +69,7 @@ class VisibleMessage : Message() {
|
|||||||
|
|
||||||
override fun toProto(): SignalServiceProtos.Content? {
|
override fun toProto(): SignalServiceProtos.Content? {
|
||||||
val proto = SignalServiceProtos.Content.newBuilder()
|
val proto = SignalServiceProtos.Content.newBuilder()
|
||||||
var attachmentIDs = this.attachmentIDs
|
val attachmentIDs = this.attachmentIDs
|
||||||
val dataMessage: SignalServiceProtos.DataMessage.Builder
|
val dataMessage: SignalServiceProtos.DataMessage.Builder
|
||||||
// Profile
|
// Profile
|
||||||
val profile = profile
|
val profile = profile
|
||||||
@ -116,7 +113,7 @@ class VisibleMessage : Message() {
|
|||||||
Log.d(TAG, "Sending a message before all associated attachments have been uploaded.")
|
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)
|
dataMessage.addAllAttachments(attachmentPointers)
|
||||||
// Sync target
|
// Sync target
|
||||||
if (syncTarget != null) {
|
if (syncTarget != null) {
|
||||||
@ -132,33 +129,4 @@ class VisibleMessage : Message() {
|
|||||||
return null
|
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…
x
Reference in New Issue
Block a user