mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 10:17:56 +00:00
Add process read sync tests.
This commit is contained in:
@@ -136,7 +136,6 @@ import org.thoughtcrime.securesms.util.MessageConstraintsUtil
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.util.Util
|
||||
import org.thoughtcrime.securesms.util.isStory
|
||||
import org.whispersystems.signalservice.api.messages.multidevice.ReadMessage
|
||||
import org.whispersystems.signalservice.api.push.ServiceId
|
||||
import org.whispersystems.signalservice.internal.push.SyncMessage
|
||||
import java.io.Closeable
|
||||
@@ -4379,17 +4378,17 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
/**
|
||||
* @return Unhandled ids
|
||||
*/
|
||||
fun setTimestampReadFromSyncMessage(readMessages: List<ReadMessage>, proposedExpireStarted: Long, threadToLatestRead: MutableMap<Long, Long>): Collection<SyncMessageId> {
|
||||
fun setTimestampReadFromSyncMessage(readMessages: List<SyncMessage.Read>, proposedExpireStarted: Long, threadToLatestRead: MutableMap<Long, Long>): Collection<SyncMessageId> {
|
||||
val expiringMessages: MutableList<Pair<Long, Long>> = mutableListOf()
|
||||
val updatedThreads: MutableSet<Long> = mutableSetOf()
|
||||
val unhandled: MutableCollection<SyncMessageId> = mutableListOf()
|
||||
|
||||
writableDatabase.withinTransaction {
|
||||
for (readMessage in readMessages) {
|
||||
val authorId: RecipientId = recipients.getOrInsertFromServiceId(readMessage.sender)
|
||||
val authorId: RecipientId = recipients.getOrInsertFromServiceId(ServiceId.parseOrThrow(readMessage.senderAci!!))
|
||||
|
||||
val result: TimestampReadResult = setTimestampReadFromSyncMessageInternal(
|
||||
messageId = SyncMessageId(authorId, readMessage.timestamp),
|
||||
messageId = SyncMessageId(authorId, readMessage.timestamp!!),
|
||||
proposedExpireStarted = proposedExpireStarted,
|
||||
threadToLatestRead = threadToLatestRead
|
||||
)
|
||||
@@ -4398,7 +4397,7 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
updatedThreads += result.threads
|
||||
|
||||
if (result.threads.isEmpty()) {
|
||||
unhandled += SyncMessageId(authorId, readMessage.timestamp)
|
||||
unhandled += SyncMessageId(authorId, readMessage.timestamp!!)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4419,12 +4418,6 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
|
||||
return unhandled
|
||||
}
|
||||
|
||||
fun setTimestampReadFromSyncMessageProto(readMessages: List<SyncMessage.Read>, proposedExpireStarted: Long, threadToLatestRead: MutableMap<Long, Long>): Collection<SyncMessageId> {
|
||||
val reads: List<ReadMessage> = readMessages.map { r -> ReadMessage(ServiceId.parseOrThrow(r.senderAci!!), r.timestamp!!) }
|
||||
|
||||
return setTimestampReadFromSyncMessage(reads, proposedExpireStarted, threadToLatestRead)
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a synchronized read message.
|
||||
* @param messageId An id representing the author-timestamp pair of the message that was read on a linked device. Note that the author could be self when
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.thoughtcrime.securesms.database.CallLinkTable
|
||||
import org.thoughtcrime.securesms.database.CallTable
|
||||
import org.thoughtcrime.securesms.database.GroupReceiptTable
|
||||
import org.thoughtcrime.securesms.database.GroupTable
|
||||
import org.thoughtcrime.securesms.database.MessageTable
|
||||
import org.thoughtcrime.securesms.database.MessageTable.MarkedMessageInfo
|
||||
import org.thoughtcrime.securesms.database.NoSuchMessageException
|
||||
import org.thoughtcrime.securesms.database.PaymentMetaDataUtil
|
||||
@@ -916,9 +917,9 @@ object SyncMessageProcessor {
|
||||
) {
|
||||
log(envelopeTimestamp, "Synchronize read message. Count: ${readMessages.size}, Timestamps: ${readMessages.map { it.timestamp }}")
|
||||
|
||||
val threadToLatestRead: Map<Long, Long> = HashMap()
|
||||
val unhandled = SignalDatabase.messages.setTimestampReadFromSyncMessageProto(readMessages, envelopeTimestamp, threadToLatestRead.toMutableMap())
|
||||
val markedMessages: List<MarkedMessageInfo?> = SignalDatabase.threads.setReadSince(threadToLatestRead, false)
|
||||
val threadToLatestRead: MutableMap<Long, Long> = HashMap()
|
||||
val unhandled: Collection<MessageTable.SyncMessageId> = SignalDatabase.messages.setTimestampReadFromSyncMessage(readMessages, envelopeTimestamp, threadToLatestRead)
|
||||
val markedMessages: List<MarkedMessageInfo> = SignalDatabase.threads.setReadSince(threadToLatestRead, false)
|
||||
|
||||
if (Util.hasItems(markedMessages)) {
|
||||
log("Updating past SignalDatabase.messages: " + markedMessages.size)
|
||||
|
||||
Reference in New Issue
Block a user