From 52f4299a0f8040ad11e14c9ee4916543a6403562 Mon Sep 17 00:00:00 2001 From: Valere Date: Sat, 5 Feb 2022 17:55:55 +0100 Subject: [PATCH] Fix back pagination conduit --- changelog.d/5166.bugfix | 1 + .../session/room/timeline/TokenChunkEvent.kt | 2 +- .../room/timeline/TokenChunkEventPersistor.kt | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 changelog.d/5166.bugfix diff --git a/changelog.d/5166.bugfix b/changelog.d/5166.bugfix new file mode 100644 index 00000000000..822c0002941 --- /dev/null +++ b/changelog.d/5166.bugfix @@ -0,0 +1 @@ +Back pagination not working on conduit \ No newline at end of file diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEvent.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEvent.kt index 465b0faac80..e9626a2173b 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEvent.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEvent.kt @@ -24,5 +24,5 @@ internal interface TokenChunkEvent { val events: List val stateEvents: List? - fun hasMore() = start != end + fun hasMore() = end != null && start != end } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt index 6607e71bd9c..2181e22c6f6 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/timeline/TokenChunkEventPersistor.kt @@ -67,14 +67,25 @@ internal class TokenChunkEventPersistor @Inject constructor( .awaitTransaction { realm -> Timber.v("Start persisting ${receivedChunk.events.size} events in $roomId towards $direction") + /** + * As per spec + * if no further events are available (either because we have reached the start of the timeline, + * or because the user does not have permission to see any more events), the end property is omitted from the response. + * Synapse is not omitting it and EA was relying on it + */ + val chunkEnd = if (receivedChunk.events.isEmpty()) { + receivedChunk.start + } else { + receivedChunk.end + } val nextToken: String? val prevToken: String? if (direction == PaginationDirection.FORWARDS) { - nextToken = receivedChunk.end + nextToken = chunkEnd prevToken = receivedChunk.start } else { nextToken = receivedChunk.start - prevToken = receivedChunk.end + prevToken = chunkEnd } val existingChunk = ChunkEntity.find(realm, roomId, prevToken = prevToken, nextToken = nextToken)