Fix unable to delete mms message (#884)

pull/1709/head
SessionHero01 3 months ago committed by GitHub
parent 03b5b40b93
commit eb2f92b8a7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -288,10 +288,11 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
return result
}
fun getMessageServerHash(messageID: Long, mms: Boolean): String? = getMessageTables(mms).firstNotNullOfOrNull {
databaseHelper.readableDatabase.get(it, "${Companion.messageID} = ?", arrayOf(messageID.toString())) { cursor ->
cursor.getString(serverHash)
}
fun getMessageServerHash(messageID: Long, mms: Boolean): String? {
return databaseHelper.readableDatabase.get(
getMessageTable(mms),
"${Companion.messageID} = ?",
arrayOf(messageID.toString())) { cursor -> cursor.getString(serverHash) }
}
fun setMessageServerHash(messageID: Long, mms: Boolean, serverHash: String) {
@ -306,9 +307,7 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
}
fun deleteMessageServerHash(messageID: Long, mms: Boolean) {
getMessageTables(mms).firstOrNull {
databaseHelper.writableDatabase.delete(it, "${Companion.messageID} = ?", arrayOf(messageID.toString())) > 0
}
databaseHelper.writableDatabase.delete(getMessageTable(mms), "${Companion.messageID} = ?", arrayOf(messageID.toString()))
}
fun deleteMessageServerHashes(messageIDs: List<Long>, mms: Boolean) {
@ -347,10 +346,6 @@ class LokiMessageDatabase(context: Context, helper: SQLCipherOpenHelper) : Datab
groupInviteTable, "$threadID = ?", arrayOf(groupThreadId.toString())
)
}
private fun getMessageTables(mms: Boolean) = sequenceOf(
getMessageTable(mms),
messageHashTable
)
private fun getMessageTable(mms: Boolean) = if (mms) mmsHashTable else smsHashTable
}

@ -467,7 +467,11 @@ open class Storage @Inject constructor(
}
message.serverHash?.let { serverHash ->
messageID?.let { id ->
lokiMessageDatabase.setMessageServerHash(id, message.isMediaMessage(), serverHash)
// When a message with attachment is received, we don't immediately have
// attachments attached in the messages, but it's a mms from the db's perspective
// nonetheless.
val isMms = message.isMediaMessage() || attachments.isNotEmpty()
lokiMessageDatabase.setMessageServerHash(id, isMms, serverHash)
}
}
return messageID

Loading…
Cancel
Save