mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
[TEST] Fix another case of wrong read receipt location, to be observed
Context: https://github.com/SchildiChat/SchildiChat-android-rageshakes/issues/995 So comparing timestamps for main vs null read receipts does not seem to work at all... so better only use that as fallback in case we really don't know which event came later...? Change-Id: I8f7df95735d1478784ec5f8bf3b0b1a70c534a29
This commit is contained in:
parent
f4e9559eca
commit
5ef2341bec
2 changed files with 8 additions and 2 deletions
|
@ -146,16 +146,19 @@ private fun handleReadReceipts(realm: Realm, roomId: String, eventEntity: EventE
|
|||
}
|
||||
receiptDestinations.forEach { rootThreadEventId ->
|
||||
val readReceiptOfSender = ReadReceiptEntity.getOrCreate(realm, roomId = roomId, userId = senderId, threadId = rootThreadEventId)
|
||||
val shouldForceMon: Boolean
|
||||
val shouldSkipMon = if (rootThreadEventId == THREAD_ID_MAIN_OR_NULL) {
|
||||
val previousReceiptsSummary = ReadReceiptsSummaryEntity.where(realm, eventId = readReceiptOfSender.eventId).findFirst()
|
||||
val oldEventTs = previousReceiptsSummary?.let { EventEntity.where(realm, roomId, it.eventId).findFirst()?.originServerTs }
|
||||
val newEventTs = EventEntity.where(realm, roomId, eventEntity.eventId).findFirst()?.originServerTs
|
||||
shouldForceMon = oldEventTs != null && newEventTs != null && oldEventTs < newEventTs
|
||||
oldEventTs != null && newEventTs != null && oldEventTs > newEventTs
|
||||
} else {
|
||||
shouldForceMon = false
|
||||
false
|
||||
}
|
||||
// If the synced RR is older, update
|
||||
if (timestampOfEvent > readReceiptOfSender.originServerTs && !shouldSkipMon) {
|
||||
if (shouldForceMon || (timestampOfEvent > readReceiptOfSender.originServerTs && !shouldSkipMon)) {
|
||||
val previousReceiptsSummary = ReadReceiptsSummaryEntity.where(realm, eventId = readReceiptOfSender.eventId).findFirst()
|
||||
rrDimber.i { "Handle outdated chunk RR $roomId / $senderId thread $rootThreadEventId(${eventEntity.rootThreadEventId}): event ${readReceiptOfSender.eventId} -> ${eventEntity.eventId}" }
|
||||
readReceiptOfSender.eventId = eventEntity.eventId
|
||||
|
|
|
@ -172,15 +172,18 @@ internal class ReadReceiptHandler @Inject constructor(
|
|||
}
|
||||
receiptDestinations.forEach { threadId ->
|
||||
val receiptEntity = ReadReceiptEntity.getOrCreate(realm, roomId, userId, threadId)
|
||||
val shouldForceMon: Boolean
|
||||
val shouldSkipMon = if (threadId == THREAD_ID_MAIN_OR_NULL) {
|
||||
val oldEventTs = EventEntity.where(realm, roomId, receiptEntity.eventId).findFirst()?.originServerTs
|
||||
val newEventTs = EventEntity.where(realm, roomId, eventId).findFirst()?.originServerTs
|
||||
shouldForceMon = oldEventTs != null && newEventTs != null && oldEventTs < newEventTs
|
||||
oldEventTs != null && newEventTs != null && oldEventTs > newEventTs
|
||||
} else {
|
||||
shouldForceMon = false
|
||||
false
|
||||
}
|
||||
// ensure new ts is superior to the previous one
|
||||
if (ts > receiptEntity.originServerTs && !shouldSkipMon) {
|
||||
if (shouldForceMon || (ts > receiptEntity.originServerTs && !shouldSkipMon)) {
|
||||
rrDimber.i { "Handle outdated sync RR $roomId / $userId thread $threadId($syncedThreadId): event ${receiptEntity.eventId} -> $eventId" }
|
||||
ReadReceiptsSummaryEntity.where(realm, receiptEntity.eventId).findFirst()?.also {
|
||||
it.readReceipts.remove(receiptEntity)
|
||||
|
|
Loading…
Reference in a new issue