Avoid missing messages when trying to add event to chunk twice

Change-Id: I98ae8e7a5254e6f93fd2a38498b7f8e173ccd565
This commit is contained in:
SpiritCroc 2022-05-19 22:32:57 +02:00
parent 00fb32a156
commit 088657168f

View File

@ -213,6 +213,20 @@ internal class TokenChunkEventPersistor @Inject constructor(
// If it exists, we want to stop here, just link the prevChunk // If it exists, we want to stop here, just link the prevChunk
val existingChunk = existingTimelineEvent?.chunk?.firstOrNull() val existingChunk = existingTimelineEvent?.chunk?.firstOrNull()
if (existingChunk != null) { if (existingChunk != null) {
if (existingChunk == currentChunk) {
Timber.w("Avoid double insertion of event $eventId, shouldn't happen in an ideal world | " +
"direction: $direction.value" +
"room: $roomId" +
"chunk: ${existingChunk.identifier()}" +
"eventId: $eventId" +
"caughtByOldCheck ${((if (direction == PaginationDirection.BACKWARDS) currentChunk.nextChunk else currentChunk.prevChunk) == existingChunk)}" +
"caughtByOldBackwardCheck ${(currentChunk.nextChunk == existingChunk)}" +
"caughtByOldForwardCheck ${(currentChunk.prevChunk == existingChunk)}"
)
// No idea why this happens, but if it does, we don't want to throw away all the other events
// (or even link chunks to themselves)
return@forEach
}
val alreadyLinkedNext = currentChunk.doesNextChunksVerifyCondition { it == existingChunk } val alreadyLinkedNext = currentChunk.doesNextChunksVerifyCondition { it == existingChunk }
val alreadyLinkedPrev = currentChunk.doesPrevChunksVerifyCondition { it == existingChunk } val alreadyLinkedPrev = currentChunk.doesPrevChunksVerifyCondition { it == existingChunk }
if (alreadyLinkedNext || alreadyLinkedPrev) { if (alreadyLinkedNext || alreadyLinkedPrev) {