mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Merge pull request #1497 from bemusementpark/ses-1948
[SES-1948] Do not fetch quotes recursively
This commit is contained in:
commit
fe29bce70d
@ -40,18 +40,16 @@ object ResendMessageUtilities {
|
|||||||
message.recipient = messageRecord.recipient.address.serialize()
|
message.recipient = messageRecord.recipient.address.serialize()
|
||||||
}
|
}
|
||||||
message.threadID = messageRecord.threadId
|
message.threadID = messageRecord.threadId
|
||||||
if (messageRecord.isMms) {
|
if (messageRecord.isMms && messageRecord is MmsMessageRecord) {
|
||||||
val mmsMessageRecord = messageRecord as MmsMessageRecord
|
messageRecord.linkPreviews.firstOrNull()?.let { message.linkPreview = LinkPreview.from(it) }
|
||||||
if (mmsMessageRecord.linkPreviews.isNotEmpty()) {
|
messageRecord.quote?.quoteModel?.let {
|
||||||
message.linkPreview = LinkPreview.from(mmsMessageRecord.linkPreviews[0])
|
message.quote = Quote.from(it)?.apply {
|
||||||
}
|
if (userBlindedKey != null && publicKey == TextSecurePreferences.getLocalNumber(context)) {
|
||||||
if (mmsMessageRecord.quote != null) {
|
publicKey = userBlindedKey
|
||||||
message.quote = Quote.from(mmsMessageRecord.quote!!.quoteModel)
|
|
||||||
if (userBlindedKey != null && messageRecord.quote!!.author.serialize() == TextSecurePreferences.getLocalNumber(context)) {
|
|
||||||
message.quote!!.publicKey = userBlindedKey
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message.addSignalAttachments(mmsMessageRecord.slideDeck.asAttachments())
|
}
|
||||||
|
message.addSignalAttachments(messageRecord.slideDeck.asAttachments())
|
||||||
}
|
}
|
||||||
val sentTimestamp = message.sentTimestamp
|
val sentTimestamp = message.sentTimestamp
|
||||||
val sender = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
|
val sender = MessagingModuleConfiguration.shared.storage.getUserPublicKey()
|
||||||
|
@ -1147,13 +1147,9 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun readerFor(cursor: Cursor?): Reader {
|
fun readerFor(cursor: Cursor?, getQuote: Boolean = true) = Reader(cursor, getQuote)
|
||||||
return Reader(cursor)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun readerFor(message: OutgoingMediaMessage?, threadId: Long): OutgoingMessageReader {
|
fun readerFor(message: OutgoingMediaMessage?, threadId: Long) = OutgoingMessageReader(message, threadId)
|
||||||
return OutgoingMessageReader(message, threadId)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setQuoteMissing(messageId: Long): Int {
|
fun setQuoteMissing(messageId: Long): Int {
|
||||||
val contentValues = ContentValues()
|
val contentValues = ContentValues()
|
||||||
@ -1217,7 +1213,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class Reader(private val cursor: Cursor?) : Closeable {
|
inner class Reader(private val cursor: Cursor?, private val getQuote: Boolean = true) : Closeable {
|
||||||
val next: MessageRecord?
|
val next: MessageRecord?
|
||||||
get() = if (cursor == null || !cursor.moveToNext()) null else current
|
get() = if (cursor == null || !cursor.moveToNext()) null else current
|
||||||
val current: MessageRecord
|
val current: MessageRecord
|
||||||
@ -1226,7 +1222,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
return if (mmsType == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND.toLong()) {
|
return if (mmsType == PduHeaders.MESSAGE_TYPE_NOTIFICATION_IND.toLong()) {
|
||||||
getNotificationMmsMessageRecord(cursor)
|
getNotificationMmsMessageRecord(cursor)
|
||||||
} else {
|
} else {
|
||||||
getMediaMmsMessageRecord(cursor)
|
getMediaMmsMessageRecord(cursor, getQuote)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1253,20 +1249,10 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
DELIVERY_RECEIPT_COUNT
|
DELIVERY_RECEIPT_COUNT
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
var readReceiptCount = cursor.getInt(cursor.getColumnIndexOrThrow(READ_RECEIPT_COUNT))
|
val readReceiptCount = if (isReadReceiptsEnabled(context)) cursor.getInt(cursor.getColumnIndexOrThrow(READ_RECEIPT_COUNT)) else 0
|
||||||
val subscriptionId = cursor.getInt(cursor.getColumnIndexOrThrow(SUBSCRIPTION_ID))
|
|
||||||
val hasMention = (cursor.getInt(cursor.getColumnIndexOrThrow(HAS_MENTION)) == 1)
|
val hasMention = (cursor.getInt(cursor.getColumnIndexOrThrow(HAS_MENTION)) == 1)
|
||||||
if (!isReadReceiptsEnabled(context)) {
|
val contentLocationBytes: ByteArray? = contentLocation?.takeUnless { it.isEmpty() }?.let(::toIsoBytes)
|
||||||
readReceiptCount = 0
|
val transactionIdBytes: ByteArray? = transactionId?.takeUnless { it.isEmpty() }?.let(::toIsoBytes)
|
||||||
}
|
|
||||||
var contentLocationBytes: ByteArray? = null
|
|
||||||
var transactionIdBytes: ByteArray? = null
|
|
||||||
if (!contentLocation.isNullOrEmpty()) contentLocationBytes = toIsoBytes(
|
|
||||||
contentLocation
|
|
||||||
)
|
|
||||||
if (!transactionId.isNullOrEmpty()) transactionIdBytes = toIsoBytes(
|
|
||||||
transactionId
|
|
||||||
)
|
|
||||||
val slideDeck = SlideDeck(context, MmsNotificationAttachment(status, messageSize))
|
val slideDeck = SlideDeck(context, MmsNotificationAttachment(status, messageSize))
|
||||||
return NotificationMmsMessageRecord(
|
return NotificationMmsMessageRecord(
|
||||||
id, recipient, recipient,
|
id, recipient, recipient,
|
||||||
@ -1277,7 +1263,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMediaMmsMessageRecord(cursor: Cursor): MediaMmsMessageRecord {
|
private fun getMediaMmsMessageRecord(cursor: Cursor, getQuote: Boolean): MediaMmsMessageRecord {
|
||||||
val id = cursor.getLong(cursor.getColumnIndexOrThrow(ID))
|
val id = cursor.getLong(cursor.getColumnIndexOrThrow(ID))
|
||||||
val dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT))
|
val dateSent = cursor.getLong(cursor.getColumnIndexOrThrow(NORMALIZED_DATE_SENT))
|
||||||
val dateReceived = cursor.getLong(
|
val dateReceived = cursor.getLong(
|
||||||
@ -1328,7 +1314,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
.filterNot { o: DatabaseAttachment? -> o in contactAttachments }
|
.filterNot { o: DatabaseAttachment? -> o in contactAttachments }
|
||||||
.filterNot { o: DatabaseAttachment? -> o in previewAttachments }
|
.filterNot { o: DatabaseAttachment? -> o in previewAttachments }
|
||||||
)
|
)
|
||||||
val quote = getQuote(cursor)
|
val quote = if (getQuote) getQuote(cursor) else null
|
||||||
val reactions = get(context).reactionDatabase().getReactions(cursor)
|
val reactions = get(context).reactionDatabase().getReactions(cursor)
|
||||||
return MediaMmsMessageRecord(
|
return MediaMmsMessageRecord(
|
||||||
id, recipient, recipient,
|
id, recipient, recipient,
|
||||||
@ -1381,7 +1367,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
val quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_ID))
|
val quoteId = cursor.getLong(cursor.getColumnIndexOrThrow(QUOTE_ID))
|
||||||
val quoteAuthor = cursor.getString(cursor.getColumnIndexOrThrow(QUOTE_AUTHOR))
|
val quoteAuthor = cursor.getString(cursor.getColumnIndexOrThrow(QUOTE_AUTHOR))
|
||||||
if (quoteId == 0L || quoteAuthor.isNullOrBlank()) return null
|
if (quoteId == 0L || quoteAuthor.isNullOrBlank()) return null
|
||||||
val retrievedQuote = get(context).mmsSmsDatabase().getMessageFor(quoteId, quoteAuthor)
|
val retrievedQuote = get(context).mmsSmsDatabase().getMessageFor(quoteId, quoteAuthor, false)
|
||||||
val quoteText = retrievedQuote?.body
|
val quoteText = retrievedQuote?.body
|
||||||
val quoteMissing = retrievedQuote == null
|
val quoteMissing = retrievedQuote == null
|
||||||
val quoteDeck = (
|
val quoteDeck = (
|
||||||
|
@ -97,9 +97,13 @@ public class MmsSmsDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageFor(long timestamp, String serializedAuthor) {
|
public @Nullable MessageRecord getMessageFor(long timestamp, String serializedAuthor) {
|
||||||
|
return getMessageFor(timestamp, serializedAuthor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable MessageRecord getMessageFor(long timestamp, String serializedAuthor, boolean getQuote) {
|
||||||
|
|
||||||
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 = readerFor(cursor);
|
MmsSmsDatabase.Reader reader = readerFor(cursor, getQuote);
|
||||||
|
|
||||||
MessageRecord messageRecord;
|
MessageRecord messageRecord;
|
||||||
boolean isOwnNumber = Util.isOwnNumber(context, serializedAuthor);
|
boolean isOwnNumber = Util.isOwnNumber(context, serializedAuthor);
|
||||||
@ -635,7 +639,11 @@ public class MmsSmsDatabase extends Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Reader readerFor(@NonNull Cursor cursor) {
|
public Reader readerFor(@NonNull Cursor cursor) {
|
||||||
return new Reader(cursor);
|
return readerFor(cursor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Reader readerFor(@NonNull Cursor cursor, boolean getQuote) {
|
||||||
|
return new Reader(cursor, getQuote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@ -658,11 +666,13 @@ public class MmsSmsDatabase extends Database {
|
|||||||
public class Reader implements Closeable {
|
public class Reader implements Closeable {
|
||||||
|
|
||||||
private final Cursor cursor;
|
private final Cursor cursor;
|
||||||
|
private final boolean getQuote;
|
||||||
private SmsDatabase.Reader smsReader;
|
private SmsDatabase.Reader smsReader;
|
||||||
private MmsDatabase.Reader mmsReader;
|
private MmsDatabase.Reader mmsReader;
|
||||||
|
|
||||||
public Reader(Cursor cursor) {
|
public Reader(Cursor cursor, boolean getQuote) {
|
||||||
this.cursor = cursor;
|
this.cursor = cursor;
|
||||||
|
this.getQuote = getQuote;
|
||||||
}
|
}
|
||||||
|
|
||||||
private SmsDatabase.Reader getSmsReader() {
|
private SmsDatabase.Reader getSmsReader() {
|
||||||
@ -675,7 +685,7 @@ public class MmsSmsDatabase extends Database {
|
|||||||
|
|
||||||
private MmsDatabase.Reader getMmsReader() {
|
private MmsDatabase.Reader getMmsReader() {
|
||||||
if (mmsReader == null) {
|
if (mmsReader == null) {
|
||||||
mmsReader = DatabaseComponent.get(context).mmsDatabase().readerFor(cursor);
|
mmsReader = DatabaseComponent.get(context).mmsDatabase().readerFor(cursor, getQuote);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mmsReader;
|
return mmsReader;
|
||||||
|
Loading…
Reference in New Issue
Block a user