Timeline: fix double link issue when server is messed up...

This commit is contained in:
ganfra 2021-11-16 18:14:11 +01:00
parent 52df50a686
commit 8c0b2a6704

View file

@ -128,7 +128,7 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
roomMemberContentsByUser[stateEvent.stateKey] = stateEvent.content.toModel<RoomMemberContent>() roomMemberContentsByUser[stateEvent.stateKey] = stateEvent.content.toModel<RoomMemberContent>()
} }
} }
run processTimelineEvents@ { run processTimelineEvents@{
eventList.forEach { event -> eventList.forEach { event ->
if (event.eventId == null || event.senderId == null) { if (event.eventId == null || event.senderId == null) {
return@forEach return@forEach
@ -139,13 +139,24 @@ internal class TokenChunkEventPersistor @Inject constructor(@SessionDatabase pri
// 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 (direction == PaginationDirection.BACKWARDS) { when (direction) {
PaginationDirection.BACKWARDS -> {
if (currentChunk.nextChunk == existingChunk) {
Timber.w("Avoid double link, shouldn't happen in an ideal world")
} else {
currentChunk.prevChunk = existingChunk currentChunk.prevChunk = existingChunk
existingChunk.nextChunk = currentChunk existingChunk.nextChunk = currentChunk
} else if (direction == PaginationDirection.FORWARDS) { }
}
PaginationDirection.FORWARDS -> {
if (currentChunk.prevChunk == existingChunk) {
Timber.w("Avoid double link, shouldn't happen in an ideal world")
} else {
currentChunk.nextChunk = existingChunk currentChunk.nextChunk = existingChunk
existingChunk.prevChunk = currentChunk existingChunk.prevChunk = currentChunk
} }
}
}
// Stop processing here // Stop processing here
return@processTimelineEvents return@processTimelineEvents
} }