Fix double RR issue when optimizing init sync

This commit is contained in:
Benoit Marty 2021-03-15 14:19:23 +01:00
parent 857bfcb971
commit ed662d3add
2 changed files with 8 additions and 5 deletions

View file

@ -199,7 +199,7 @@ internal class DefaultTimeline(
}
?.let { readReceiptContent ->
realm.executeTransactionAsync {
readReceiptHandler.handle(it, roomId, readReceiptContent, true)
readReceiptHandler.handle(it, roomId, readReceiptContent, false)
}
}
}

View file

@ -56,9 +56,8 @@ internal class ReadReceiptHandler @Inject constructor(
}
fun handle(realm: Realm, roomId: String, content: ReadReceiptContent?, isInitialSync: Boolean) {
if (content == null) {
return
}
content ?: return
try {
handleReadReceiptContent(realm, roomId, content, isInitialSync)
} catch (exception: Exception) {
@ -94,9 +93,13 @@ internal class ReadReceiptHandler @Inject constructor(
// First check if we have data from init sync to handle
getContentFromInitSync(roomId)?.let {
Timber.w("INIT_SYNC Insert during incremental sync RR for room $roomId")
initialSyncStrategy(realm, roomId, it)
doIncrementalSyncStrategy(realm, roomId, it)
}
doIncrementalSyncStrategy(realm, roomId, content)
}
private fun doIncrementalSyncStrategy(realm: Realm, roomId: String, content: ReadReceiptContent) {
for ((eventId, receiptDict) in content) {
val userIdsDict = receiptDict[READ_KEY] ?: continue
val readReceiptsSummary = ReadReceiptsSummaryEntity.where(realm, eventId).findFirst()