fix: changing the way received timestamp handling happens

This commit is contained in:
jubb 2021-03-23 15:56:15 +11:00
parent 1c1ce1424b
commit fad8cd5ba6
2 changed files with 2 additions and 7 deletions

View File

@ -274,12 +274,7 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
} }
override fun isMessageDuplicated(timestamp: Long, sender: String): Boolean { override fun isMessageDuplicated(timestamp: Long, sender: String): Boolean {
val database = DatabaseFactory.getMmsSmsDatabase(context) return getReceivedMessageTimestamps().contains(timestamp)
return if (sender.isEmpty()) {
database.getMessageForTimestamp(timestamp) != null
} else {
database.getMessageFor(timestamp, sender) != null
}
} }
override fun setUserCount(group: Long, server: String, newValue: Int) { override fun setUserCount(group: Long, server: String, newValue: Int) {

View File

@ -52,7 +52,6 @@ object MessageReceiver {
// will already be in the database but we don't want to treat the message as a duplicate. The isRetry flag is a simple workaround // will already be in the database but we don't want to treat the message as a duplicate. The isRetry flag is a simple workaround
// for this issue. // for this issue.
if (storage.isMessageDuplicated(envelope.timestamp, GroupUtil.doubleEncodeGroupID(envelope.source)) && !isRetry) throw Error.DuplicateMessage if (storage.isMessageDuplicated(envelope.timestamp, GroupUtil.doubleEncodeGroupID(envelope.source)) && !isRetry) throw Error.DuplicateMessage
storage.addReceivedMessageTimestamp(envelope.timestamp)
// Decrypt the contents // Decrypt the contents
val ciphertext = envelope.content ?: throw Error.NoData val ciphertext = envelope.content ?: throw Error.NoData
var plaintext: ByteArray? = null var plaintext: ByteArray? = null
@ -101,6 +100,7 @@ object MessageReceiver {
} }
// Don't process the envelope any further if the message has been handled already // Don't process the envelope any further if the message has been handled already
if (storage.isMessageDuplicated(envelope.timestamp, sender!!) && !isRetry) throw Error.DuplicateMessage if (storage.isMessageDuplicated(envelope.timestamp, sender!!) && !isRetry) throw Error.DuplicateMessage
storage.addReceivedMessageTimestamp(envelope.timestamp)
// Don't process the envelope any further if the sender is blocked // Don't process the envelope any further if the sender is blocked
if (isBlock(sender!!)) throw Error.SenderBlocked if (isBlock(sender!!)) throw Error.SenderBlocked
// Parse the proto // Parse the proto