mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-18 23:08:27 +00:00
timestamp & duplicated message
This commit is contained in:
parent
e14b5b9f33
commit
b517555a45
@ -78,6 +78,14 @@ public class MmsSmsDatabase extends Database {
|
|||||||
super(context, databaseHelper);
|
super(context, databaseHelper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public @Nullable MessageRecord getMessageForTimestamp(long timestamp) {
|
||||||
|
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
||||||
|
try (Cursor cursor = queryTables(PROJECTION, MmsSmsColumns.NORMALIZED_DATE_SENT + " = " + timestamp, null, null)) {
|
||||||
|
MmsSmsDatabase.Reader reader = db.readerFor(cursor);
|
||||||
|
return reader.getNext();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public @Nullable MessageRecord getMessageFor(long messageId) {
|
public @Nullable MessageRecord getMessageFor(long messageId) {
|
||||||
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
MmsSmsDatabase db = DatabaseFactory.getMmsSmsDatabase(context);
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ import org.session.libsignal.utilities.logging.Log
|
|||||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase
|
import org.thoughtcrime.securesms.loki.database.LokiThreadDatabase
|
||||||
|
import org.thoughtcrime.securesms.loki.protocol.SessionMetaProtocol
|
||||||
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
|
import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities
|
||||||
import org.thoughtcrime.securesms.loki.utilities.get
|
import org.thoughtcrime.securesms.loki.utilities.get
|
||||||
import org.thoughtcrime.securesms.loki.utilities.getString
|
import org.thoughtcrime.securesms.loki.utilities.getString
|
||||||
@ -279,6 +280,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
DatabaseFactory.getLokiAPIDatabase(context).removeLastDeletionServerID(group, server)
|
DatabaseFactory.getLokiAPIDatabase(context).removeLastDeletionServerID(group, server)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun isMessageDuplicated(timestamp: Long, sender: String): Boolean {
|
||||||
|
val database = DatabaseFactory.getMmsSmsDatabase(context)
|
||||||
|
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) {
|
||||||
DatabaseFactory.getLokiAPIDatabase(context).setUserCount(group, server, newValue)
|
DatabaseFactory.getLokiAPIDatabase(context).setUserCount(group, server, newValue)
|
||||||
}
|
}
|
||||||
@ -300,16 +310,16 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getReceivedMessageTimestamps(): Set<Long> {
|
override fun getReceivedMessageTimestamps(): Set<Long> {
|
||||||
TODO("Not yet implemented")
|
return SessionMetaProtocol.getTimestamps()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun addReceivedMessageTimestamp(timestamp: Long) {
|
override fun addReceivedMessageTimestamp(timestamp: Long) {
|
||||||
TODO("Not yet implemented")
|
SessionMetaProtocol.addTimestamp(timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun removeReceivedMessageTimestamps(timestamps: Set<Long>) {
|
// override fun removeReceivedMessageTimestamps(timestamps: Set<Long>) {
|
||||||
TODO("Not yet implemented")
|
// TODO("Not yet implemented")
|
||||||
}
|
// }
|
||||||
|
|
||||||
override fun getMessageIdInDatabase(timestamp: Long, author: String): Long? {
|
override fun getMessageIdInDatabase(timestamp: Long, author: String): Long? {
|
||||||
val database = DatabaseFactory.getMmsSmsDatabase(context)
|
val database = DatabaseFactory.getMmsSmsDatabase(context)
|
||||||
|
@ -21,6 +21,14 @@ object SessionMetaProtocol {
|
|||||||
timestamps.remove(timestamp)
|
timestamps.remove(timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getTimestamps(): Set<Long> {
|
||||||
|
return timestamps
|
||||||
|
}
|
||||||
|
|
||||||
|
fun addTimestamp(timestamp: Long) {
|
||||||
|
timestamps.add(timestamp)
|
||||||
|
}
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun shouldIgnoreMessage(timestamp: Long): Boolean {
|
fun shouldIgnoreMessage(timestamp: Long): Boolean {
|
||||||
val shouldIgnoreMessage = timestamps.contains(timestamp)
|
val shouldIgnoreMessage = timestamps.contains(timestamp)
|
||||||
|
@ -86,9 +86,10 @@ interface StorageProtocol {
|
|||||||
fun removeLastDeletionServerID(group: Long, server: String)
|
fun removeLastDeletionServerID(group: Long, server: String)
|
||||||
|
|
||||||
// Message Handling
|
// Message Handling
|
||||||
|
fun isMessageDuplicated(timestamp: Long, sender: String): Boolean
|
||||||
fun getReceivedMessageTimestamps(): Set<Long>
|
fun getReceivedMessageTimestamps(): Set<Long>
|
||||||
fun addReceivedMessageTimestamp(timestamp: Long)
|
fun addReceivedMessageTimestamp(timestamp: Long)
|
||||||
fun removeReceivedMessageTimestamps(timestamps: Set<Long>)
|
// fun removeReceivedMessageTimestamps(timestamps: Set<Long>)
|
||||||
// Returns the IDs of the saved attachments.
|
// Returns the IDs of the saved attachments.
|
||||||
fun persistAttachments(messageId: Long, attachments: List<Attachment>): List<Long>
|
fun persistAttachments(messageId: Long, attachments: List<Attachment>): List<Long>
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ object MessageReceiver {
|
|||||||
// If the message failed to process the first time around we retry it later (if the error is retryable). In this case the timestamp
|
// If the message failed to process the first time around we retry it later (if the error is retryable). In this case the timestamp
|
||||||
// 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.getReceivedMessageTimestamps().contains(envelope.timestamp) && !isRetry) throw Error.DuplicateMessage
|
if (storage.isMessageDuplicated(envelope.timestamp, envelope.source) && !isRetry) throw Error.DuplicateMessage
|
||||||
storage.addReceivedMessageTimestamp(envelope.timestamp)
|
storage.addReceivedMessageTimestamp(envelope.timestamp)
|
||||||
// Decrypt the contents
|
// Decrypt the contents
|
||||||
val ciphertext = envelope.content ?: throw Error.NoData
|
val ciphertext = envelope.content ?: throw Error.NoData
|
||||||
|
Loading…
x
Reference in New Issue
Block a user