mirror of
https://github.com/oxen-io/session-android.git
synced 2025-05-05 01:50:51 +00:00
fix: attachments for quotes no longer doubled up
This commit is contained in:
parent
fad8cd5ba6
commit
611b272493
@ -68,17 +68,17 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
|
|||||||
|
|
||||||
override fun getMessageForQuote(timestamp: Long, author: Address): Long? {
|
override fun getMessageForQuote(timestamp: Long, author: Address): Long? {
|
||||||
val messagingDatabase = DatabaseFactory.getMmsSmsDatabase(context)
|
val messagingDatabase = DatabaseFactory.getMmsSmsDatabase(context)
|
||||||
return messagingDatabase.getMessageFor(timestamp, author)?.id
|
val message = messagingDatabase.getMessageFor(timestamp, author)
|
||||||
|
return message?.id
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAttachmentsAndLinkPreviewFor(messageID: Long): List<Attachment> {
|
override fun getAttachmentsAndLinkPreviewFor(mmsId: Long): List<Attachment> {
|
||||||
val attachmentDatabase = DatabaseFactory.getAttachmentDatabase(context)
|
return DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(mmsId)
|
||||||
return attachmentDatabase.getAttachmentsForMessage(messageID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMessageBodyFor(messageID: Long): String {
|
override fun getMessageBodyFor(timestamp: Long, author: String): String {
|
||||||
val messagingDatabase = DatabaseFactory.getSmsDatabase(context)
|
val messagingDatabase = DatabaseFactory.getMmsSmsDatabase(context)
|
||||||
return messagingDatabase.getMessage(messageID).body
|
return messagingDatabase.getMessageFor(timestamp, author)!!.body
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAttachmentIDsFor(messageID: Long): List<Long> {
|
override fun getAttachmentIDsFor(messageID: Long): List<Long> {
|
||||||
|
@ -37,32 +37,26 @@ import net.sqlcipher.database.SQLiteDatabase;
|
|||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
||||||
|
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId;
|
||||||
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.DatabaseAttachmentAudioExtras;
|
||||||
import org.session.libsession.utilities.MediaTypes;
|
import org.session.libsession.utilities.MediaTypes;
|
||||||
|
import org.session.libsession.utilities.Util;
|
||||||
|
import org.session.libsignal.utilities.JsonUtil;
|
||||||
|
import org.session.libsignal.utilities.externalstorage.ExternalStorageUtil;
|
||||||
import org.session.libsignal.utilities.logging.Log;
|
import org.session.libsignal.utilities.logging.Log;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.AttachmentSecret;
|
import org.thoughtcrime.securesms.crypto.AttachmentSecret;
|
||||||
import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream;
|
import org.thoughtcrime.securesms.crypto.ClassicDecryptingPartInputStream;
|
||||||
import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream;
|
import org.thoughtcrime.securesms.crypto.ModernDecryptingPartInputStream;
|
||||||
import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream;
|
import org.thoughtcrime.securesms.crypto.ModernEncryptingPartOutputStream;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
|
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.Attachment;
|
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentId;
|
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachment;
|
|
||||||
import org.session.libsession.messaging.sending_receiving.attachments.DatabaseAttachmentAudioExtras;
|
|
||||||
|
|
||||||
import org.session.libsignal.utilities.JsonUtil;
|
|
||||||
import org.session.libsession.utilities.Util;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.mms.MediaStream;
|
import org.thoughtcrime.securesms.mms.MediaStream;
|
||||||
import org.thoughtcrime.securesms.mms.MmsException;
|
import org.thoughtcrime.securesms.mms.MmsException;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
import org.thoughtcrime.securesms.util.BitmapDecodingException;
|
||||||
import org.thoughtcrime.securesms.util.BitmapUtil;
|
import org.thoughtcrime.securesms.util.BitmapUtil;
|
||||||
import org.session.libsignal.utilities.externalstorage.ExternalStorageUtil;
|
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||||
import org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData;
|
import org.thoughtcrime.securesms.util.MediaUtil.ThumbnailData;
|
||||||
import org.thoughtcrime.securesms.video.EncryptedMediaDataSource;
|
import org.thoughtcrime.securesms.video.EncryptedMediaDataSource;
|
||||||
@ -240,7 +234,11 @@ public class AttachmentDatabase extends Database {
|
|||||||
null, null, null);
|
null, null, null);
|
||||||
|
|
||||||
while (cursor != null && cursor.moveToNext()) {
|
while (cursor != null && cursor.moveToNext()) {
|
||||||
results.addAll(getAttachment(cursor));
|
List<DatabaseAttachment> attachments = getAttachment(cursor);
|
||||||
|
for (DatabaseAttachment attachment : attachments) {
|
||||||
|
if (attachment.isQuote()) continue;
|
||||||
|
results.add(attachment);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
|
@ -18,19 +18,19 @@ package org.thoughtcrime.securesms.database;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import net.sqlcipher.database.SQLiteDatabase;
|
import net.sqlcipher.database.SQLiteDatabase;
|
||||||
import net.sqlcipher.database.SQLiteQueryBuilder;
|
import net.sqlcipher.database.SQLiteQueryBuilder;
|
||||||
|
|
||||||
|
import org.session.libsession.messaging.threads.Address;
|
||||||
|
import org.session.libsession.utilities.Util;
|
||||||
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
import org.thoughtcrime.securesms.database.MessagingDatabase.SyncMessageId;
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
||||||
|
|
||||||
import org.session.libsession.messaging.threads.Address;
|
|
||||||
import org.session.libsession.utilities.Util;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -79,18 +79,16 @@ public class MmsSmsDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageForTimestamp(long timestamp) {
|
public @Nullable MessageRecord getMessageForTimestamp(long timestamp) {
|
||||||
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
|
||||||
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
||||||
MmsSmsDatabase.Reader reader = db.readerFor(cursor);
|
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
||||||
return reader.getNext();
|
return reader.getNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageFor(long timestamp, String serializedAuthor) {
|
public @Nullable MessageRecord getMessageFor(long timestamp, String serializedAuthor) {
|
||||||
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
|
||||||
|
|
||||||
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
||||||
MmsSmsDatabase.Reader reader = db.readerFor(cursor);
|
MmsSmsDatabase.Reader reader = readerFor(cursor);
|
||||||
|
|
||||||
MessageRecord messageRecord;
|
MessageRecord messageRecord;
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ interface MessageDataProvider {
|
|||||||
|
|
||||||
// Quotes
|
// Quotes
|
||||||
fun getMessageForQuote(timestamp: Long, author: Address): Long?
|
fun getMessageForQuote(timestamp: Long, author: Address): Long?
|
||||||
fun getAttachmentsAndLinkPreviewFor(messageID: Long): List<Attachment>
|
fun getAttachmentsAndLinkPreviewFor(mmsId: Long): List<Attachment>
|
||||||
fun getMessageBodyFor(messageID: Long): String
|
fun getMessageBodyFor(timestamp: Long, author: String): String
|
||||||
|
|
||||||
fun getAttachmentIDsFor(messageID: Long): List<Long>
|
fun getAttachmentIDsFor(messageID: Long): List<Long>
|
||||||
fun getLinkPreviewAttachmentIDFor(messageID: Long): Long?
|
fun getLinkPreviewAttachmentIDFor(messageID: Long): Long?
|
||||||
|
@ -72,7 +72,7 @@ public class IncomingMediaMessage {
|
|||||||
Optional<QuoteModel> quote,
|
Optional<QuoteModel> quote,
|
||||||
Optional<List<LinkPreview>> linkPreviews)
|
Optional<List<LinkPreview>> linkPreviews)
|
||||||
{
|
{
|
||||||
return new IncomingMediaMessage(from, message.getReceivedTimestamp(), -1, expiresIn, false,
|
return new IncomingMediaMessage(from, message.getSentTimestamp(), -1, expiresIn, false,
|
||||||
false, Optional.fromNullable(message.getText()), group, Optional.fromNullable(attachments), quote, Optional.absent(), linkPreviews);
|
false, Optional.fromNullable(message.getText()), group, Optional.fromNullable(attachments), quote, Optional.absent(), linkPreviews);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +154,8 @@ fun MessageReceiver.handleVisibleMessage(message: VisibleMessage, proto: SignalS
|
|||||||
val author = Address.fromSerialized(quote.author)
|
val author = Address.fromSerialized(quote.author)
|
||||||
val messageID = MessagingConfiguration.shared.messageDataProvider.getMessageForQuote(quote.id, author)
|
val messageID = MessagingConfiguration.shared.messageDataProvider.getMessageForQuote(quote.id, author)
|
||||||
if (messageID != null) {
|
if (messageID != null) {
|
||||||
val attachmentsWithLinkPreview = MessagingConfiguration.shared.messageDataProvider.getAttachmentsAndLinkPreviewFor(messageID)
|
val attachments = MessagingConfiguration.shared.messageDataProvider.getAttachmentsAndLinkPreviewFor(messageID)
|
||||||
quoteModel = QuoteModel(quote.id, author, MessagingConfiguration.shared.messageDataProvider.getMessageBodyFor(messageID), false, attachmentsWithLinkPreview)
|
quoteModel = QuoteModel(quote.id, author, MessagingConfiguration.shared.messageDataProvider.getMessageBodyFor(quote.id, quote.author), false, attachments)
|
||||||
} else {
|
} else {
|
||||||
quoteModel = QuoteModel(quote.id, author, quote.text, true, PointerAttachment.forPointers(proto.dataMessage.quote.attachmentsList))
|
quoteModel = QuoteModel(quote.id, author, quote.text, true, PointerAttachment.forPointers(proto.dataMessage.quote.attachmentsList))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user