mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-10 01:18:33 +00:00
Fix quote retrieval crash (#944)
Co-authored-by: charles <charles@oxen.io>
This commit is contained in:
parent
25eff4fece
commit
2bfc8215d4
@ -19,7 +19,6 @@ package org.thoughtcrime.securesms.database
|
|||||||
import android.content.ContentValues
|
import android.content.ContentValues
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.Cursor
|
import android.database.Cursor
|
||||||
import android.text.TextUtils
|
|
||||||
import com.annimon.stream.Stream
|
import com.annimon.stream.Stream
|
||||||
import com.google.android.mms.pdu_alt.NotificationInd
|
import com.google.android.mms.pdu_alt.NotificationInd
|
||||||
import com.google.android.mms.pdu_alt.PduHeaders
|
import com.google.android.mms.pdu_alt.PduHeaders
|
||||||
@ -497,7 +496,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
var networkFailures: List<NetworkFailure?>? = LinkedList()
|
var networkFailures: List<NetworkFailure?>? = LinkedList()
|
||||||
var mismatches: List<IdentityKeyMismatch?>? = LinkedList()
|
var mismatches: List<IdentityKeyMismatch?>? = LinkedList()
|
||||||
var quote: QuoteModel? = null
|
var quote: QuoteModel? = null
|
||||||
if (quoteId > 0 && (!TextUtils.isEmpty(quoteText) || quoteAttachments.isNotEmpty())) {
|
if (quoteId > 0 && (!quoteText.isNullOrEmpty() || quoteAttachments.isNotEmpty())) {
|
||||||
quote = QuoteModel(
|
quote = QuoteModel(
|
||||||
quoteId,
|
quoteId,
|
||||||
fromSerialized(quoteAuthor),
|
fromSerialized(quoteAuthor),
|
||||||
@ -506,7 +505,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
quoteAttachments
|
quoteAttachments
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(mismatchDocument)) {
|
if (!mismatchDocument.isNullOrEmpty()) {
|
||||||
try {
|
try {
|
||||||
mismatches = JsonUtil.fromJson(
|
mismatches = JsonUtil.fromJson(
|
||||||
mismatchDocument,
|
mismatchDocument,
|
||||||
@ -516,7 +515,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
Log.w(TAG, e)
|
Log.w(TAG, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(networkDocument)) {
|
if (!networkDocument.isNullOrEmpty()) {
|
||||||
try {
|
try {
|
||||||
networkFailures =
|
networkFailures =
|
||||||
JsonUtil.fromJson(networkDocument, NetworkFailureList::class.java).list
|
JsonUtil.fromJson(networkDocument, NetworkFailureList::class.java).list
|
||||||
@ -553,7 +552,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
attachments: List<DatabaseAttachment>
|
attachments: List<DatabaseAttachment>
|
||||||
): List<Contact> {
|
): List<Contact> {
|
||||||
val serializedContacts = cursor.getString(cursor.getColumnIndexOrThrow(SHARED_CONTACTS))
|
val serializedContacts = cursor.getString(cursor.getColumnIndexOrThrow(SHARED_CONTACTS))
|
||||||
if (TextUtils.isEmpty(serializedContacts)) {
|
if (serializedContacts.isNullOrEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
val attachmentIdMap: MutableMap<AttachmentId?, DatabaseAttachment> = HashMap()
|
val attachmentIdMap: MutableMap<AttachmentId?, DatabaseAttachment> = HashMap()
|
||||||
@ -591,7 +590,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
attachments: List<DatabaseAttachment>
|
attachments: List<DatabaseAttachment>
|
||||||
): List<LinkPreview> {
|
): List<LinkPreview> {
|
||||||
val serializedPreviews = cursor.getString(cursor.getColumnIndexOrThrow(LINK_PREVIEWS))
|
val serializedPreviews = cursor.getString(cursor.getColumnIndexOrThrow(LINK_PREVIEWS))
|
||||||
if (TextUtils.isEmpty(serializedPreviews)) {
|
if (serializedPreviews.isNullOrEmpty()) {
|
||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
val attachmentIdMap: MutableMap<AttachmentId?, DatabaseAttachment> = HashMap()
|
val attachmentIdMap: MutableMap<AttachmentId?, DatabaseAttachment> = HashMap()
|
||||||
@ -898,7 +897,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
val serializedContacts =
|
val serializedContacts =
|
||||||
getSerializedSharedContacts(insertedAttachments, sharedContacts)
|
getSerializedSharedContacts(insertedAttachments, sharedContacts)
|
||||||
val serializedPreviews = getSerializedLinkPreviews(insertedAttachments, linkPreviews)
|
val serializedPreviews = getSerializedLinkPreviews(insertedAttachments, linkPreviews)
|
||||||
if (!TextUtils.isEmpty(serializedContacts)) {
|
if (!serializedContacts.isNullOrEmpty()) {
|
||||||
val contactValues = ContentValues()
|
val contactValues = ContentValues()
|
||||||
contactValues.put(SHARED_CONTACTS, serializedContacts)
|
contactValues.put(SHARED_CONTACTS, serializedContacts)
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
@ -912,7 +911,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
Log.w(TAG, "Failed to update message with shared contact data.")
|
Log.w(TAG, "Failed to update message with shared contact data.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!TextUtils.isEmpty(serializedPreviews)) {
|
if (!serializedPreviews.isNullOrEmpty()) {
|
||||||
val contactValues = ContentValues()
|
val contactValues = ContentValues()
|
||||||
contactValues.put(LINK_PREVIEWS, serializedPreviews)
|
contactValues.put(LINK_PREVIEWS, serializedPreviews)
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
@ -1316,11 +1315,11 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
var contentLocationBytes: ByteArray? = null
|
var contentLocationBytes: ByteArray? = null
|
||||||
var transactionIdBytes: ByteArray? = null
|
var transactionIdBytes: ByteArray? = null
|
||||||
if (!TextUtils.isEmpty(contentLocation)) contentLocationBytes = toIsoBytes(
|
if (!contentLocation.isNullOrEmpty()) contentLocationBytes = toIsoBytes(
|
||||||
contentLocation!!
|
contentLocation
|
||||||
)
|
)
|
||||||
if (!TextUtils.isEmpty(transactionId)) transactionIdBytes = toIsoBytes(
|
if (!transactionId.isNullOrEmpty()) transactionIdBytes = toIsoBytes(
|
||||||
transactionId!!
|
transactionId
|
||||||
)
|
)
|
||||||
val slideDeck = SlideDeck(context, MmsNotificationAttachment(status, messageSize))
|
val slideDeck = SlideDeck(context, MmsNotificationAttachment(status, messageSize))
|
||||||
return NotificationMmsMessageRecord(
|
return NotificationMmsMessageRecord(
|
||||||
@ -1402,16 +1401,16 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getRecipientFor(serialized: String?): Recipient {
|
private fun getRecipientFor(serialized: String?): Recipient {
|
||||||
val address: Address = if (TextUtils.isEmpty(serialized) || "insert-address-token" == serialized) {
|
val address: Address = if (serialized.isNullOrEmpty() || "insert-address-token" == serialized) {
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
} else {
|
} else {
|
||||||
fromSerialized(serialized!!)
|
fromSerialized(serialized)
|
||||||
}
|
}
|
||||||
return Recipient.from(context, address, true)
|
return Recipient.from(context, address, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getMismatchedIdentities(document: String?): List<IdentityKeyMismatch?>? {
|
private fun getMismatchedIdentities(document: String?): List<IdentityKeyMismatch?>? {
|
||||||
if (!TextUtils.isEmpty(document)) {
|
if (!document.isNullOrEmpty()) {
|
||||||
try {
|
try {
|
||||||
return JsonUtil.fromJson(document, IdentityKeyMismatchList::class.java).list
|
return JsonUtil.fromJson(document, IdentityKeyMismatchList::class.java).list
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
@ -1422,7 +1421,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getFailures(document: String?): List<NetworkFailure?>? {
|
private fun getFailures(document: String?): List<NetworkFailure?>? {
|
||||||
if (!TextUtils.isEmpty(document)) {
|
if (!document.isNullOrEmpty()) {
|
||||||
try {
|
try {
|
||||||
return JsonUtil.fromJson(document, NetworkFailureList::class.java).list
|
return JsonUtil.fromJson(document, NetworkFailureList::class.java).list
|
||||||
} catch (ioe: IOException) {
|
} catch (ioe: IOException) {
|
||||||
@ -1442,6 +1441,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
private fun getQuote(cursor: Cursor): Quote? {
|
private fun getQuote(cursor: Cursor): Quote? {
|
||||||
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
|
||||||
val retrievedQuote = get(context).mmsSmsDatabase().getMessageFor(quoteId, quoteAuthor)
|
val retrievedQuote = get(context).mmsSmsDatabase().getMessageFor(quoteId, quoteAuthor)
|
||||||
val quoteText = retrievedQuote?.body
|
val quoteText = retrievedQuote?.body
|
||||||
val quoteMissing = retrievedQuote == null
|
val quoteMissing = retrievedQuote == null
|
||||||
@ -1450,17 +1450,13 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa
|
|||||||
Stream.of(attachments).filter { obj: DatabaseAttachment? -> obj!!.isQuote }
|
Stream.of(attachments).filter { obj: DatabaseAttachment? -> obj!!.isQuote }
|
||||||
.toList()
|
.toList()
|
||||||
val quoteDeck = SlideDeck(context, quoteAttachments!!)
|
val quoteDeck = SlideDeck(context, quoteAttachments!!)
|
||||||
return if (quoteId > 0 && !TextUtils.isEmpty(quoteAuthor)) {
|
return Quote(
|
||||||
Quote(
|
quoteId,
|
||||||
quoteId,
|
fromExternal(context, quoteAuthor),
|
||||||
fromExternal(context, quoteAuthor),
|
quoteText,
|
||||||
quoteText,
|
quoteMissing,
|
||||||
quoteMissing,
|
quoteDeck
|
||||||
quoteDeck
|
)
|
||||||
)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user